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

Problem with queues - simple program with ADC and leds

Posted by bartx on September 8, 2014

Hello,

I'm working on simple project - tempereature sensor based on thermistor. Measured voltage is 0-3,3v and it's connected to ADC on FRDM KL25Z board (16-bit). So as an output I have 16-bit variable with values 0-65536. Depends on the values, I want to turn on/off led diodes. Code is listed below. I'm using CodeWarrior 10.6

My problem is, that it's not working as I expected. When temperature is rising, voltage is going down and one LED is turned on, after some time another led is also ON. But when voltage raises back to 3.3v leds are still on. I have to reset my board, then diodes are off. Anyone have an idea what's wrong with my code?

xQueueHandle queue_led;

void TaskTemp ( void *pvParameters )
{
while(1)
{
	queue_led = xQueueCreate( 2, sizeof( uint16_t ) );

	uint16_t temp_val;

	(void)AD1_Measure(TRUE);
	(void)AD1_GetValue16(&temp_val);

	xQueueSendToFront(queue_led, &temp_val, 100);
	vTaskDelay(100);
}

}
void TaskLed ( void *pvParameters )
{
while(1)
{

	uint16_t temp_val;

		xQueueReceive(queue_led, &temp_val, 100);

		if (temp_val<59000)
		{
			LED_1_SetVal();
		}
		else if (temp_val>59000)
		{
			LED_1_ClrVal();
		}


		if (temp_val<56000)
		{
			LED_2_SetVal();
		}
		else if (temp_val>56000)
		{
			LED_2_ClrVal();
		}

}
vTaskDelete ( NULL );

}

Code in main():

xTaskCreate(TaskLed, (signed char *)"tl", 150, NULL, 1, NULL);
xTaskCreate(TaskTemp, (signed char *)"tt", 150, NULL, 1, NULL);
vTaskStartScheduler();
return(0);

Problem with queues - simple program with ADC and leds

Posted by davedoors on September 8, 2014

TaskTemp() is creating a queue each time it goes around its while(1) loop, so it is posting to a different queue each time it calls xQueueSendToFront(), and TaskLed() is using a queue handle which is always changing. You will probably just run out of RAM eventually as this will be leaking lots of memory because there is no way to recover the queues that have already been created. Do you have a malloc failed hook defined to trap that happening?

I would recommend creating the queue before the tasks are created. That way the queue will already be created before either task tries to use it. You could also check the return value of the queue read to know if a new value has been received.


Problem with queues - simple program with ADC and leds

Posted by bartx on September 8, 2014

Works fine, thanks for your help :) Do you have any idea how to prevent leds from blinking? I'm trying different settings in TicksToWait parameter in QueueReceive/QueueSendtoFront but they're still blinking when value of the 16-bit variable is near value in the if ().


[ 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