dsPIC33 stop PWM generation after enabling soft timers

Hello everyone!!

I am back to work on a old project of a little differential drive robot. The project was already tested and retested exhaustively and I made it using the powerful functionalities of FreeRTOS plus DSP functionality and everything works fine but, when I add the soft timer configUSE_TIMERS define to FreeRTOSConfig.h, compile and upload the code, everything goes fine but the MCPWM stops generating signal… I already verified that the task that calls SetDCMCPWM1 is running and reaching the call to this function with correct values, the MCPWM is being initialized correctly, all the tasks are running as expected as opposed to the PWM signals are not visible on the pins. Someone could help-me with this issue?

I am not familiar with MCPWM but adding timer creates an extra task. Is it possible that the task which interacts with MCPWM is getting starved? The timer task priority is defined using configTIMER_TASK_PRIORITY.


Thanks for your attention Aggarwal. I thought this at first, but I verify and debug the code massively and I am absolutely sure that the task that updates the PWM is running and calling the library function that set the PWM duty cycle.
As mentioned before, imagine: One project that was already tested running fine for months. Then you go to the FreeRTOSConfig.h and add the following lines;

#define configUSE_TIMERS                1
#define configTIMER_TASK_PRIORITY       ( 2 )
#define configTIMER_QUEUE_LENGTH        ( 1 )
#define configTIMER_TASK_STACK_DEPTH    ( 20 )

Now you compile and upload this into the uC (dsPIC33FJ actually). As well, mentioned before, this time, and only with these ‘defines’ the PWM stop outputting the wave form. Why???

The project has TIMER2, TIMER3, UART2(with DMA), IC1(with DMA), IC2, IC8 and QEI hardware usage plus 7 tasks. All running and working fine before ‘enabling FreeRTOS soft timers’.
Of course that I added one sTimer (from FreeRTOS) and I supposed that the timer task or the timer callback were causing the issue. The sTimer worked like a charm, but no spinning wheels. After some survey looking for what was causing the problem I check the PWM pins with the oscilloscope, since the software ran everything ok. Checked that PWM’s were calculated and had correctly values. I thought… Why??? It’s not a crash nor frozen task or whatever observable at all.

After many hours of study and analysis I decided to git revert to the point before the sTimer was written into the code. Everything working, even PWM!! Then, before start writing the timer properly, I decided to start enabling “FreeRTOS timer usage” and wrote those lines into the FreeRTOSConfig.h (#define configUSE_TIMERS…) and only that! Code compiled and uploaded into the dsPIC and… no PWM signal…
Only commented those 4 lines into FreeRTOSConfig… Everything went ok again… WHY???

I’m so so sorry about the long text, but I already had many troubles that I spent many hours discovering what was going wrong and don’t came to the forum ask for a quick answer. I dug the forums, specs, documents and got the solution by my way. But, now, this misfunctioning is driving me crazy!!

Thanks in advance…

Claudio Marques

That seems less. Would you please try to increase it to a bigger value (something like 256)?


Thank you very much Aggarwal!!

I swear I tried up to 100 and did not think that this should be the case because I remember trying 1000 to exclude this possibility. But, as mentioned, it was before I revert all modifications… Don’t remember if I tried high values to stack depth after revert, then, as you suggested, increased to 256 and it works!!!
Thanks a lot!!! And sorry by the long text…

Glad that it worked for you.


Thanks for sharing this useful info. It is really helpful for us.