Problem with queues – simple program with ADC and leds

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

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

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 ().