Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

PWM Jitter on ATmega32

Posted by Kupo on December 15, 2007
Hi,

I'm trying to run some servos using the PWM features of ATmega32 hardware timers, producing a 1-2ms pulse with a 1/128ms resolution. My capture/compare interrupt code works as a stand-alone, but when I integrate it with freeRTOS, the signal jitters by about 30us which causes the servos to shake.

I've tried modifying the tick code to use timer2 instead of timer1, I've tried using naked interrupts, using enter/exit critical and also running the code as a plain hardware interrupt rather than using the interrupt to resume the task but nothing seems to work.

FreeRTOS is running the ATmega32's 8MHz internal clock with a tick rate of 1000. Is the interrupt latency of the ATmega32 on freeRTOS too much for use with servos, or am I doing something wrong here?

Thanks,

Jon

RE: PWM Jitter on ATmega32

Posted by Dave on December 17, 2007
Set the tick interrupt to use the lowest priority and the PWM interrupt to use a higher priority. This is ok provided you dont call FreeRTOS API functions from the PWM interrupt. Some ports have a configKERNEL_INTERRUPT_PRIORITY for this purpose.


RE: PWM Jitter on ATmega32

Posted by JMR on December 17, 2007
Well the first thing I would do is to lower the tick rate. Are you certain that you need to swap tasks every 1ms?
Also 30us is about 240 clock cycles at 8MHz that's, in an average bit of code, around 200 instructions (which isn't bad at all).
If you really need to update your control loop at a 1ms rate then I would suggest that you go for a higher clock frequency (this will reduce your jitter but it won't eliminate it).

I would put the servo speed and position update loops into ISRs and leave the RTOS tick at a much lower rate say 50ms+)


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS