Using a single PWM block to drive multiple pins using DEMUX

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello all,

   

I'm trying to drive multiple servos using a single PWM block and DEMUX. Normally, I have enough PWM blocks to drive 4 servos. However, there are some applications that we require to use nearly all TCPWM/UDBs. So I'd like to know if it is possible to drive multiple pins with PWM using a single PWM block and DEMUX.

   

The idea is as follows:

   

PWM frequency is 50 Hz. Duty cycle on time is around 0.5 ms to 5 ms. So, I thought that I could start pwm on pin 1, wait for a falling edge interrupt. After that, switch to pin 2 and start PWM again with counter reset and new compare value. Same stuff for pin 3 and 4. After we get a final falling edge on pin 4, I write the total elapsed on time to PWM counter and let it generate an interrupt on TC. After TC is reached, the processes loops. So, this should in theory, make me able to use 1 single PWM block and vary its compare match value to drive multiple pins. However, the project does not work as expected. There is much jitter on the servos. Can anyone help me with this issue?

   

Thanks, in advance.

   

Attached is the example project that I've been working on.

13 Replies