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).

\$\endgroup\$
  • \$\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\$ – Lundin Oct 14 '16 at 13:45
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.

\$\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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.