Page 1 of 1

TWD in low-latency task

Posted: Mon Jul 30, 2018 9:31 pm
by vyo2003
I develop simple library for playing audio via DAC. In it, using task as data provider is very common pattern (it is very simple to use).

However, task watch dog is triggered very soon. I saw recommendation about turning off TWD completely, but requiring this to do for my library isn't very good, is it?

What is the best way to solve this problem? I use queue to transfer data from task to player function (called using `esp_timer`).
Thanks for your help :D!

Re: TWD in low-latency task

Posted: Mon Jul 30, 2018 10:01 pm
by vyo2003
Some news: idle task isn't triggered on esp_timer core, not provider task.

Re: TWD in low-latency task

Posted: Tue Jul 31, 2018 3:36 am
by ESP_Angus
Most likely, your task is busy-waiting somewhere (ie polling in a while loop) so it always occupies the CPU and never allows the idle task to run. Try to find a way to block until an interrupt occurs, or until data is received via queue, that doesn't use polling. If you must use polling, find a place you can call vTaskDelay() in the polling loop.

If you're able to share your code, it may be possible to give more specific suggestions.

Re: TWD in low-latency task

Posted: Tue Jul 31, 2018 3:55 am
by ESP_Sprite
Also note that the I2S driver allows you to send samples to the DAC without any CPU involvement at all, allowing you to play sounds while having nearly the full power of the CPU available to do other things. You may want to switch to that instead.

Re: TWD in low-latency task

Posted: Tue Jul 31, 2018 10:49 am
by vyo2003
At first, thanks for I2S suggestion. I know about it very well, but my library is for ones like me who don't want external device for playing some audio.

Now back to discussion:
It is pretty fun that library itself doesn't include mistake, but my test program does. This is how it looks:

Code: Select all

#include <sound.h>
#include <soundProviderPcm.h>
#include <memory>

const extern long unsigned int voice_length;
const extern uint8_t voice_data[];

void play_voice() {
	auto provider = std::make_unique<SoundProviderPcm>(voice_data, voice_length, 8000);
	auto player = std::make_unique<SoundMixer>(1, 0, DAC_GPIO25_CHANNEL);
	provider->repeat = true;
	player->play(0, provider.get());
	while (true) {};
}

extern "C" void app_main() {
	play_voice();
}
Just added

Code: Select all

vTaskDelay(100);
to while loop and it is working now!

If you want to look at library:
https://github.com/v1993/esp32-sound (Bug: https://github.com/v1993/esp32-sound/issues/4)
https://github.com/v1993/esp32-sound-pcm

Re: TWD in low-latency task

Posted: Tue Jul 31, 2018 5:13 pm
by WiFive
vyo2003 wrote:At first, thanks for I2S suggestion. I know about it very well, but my library is for ones like me who don't want external device for playing some audio.
He means i2s will write to internal dac too.