very very slow pwm singal generation

Ian777
Posts: 21
Joined: Sun Jun 17, 2018 11:31 pm

very very slow pwm singal generation

Postby Ian777 » Tue Jul 23, 2019 6:25 am

Hey everyone,

I'm starting to dig around and have been fooling with the ledc module, but I don't think it will fulfill my requirements completely. I need to generate a very slow pwm signal, somewhere in the order of having a period of 10 to 20 minutes. The duty will be fixed

Is there anyone I can generate this signal using the esp32?

Any help will really be appreciated!

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: very very slow pwm singal generation

Postby WiFive » Tue Jul 23, 2019 6:43 am

Use a timer. How accurate does it have to be?

Ian777
Posts: 21
Joined: Sun Jun 17, 2018 11:31 pm

Re: very very slow pwm singal generation

Postby Ian777 » Tue Jul 23, 2019 6:59 am

Hi WiFive,

This was the other option I was thinking of doing.

I was hoping that maybe the ledc module could do this.

I'd say if the timer has a period of 20 mins with a 10% duty, then a variation of 5% or less would be preferred.

I'm not too familiar with the esp32's timers. How would I go about setting the duty cycle?

Thanks for the help! appreciate it!

mikronauts
Posts: 23
Joined: Wed Dec 09, 2015 8:11 pm

Re: very very slow pwm singal generation

Postby mikronauts » Thu Jul 25, 2019 2:56 pm

Just use a timer interrupt
Ian777 wrote:
Tue Jul 23, 2019 6:59 am
Hi WiFive,

This was the other option I was thinking of doing.

I was hoping that maybe the ledc module could do this.

I'd say if the timer has a period of 20 mins with a 10% duty, then a variation of 5% or less would be preferred.

I'm not too familiar with the esp32's timers. How would I go about setting the duty cycle?

Thanks for the help! appreciate it!

Ian777
Posts: 21
Joined: Sun Jun 17, 2018 11:31 pm

Re: very very slow pwm singal generation

Postby Ian777 » Sat Jul 27, 2019 11:49 pm

Just use a timer interrupt
That's what I ended up on doing, Only issue is I need three of these triggering at different times (with an interrupt triggering the respective timer and switching the others off)

Although this code works perfectly to start the timer:

Code: Select all

                gpio_set_level(32, 0);
                gpio_output_disable(GPIO_NUM_32);
                gpio_set_level(27, 0);
                gpio_output_disable(GPIO_NUM_27);
                gpio_output_enable(GPIO_NUM_13);
                restoff_args.callback = Rest_toggle_timer;
                restoff_args.dispatch_method = ESP_TIMER_TASK;
                restoff_args.name = "Restontimer";
                esp_timer_create(&restoff_args,&restoffhandle);
                esp_timer_start_once(restoffhandle,reston*1000000);
Now I want to be able to disable the other timers when this one starts (if there not active it should just carry on) so I changed the code to this:

Code: Select all

                esp_timer_stop(dischargeonhandle);
                err=esp_timer_stop(chargeonhandle);
                gpio_set_level(32, 0);
                gpio_output_disable(GPIO_NUM_32);
                gpio_set_level(27, 0);
                gpio_output_disable(GPIO_NUM_27);
                gpio_output_enable(GPIO_NUM_13);
                restoff_args.callback = Rest_toggle_timer;
                restoff_args.dispatch_method = ESP_TIMER_TASK;
                restoff_args.name = "Restontimer";
                esp_timer_create(&restoff_args,&restoffhandle);
                esp_timer_start_once(restoffhandle,reston*1000000);
Sadly it works when the timers are active, although when the timer linked to dischargeonhandle and chargeonhandle isn't active the esp32 crashes. Is there anyway around this?

Who is online

Users browsing this forum: No registered users and 42 guests