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




Loading

PWM+ADC+Atmega128+FreeRTOS problem.

Posted by misiekg on November 15, 2009
Hello,

I have strange problems with those four. I have my PWM on timer3, when I initialize it all readings queued by ADC reading functions go wrong. My PWM initialization:

void initPwm (){
TCNT3 = 0;
OCR3A = 0;
OCR3B = 0;
TCCR3A = _BV(COM3A1)| _BV(COM3B1)| _BV(WGM31)|_BV(WGM30);
TCCR3B = _BV(CS30);
}

Next one of my ADC readings tasks(chanell 0):

void ADC0(void* pvParameters)
{

uint8_t odczyt;

while(1){
//ADC0 - czujnik - 0
ADMUX &= ~(_BV(MUX4) |_BV(MUX3) |_BV(MUX2) |_BV(MUX1) |_BV(MUX0));
ADCSRA |= _BV(ADSC);
while(bit_is_set(ADCSRA,ADSC)){};
odczyt = ADCH;

xQueueSendToBack(xQueue0, &odczyt, 0);
}
}

And ADC initialization:


void initAdc (){

ADCSRA=_BV(ADEN)| _BV(ADSC)| _BV(ADPS0) | _BV(ADPS1)| _BV(ADPS2);



ADMUX &= ~_BV(REFS1);
ADMUX |= _BV(REFS0);
ADMUX |= _BV(ADLAR);
}

Task creation:

xTaskCreate(ADC0, "ADC0", configMINIMAL_STACK_SIZE, NULL, mainADC_TASK_PRIOTITY, NULL );
xTaskCreate(vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );

And so on... Lcd task try to read and if, show on LCD. Problem is that if I initPwm() there are problems - for example form 2 ADC channels I get simmilar readings, and when I changes value ewerything stops... Hard to say whats going on because its totally random! The code without FreeRTOS works perfectly, but I must use this RTOS...

Please help me, I spent few weaks on it ant can't manage to figure it out. I can post somewhere full code if somebody wants to help me.

Thanks in advance.

RE: PWM+ADC+Atmega128+FreeRTOS problem.

Posted by Dave on November 16, 2009
Not sure I can really help, don't know about AVR specifics, but it looks like your ADC0() task is polling the ADC. If this task is not the lowest priority task then no tasks of lower priority will ever run. It would be best to make it event driven so it only runs when there is an adc reading to process.

RE: PWM+ADC+Atmega128+FreeRTOS problem.

Posted by misiekg on November 17, 2009
Thank you for your reply. It might be better, I don't have lower priority tasks, but for future. Do u know how I should fix it?


[ 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