FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [September 2014 Threads]
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);
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.
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 ().
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.