I need to drive and addressable LED chain which contains 64 addressable LEDs. The timing needs very accurate, 1X430uS and 2X430uS (0 or 1 bits). AFAIK freertos uses timer0 as a hardware timer which is the highest priority timer. I found a config flag in make menuconfig to assign hardware timer 1 to freertos, and I can use timer0. Its working well, but if I see it in an oscilloscope, there is a hard jittering.
My question is that, how can I make a high precision timer?
I tried this:
in config:
- clock frequency: 240Mhz
- run Freertos only first core
- XTensa timer to use as the freertos tick source (Timer 1(int 15 level 3))
in my code:
Code: Select all
timer_config_t config = {
.alarm_en=true,
.counter_en=false,
.intr_type = TIMER_INTR_LEVEL,
.counter_dir = TIMER_COUNT_UP,
.auto_reload = true,
.divider = TIMER_PRE_DIVIDER // 5
};
timer_init(TIMER_GROUP_0, TIMER_0, &config);
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, TIMER_RELOAD_US);
timer_enable_intr(TIMER_GROUP_0, TIMER_0);
timer_isr_register(TIMER_GROUP_0, TIMER_0, &timer_proc_isr, NULL, 0, &timer_handle);
Code: Select all
static void timer_proc_isr(void* arg)
{
static int io_state = 0;
TIMERG0.int_clr_timers.t0 = 1;
TIMERG0.hw_timer[0].config.alarm_en = 1;
gpio_set_level(PLANE_0_PIN, 0);
gpio_set_level(PLANE_0_PIN, 1);
}
thx,
Zamek