FreeRtos slow?

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

FreeRtos slow?

Postby brp80000 » Sat Dec 08, 2018 12:59 am

I need to read internal ADC1 values 1000 times per second. I was thinking of using FreeRtos but CONFIG_FREERTOS_HZ the fastest is 1,000. And the rest of the tasks never work.
How can I implement faster FreeRtos?
Also can't find what sample rate the ADC can operate. There are no settings. Maybe there is an opportunity to use DMA? Or have an example to retrieve values from ADC on interrupt from the timer.
Last edited by brp80000 on Sat Dec 08, 2018 7:32 am, edited 1 time in total.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: FreeRtos slow?

Postby ESP_Sprite » Sat Dec 08, 2018 4:41 am

You can use I2S to sample the ADC using DMA, suggest you refer to the I2S driver for more info.

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: FreeRtos slow?

Postby brp80000 » Sat Dec 08, 2018 8:26 am

Does the I2S library work with built-in ADC1?

jhinkle
Posts: 17
Joined: Wed Aug 29, 2018 3:17 pm

Re: FreeRtos slow?

Postby jhinkle » Sat Dec 08, 2018 7:36 pm

Look into using the ULP.

It was designed to do exactly what you are asking.

Don't try to speed up FreeRTOS - that's the wrong approach.

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: FreeRtos slow?

Postby brp80000 » Sun Dec 09, 2018 7:10 am

The fact that it is impossible to accelerate FreeRtos, I already knew.
I don't know what ULP has to do with it. I need to read and summarize the internal values of the four ADC1 channels 1000 times per second. One of the values should be squared and then the sum should be accumulated. And should receive the values 10 times per second.

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: FreeRtos slow?

Postby ESP_igrr » Sun Dec 09, 2018 12:17 pm

Why does ADC sampling need to be tied to FreeRTOS tick period? You can have the sampling task receiving a semaphore, and have a hardware timer ISR sending the semaphore. This can happen multiple times per tick, as long as you yield from the ISR.
Second, as ESP_Sprite said, I2S peripheral can be used to do DMA from internal ADC to memory.

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: FreeRtos slow?

Postby brp80000 » Tue Dec 11, 2018 11:16 pm

I created the interrupt on the ISR timer 1000 times per second as I needed and wrote the most needed code inside it.
When I use printf(...) everything works but when I want to save values in flash using fprintf(...) I immediately getGuru Meditation Error: Cache disabled but cached memory region accessed
I use IRAM_ATTR atribute for isr
  • void IRAM_ATTR timer_group0_isr(void *para) //
    {
    int timer_idx = (int) para;
    TIMERG0.hw_timer[timer_idx].update = 1;
    TIMERG0.int_clr_timers.t1 = 1;
    TIMERG0.hw_timer[timer_idx].config.alarm_en = TIMER_ALARM_EN;
    num++;
    adc_reading_Ua = adc1_get_raw(ADC1_CHANNEL_6);
    if (Averag==3) { // среднеквадратичное RMS
    sum_reading_Ua += adc_reading_Ua*adc_reading_Ua;
    }
    if (Averag==1) { // скользящее среднее mAverage
    sum_reading_Ua += adc_reading_Ua;
    }
    if (num==SampleRate_char) { // == 160 80 или 40 значений накопятся
    sampleNO++;
    num=0;
    S_Ua = sum_reading_Ua;
    sum_reading_Ua = 0;
    }
Is there any way to make flash WRITE and interrupt read from ADC1 work at the same time?

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: FreeRtos slow?

Postby ESP_Sprite » Wed Dec 12, 2018 3:15 am

There's a lot of things you cannot do from an ISR (actually, you're supposed to only call functions that are specifically marked as such, like the FreeRTOS *FromISR functions) and doing a fprintf is amongst one of them. The way to go here would be to create a FreeRTOS queue and push the samples into that queue, so you can read them out and write them to storage in a separate task. Or just use the I2S driver for this, as we said earlier.

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: FreeRtos slow?

Postby brp80000 » Wed Dec 12, 2018 10:56 am

It is impossible to read from the ADC1 during interrupt? Or it is impossible to summarize the values obtained during the interrupt? Record in flash I do in a separate task.
I'm making a real-time device and can't create queues. ADC data must be received exactly 1000 times per second on a timer and immediately used for monitoring and control. And 20 times a second I have to save the processed data to a flash.

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: FreeRtos slow?

Postby ESP_igrr » Wed Dec 12, 2018 12:07 pm

You can use a semaphore or Task Notification to signal a task from the ISR. The task can perform ADC sampling and do any other things you need, and then block until the next event, using the same semaphore or task notification feature. The delay due to unblocking the task from ISR is usually on the order of few (<10) microseconds, and the delay is probably going to be the same every time, so sampling will happen at correct period.

However if you need absolutely exact period, it is best to use I2S to sample internal ADC and write data to DMA.

Who is online

Users browsing this forum: No registered users and 116 guests