Page 1 of 1

very very slow pwm singal generation

Posted: Tue Jul 23, 2019 6:25 am
by Ian777
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!

Re: very very slow pwm singal generation

Posted: Tue Jul 23, 2019 6:43 am
by WiFive
Use a timer. How accurate does it have to be?

Re: very very slow pwm singal generation

Posted: Tue Jul 23, 2019 6:59 am
by Ian777
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!

Re: very very slow pwm singal generation

Posted: Thu Jul 25, 2019 2:56 pm
by mikronauts
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!

Re: very very slow pwm singal generation

Posted: Sat Jul 27, 2019 11:49 pm
by Ian777
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?