synchronize pic18f4550 pwm with external signal

Thread Starter


Joined Jun 12, 2016

I want to control the trigger angle of a triac connected to AC power (60Hz). My guess is that I can do it by changing the duty cycle of a 120Hz pwm generated by the PIC.

I have a zero crossing detector circuit that generates a pulse on every semicycle start, but I can't figure how am I supposed to synchronize it with the pwm. Since I can't generate exactly 120Hz (closest I got was 122Hz), I have to reset (restart) the PWM period everytime I receive the zerocrossing pulse, but I don't really get how to do it.. Any help would be appreciated.

I'm using PIC18f4550 with XC8 compiler on MPLAB IDE.


John P

Joined Oct 14, 2008
I don't see why you need a PWM signal. I've had to do this, to operate a vibrating conveyor that ran off the power line, and I just set up a trigger that operated from a zero crossing (an optoisolator, as I recall) and then generated a time interval from that, to produce the "on" time for the power control element. No PWM needed, because each cycle was individually triggered and timed.