0
\$\begingroup\$

I would like to determine in software if the PWM output signal is currently high or low.

As far as I know GPIO_ReadOutputDataBit(GPIOD, GPIO_Pin_12) does not work with a GPIO pin set up as an alternate function (AF).

Daniel
6,24823 silver badges33 bronze badges
asked Oct 14, 2016 at 12:24
\$\endgroup\$
1
  • \$\begingroup\$ Some microcontrollers have a "port state" register that can give the actual voltage level (active/inactive) of a port, regardless of if it is configured as output or input. If such registers can be used when a peripheral hardware is using the same port also depends on the specific MCU. So I would suggest to read the chapter describing the gpio hardware in the manual. \$\endgroup\$ Commented Oct 14, 2016 at 13:45

2 Answers 2

1
\$\begingroup\$

You should read the applicable GPIO input data register, not the output one. Only when the pin is configured as a GPIO output would they match.

The programmer's manual will explain what the actual register is; the documentation for whatever IO or HAL library you are using will show how to read it at a higher level.

It is also likely that you should be able to read the relevant timer's count register and compare it to the applicable output compare value.

answered Oct 14, 2016 at 17:45
\$\endgroup\$
0
\$\begingroup\$

I can't find a place in the timer register structure to directly read OCxREF or OCx, but you may have luck with this:

Set an interrupt on the update and reset timer events and set a flag manually that way.

Although the output state may be reflected in the GPIO input state as Chris Stratton mentions as well.

answered Oct 14, 2016 at 18:16
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.