This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software:
Hey.
I need to find a way to determine the state of a gpio pin that is set up for pwm.
I thought I could read the GPIOx->DOUT31_0 register, but that doesnt seem to reflect the pin state, when set up for pwm.
regards
Anders
As far as I know, you can't. GPIO is its own Pin Function (PF=1) so its state is disconnected when the PF is connected to the timer. I didn't find a TIMA/TIMG equivalent to the SCCI bit in the MSP430 timers.
I suspect you could use the ADC, or maybe the Comparator, to sense the state of the pin, since the "To Analog Peripheral(s)" path is independent of the PF [Ref TRM (SLAU846B) Fig 10-1]. I suppose there would be some latency. [I haven't tried it.]
Yeah, Bruce you are right. The IOMux indirection breaks the connection back to the IN register.
Another option is to feed the PWM port into another GPIO and read it that way.
What I'm trying to do is actually a bit complicated...
I have set up four timers to generate pwm signals, but at a 90 degree phase shift from each other.
I am using center-aligned pwms, as this lets me use a second channel on the first timer to generate events on ZERO, CCU1, LOAD and CCD1.
These events corresponds to the middle of each respective duty cycle of the four pwms, and are triggering the ADC to sample four channels repeatedly, and generating an interrupt after four samples.
However, I would like to find a way to ensure synchronization, so I dont accidentally end up in a situation where the ADC sampling gets shifted, so it samples at a wrong time - potentially during the pwm OFF period...
So I need to try to find a fast effecient way to determine which of those four events triggered last. Another option could be to compare the pins of two of the timers to see if they had the expected state during the ISR, but if the duty cycle is large this might not work.
Any suggestions?
I'm not sure I understand what your signals look like, or what you're checking for, but:
For PWM (output) in particular, a fairly simple check would be to compare the CTR value with the CC0 value, in effect acting as the timer comparator. This doesn't check the actual pin, so it doesn't account for Faults or other output features. What it lacks in elegance it makes up in low-cost.