PWM with sync input

User avatar
tomi_isp
Posts: 2
Joined: Tue Sep 10, 2019 4:19 pm

PWM with sync input

Postby tomi_isp » Tue Sep 10, 2019 4:29 pm

Hi,

I need (on ESP32) generate PWM signal (400Hz), this is fine but I need to sync this PWM to AC mains 50Hz (via optocoupler).
Can anyone point me how to do on ESP32/Arduino ? In old design (M2560) I have connected "sync" signal to INT pin and just reset/restart Timer what generates PWM on each rising edge. How to make it on ESP32?
And second question, I also need to measure duty cycle of PWM signal (again ~400Hz), any idea/example?
All what I need to do is convert/measure input PWM signal (not stable, ~400Hz, not synced to AC) to stable 400Hz PWM synced to AC frequency. (Duty cycle at input/output is recalculated/optimized but that is not important for this question)

Thanks for any help or idea
/Tomi

arnoldg
Posts: 2
Joined: Sun Sep 01, 2019 6:07 am

Re: PWM with sync input

Postby arnoldg » Fri Sep 13, 2019 8:01 pm

Hi,

Have you looked at MCPWM, i'm using it for a AC Dimmer.
It works great, please keep in mind that if you use a optocoupler for synch use a dual schmitt trigger to get a stable signal.
i had some interupt errors.

http://www.bristolwatch.com/ele2/zcnew.htm

markiv
Posts: 2
Joined: Mon Sep 16, 2019 7:46 am

Re: PWM with sync input

Postby markiv » Mon Sep 16, 2019 7:51 am

Hey I am too trying to make a ac dimmer using mcpwm but their is lot of flickering !, I am using 4n35 optocoupler and getting a smooth wave .

User avatar
tomi_isp
Posts: 2
Joined: Tue Sep 10, 2019 4:19 pm

Re: PWM with sync input

Postby tomi_isp » Wed Sep 18, 2019 1:05 pm

Hi,

after some experiments I was able to set PWM/SYNC with mcpwm in Arudino, seems this works fine but I also try to setup Capture mode, I follow example for mcpwm but I stuck on reading/setting registers, problem is with this lines:
  1. static mcpwm_dev_t *MCPWM[2] = {&MCPWM0, &MCPWM1};
it end with error: 'mcpwm_dev_t' does not name a type

and of course this lines is affected :
  1. mcpwm_intr_status = MCPWM[MCPWM_UNIT_0]->int_st.val;
  2. MCPWM[MCPWM_UNIT_0]->int_clr.val = mcpwm_intr_status;
  3. MCPWM[MCPWM_UNIT_0]->int_ena.val = CAP0_INT_EN;
have anyone idea what is wrong or how to fix this (in Arduino) ?

Thanks
/Tomi

Who is online

Users browsing this forum: Baidu [Spider] and 11 guests