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() {
}
40khz Timer setup
-
- Posts: 9759
- Joined: Thu Nov 26, 2015 4:08 am
Re: 40khz Timer setup
Your post doesn't really make sense. In what way is your output unstable and what do you mean by 'bending'?
Re: 40khz Timer setup
Hi
I have in mind that the timer is unstable as it is seen in this photo.
I have in mind that the timer is unstable as it is seen in this photo.
-
- Posts: 9759
- Joined: Thu Nov 26, 2015 4:08 am
Re: 40khz Timer setup
...That scope screenshot doesn't really make much sense, as it seems to show a 33Hz signal. In general, if you want to make a square wave, why not use e.g. the LEDPWM peripheral, by the way?
Re: 40khz Timer setup
The picture is just an example of it being seen only a problem with the timer ledc library works correctly that i tried but i need to set the timer to the frequency of 40khz my project.
-
- Posts: 9759
- Joined: Thu Nov 26, 2015 4:08 am
Re: 40khz Timer setup
...so you're saying you see 5mS of jitter at the 40KHz signal as well?
Re: 40khz Timer setup
When I use ledc library so the output signal is OK even at 80khz but as suddenly I use my code using the timer so the signal is unstable
Who is online
Users browsing this forum: No registered users and 70 guests