xavierpacheco wrote on Sunday, March 11, 2018:
A task has been created that reads a value of the ADC of a temperature sensor of a battery every 100 ms, calculate the value of it from the reading and update the value of a variable with it. My first iteration of the routine is as follows:
`#define DELAY_TICKS 100 // tick period 1 ms => 100 ms delay
volatile float battery_temperature;
void temperature_task(void* parameters) {
TickType_t current_tick_count, expired_tick_count;
while (1) {
// Read ADC
unsigned short adc_value = read_temperature_adc();
// Compute temperature
float temperature = compute_temperature(adc_value);
// Update variable
battery_temperature = temperature;
// Get current system tick count and compute expired count
current_tick_count = xTaskGetTickCount();
expired_tick_count = current_tick_count + DELAY_TICKS;
// Wait until the number of ticks has happen (100 ms)
while (xTaskGetTickCount() < expired_tick_count) {} } }`
Once incorporated into the system, other tasks have begun to have problems because they are receiving less processing time, and even one of them has stopped working completely.
The task has been created with “normal” priority and the tick of the system is 1 ms (time of change between concurrent tasks). And the function to read the ADC works waiting for the reading, but it only takes a few nanoseconds and is not considered to impact the system, like the routine that computes the temperature.
So these are my questions:
What happens with tasks that have been receiving less processing time, but still running? Specifically about their priority and the way they use their time.
What happened to the task that has stopped running completely?
What is the problem that I have caused with my routine and how can I solve it?
P.D.: I’m using FreeRTOS Cortex M3