BLE interfering with timer group interruption

contateste123
Posts: 2
Joined: Mon Oct 28, 2019 6:29 pm

BLE interfering with timer group interruption

Postby contateste123 » Mon Oct 28, 2019 6:39 pm

Hello!

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:
  1. void init_timer(int timer_period_us)
  2. {
  3.     timer_config_t config = {
  4.             .alarm_en = true,
  5.             .counter_en = false,
  6.             .intr_type = TIMER_INTR_LEVEL,
  7.             .counter_dir = TIMER_COUNT_UP,
  8.             .auto_reload = true,
  9.             .divider = 80   /* 1 us per tick */
  10.     };
  11.  
  12.     timer_init(TIMER_GROUP_1, TIMER_1, &config);
  13.     timer_set_counter_value(TIMER_GROUP_1, TIMER_1, 0);
  14.     timer_set_alarm_value(TIMER_GROUP_1, TIMER_1, timer_period_us);
  15.     timer_enable_intr(TIMER_GROUP_1, TIMER_1);
  16.     timer_isr_register(TIMER_GROUP_1, TIMER_1, &timer_isr, NULL, ESP_INTR_FLAG_IRAM, &s_timer_handle);
  17.  
  18.     timer_start(TIMER_GROUP_1, TIMER_1);
  19. }
My program was built based on the gatts_demo.c example.
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);
If I comment it out, there is no jitter and my application works perfectly. However, obviously I can't connect to the BLE.
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!

contateste123
Posts: 2
Joined: Mon Oct 28, 2019 6:29 pm

Re: BLE interfering with timer group interruption

Postby contateste123 » Thu Oct 31, 2019 5:25 pm

Any help, please?
:)

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

Re: BLE interfering with timer group interruption

Postby ESP_Sprite » Fri Nov 01, 2019 9:13 am

Not sure about the BLE behaviour, but in general, it could be a good idea to move your timing-sensitive stuff to a separate core for sure. It also can pay off to look into peripherals; for instance, the RMT peripheral should be able to create a 200mS off / 200uS on signal pretty easily.

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 159 guests