Question about changing the PWM compare value | Cypress Semiconductor
Question about changing the PWM compare value
When I call
void PWM_WriteCompare1(uint8/16 compare)
or one of the similar functions, does that new compare value have immediate effect? Or does it become effective the next time the counter rolls over?
If it's the former, how can I acheive the latter in a glitch-free way?
I am trying to control 8 hobby servos by demultiplexing the output of a single PWM generator. Every time the counter rolls over (every 2.5 ms), I redirect the multiplexer to the next output and load a new compare value. I am concerned that as my system becomes more complicated (it has a bunch of other things to do apart from babysitting these servos), it might take long enough to service the overflow interrupt to create really short pulses sent to channels that are supposed to be disabled entirely.
I have three ideas for dealing with this:
- Don't worry about it (PROS: Simple, CONS: Hard for me to assess with the equipment I have whether this is problematic or not. It might well work with the sample servos I have to test with and then cause glitchy problem later.)
- Add a control register with one bit for the enabled status of each channel, AND the control register with the outputs of the demultiplexer (PROS: Guarantees no glitches like this. CONS: Uses up a control register, might be completely unneccessary.)
- Change the software to perform these updates in the Interrupt On Compare 1 ISR instead of in the Interrupt On Terminal Count ISR. (PROS: Perfect if it works. CONS: Really bad if the update to the compare value has immediate effect, because if the upcoming channel is to receive a pulse longer than the one that was sent to this channel, this channel will end up glitched.)
The component datasheet appears to be silent on this question.
Other suggestions are welcome too.