40khz Timer setup
Posted: Mon Aug 06, 2018 11:04 pm
Hi
Can you please tell me why this setting is unstable and the oscilloscope output can see bending as otherwise I could set the timer to be stable at 40Khz thank you for your advice.
my code
#include "driver/timer.h"
static intr_handle_t s_timer_handle;
void init_timer(uint64_t 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
};
timer_init(TIMER_GROUP_0, TIMER_1, &config);
timer_set_counter_value(TIMER_GROUP_0, TIMER_1, 0);
timer_set_alarm_value(TIMER_GROUP_0, TIMER_1, timer_period_us);
timer_enable_intr(TIMER_GROUP_0, TIMER_1);
timer_isr_register(TIMER_GROUP_0, TIMER_1, &timer_isr, NULL, 0, &s_timer_handle);
timer_start(TIMER_GROUP_0, TIMER_1);
}
static void IRAM_ATTR timer_isr(void* arg){
TIMERG0.int_clr_timers.t1 = 1;
TIMERG0.hw_timer[1].config.alarm_en = 1;
digitalWrite(23, digitalRead(23) ^ 1);
}
void setup() {
pinMode(23, OUTPUT);
init_timer(12);
}
void loop() {
}
Can you please tell me why this setting is unstable and the oscilloscope output can see bending as otherwise I could set the timer to be stable at 40Khz thank you for your advice.
my code
#include "driver/timer.h"
static intr_handle_t s_timer_handle;
void init_timer(uint64_t 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
};
timer_init(TIMER_GROUP_0, TIMER_1, &config);
timer_set_counter_value(TIMER_GROUP_0, TIMER_1, 0);
timer_set_alarm_value(TIMER_GROUP_0, TIMER_1, timer_period_us);
timer_enable_intr(TIMER_GROUP_0, TIMER_1);
timer_isr_register(TIMER_GROUP_0, TIMER_1, &timer_isr, NULL, 0, &s_timer_handle);
timer_start(TIMER_GROUP_0, TIMER_1);
}
static void IRAM_ATTR timer_isr(void* arg){
TIMERG0.int_clr_timers.t1 = 1;
TIMERG0.hw_timer[1].config.alarm_en = 1;
digitalWrite(23, digitalRead(23) ^ 1);
}
void setup() {
pinMode(23, OUTPUT);
init_timer(12);
}
void loop() {
}