I am having a hard time working with BLE while working with timer group.
All I need in this program is to set high a GPIO, leave it high for 200uS and then set it back to low.
This happens every 20ms, which I think is enough time for the uC to do all its other stuff in background.
However, using a scope, my timer isn't accurate, jittering from 200-300uS and sometimes it even spikes up to 500uS which isn't acceptable at all.
The following function is my timer:
- void init_timer(int timer_period_us)
- {
- timer_config_t config = {
- .alarm_en = true,
- .counter_en = false,
- .intr_type = TIMER_INTR_LEVEL,
- .counter_dir = TIMER_COUNT_UP,
- .auto_reload = true,
- .divider = 80 /* 1 us per tick */
- };
- timer_init(TIMER_GROUP_1, TIMER_1, &config);
- timer_set_counter_value(TIMER_GROUP_1, TIMER_1, 0);
- timer_set_alarm_value(TIMER_GROUP_1, TIMER_1, timer_period_us);
- timer_enable_intr(TIMER_GROUP_1, TIMER_1);
- timer_isr_register(TIMER_GROUP_1, TIMER_1, &timer_isr, NULL, ESP_INTR_FLAG_IRAM, &s_timer_handle);
- timer_start(TIMER_GROUP_1, TIMER_1);
- }
I commented out some BLE functions until I could fine one and only one that could be the problem.
I've found this particular line to cause the jitter:
Code: Select all
ret = esp_ble_gatts_app_register(PROFILE_A_APP_ID);
So my question is: what are my options here??
I tried to change the interruption level of time from ESP_INTR_FLAG_IRAM to ESP_INTR_FLAG_NMI (which it states to be the highest priority), but it freezes some stuff.
Is there a way to lower the BLE priority? Or have it running in a different core??
Or should I run the timer in a different core??
I've read a lot in the internet and tried different timers, but none of them work. BLE has the highest priority it seems.
Thanks!