Quality RTOS & Embedded Software

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


PWM Jitter on ATmega32

Posted by Kupo on December 15, 2007

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?



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 ]    [ Privacy ]    [ Sitemap ]    [ ]

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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

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

Xilinx Microblaze and Zynq partner