PWM on dsPIC33

cahbtexhuk wrote on Saturday, March 30, 2013:


I’m trying to use FreeRTOS port on dsPIC33FJ128GP206 and I need to drive a lot of servos. Servos are being driven with OC1-3 channels through multiplexers, OCx are using timer2. FreeRTOS is using timer1, as in example and is running at lowest priority timer interrupt (priority 1), while timer2 is running at priority 7. When tasks are switching it causes a lag or something and servos shake during context switch.
Just to do some research on issue, I’ve replaced timer1 handler with some dummy code, to see if it will occur with same interrup priorities - everything is ok. As soon as I add RTOS functionality - jitter is back.
How can I get rid of this? I think I’ve already tried everything, but the jitter is still present. The more tasks I add, the more jitter there is - shake per task (switch)

rtel wrote on Saturday, March 30, 2013:

Are your drives being processed from an interrupt?  If so, then setting the interrupt priority above configKERNEL_INTERRUPT_PRIORITY will ensure the interrupts do not get delayed by anything the kernel is doing.  It does however also mean that the interrupts cannot call FreeRTOS API function (the functions that end in FromISR are safe on a PIC24/33 only if called from interrupts that run with a priority equal to configKERNEL_INTERRUPT_PRIORITY).


cahbtexhuk wrote on Saturday, March 30, 2013:

Yes, I am aware of that. I am not using any FreeRTOS functions inside interrupt handler and my interrupts are running above configKERNEL_INTERRUPT_PRIORITY while this happens

davedoors wrote on Sunday, March 31, 2013:

Does that mean your drives are being processed by the interrupts? I’m not sure. Are your tasks enabling and disabling interrupts using any method other than calling taskENTER_CRITICAL and taskEXIT_CRITICAL?

cahbtexhuk wrote on Sunday, March 31, 2013:

No, it’s a very simple “Hello World” project. My only task is a simple led blinky. Just :
for(;:wink: {
vTaskDelay(1000 / portTICK_RATE_MS);}
two lines, nothing more.
Interrupt handler is also kept as simple as possible. Clear the flag and load value from an array. Array is static. No calls to anything from ISR, no complex calculations, no nothing:
{ IEC0bits.OC1IE = 0;
IFS0bits.OC1IF = 0;
if(++mux == 2) mux = 0;
OC1RS = pwm;
IEC0bits.OC1IE = 1;}
Is this clear enough to see, how complex is the program I am running? Everything else is a code from freertos example. pmw is declared as pwm = {1500,1500} and that’s the only place it is being modified.