40khz Timer setup

Folny82
Posts: 7
Joined: Wed Feb 07, 2018 1:56 am

40khz Timer setup

Postby Folny82 » 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() {

}

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

Re: 40khz Timer setup

Postby ESP_Sprite » Tue Aug 07, 2018 3:56 am

Your post doesn't really make sense. In what way is your output unstable and what do you mean by 'bending'?

Folny82
Posts: 7
Joined: Wed Feb 07, 2018 1:56 am

Re: 40khz Timer setup

Postby Folny82 » Tue Aug 07, 2018 5:55 am

Hi

I have in mind that the timer is unstable as it is seen in this photo.

Image

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

Re: 40khz Timer setup

Postby ESP_Sprite » Tue Aug 07, 2018 9:29 am

...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?

Folny82
Posts: 7
Joined: Wed Feb 07, 2018 1:56 am

Re: 40khz Timer setup

Postby Folny82 » Tue Aug 07, 2018 9:42 am

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.

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

Re: 40khz Timer setup

Postby ESP_Sprite » Tue Aug 07, 2018 1:18 pm

...so you're saying you see 5mS of jitter at the 40KHz signal as well?

Folny82
Posts: 7
Joined: Wed Feb 07, 2018 1:56 am

Re: 40khz Timer setup

Postby Folny82 » Tue Aug 07, 2018 1:53 pm

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 51 guests