Quality RTOS & Embedded Software

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


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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists