I am looking for an Arduino code that uses PWM. Mine's a little different than most PWM programs however because I am looking to create some sort of reference point within the code to not only vary the duty cycle, but to control where my output pulse will trigger on the sine wave. It's a little hard to visualize, so here are a few pictures:
What I want to find:
What I've been finding:
The image above is the typical PWM code I've been finding, but it is irrelevant to my application because I will be triggering an SCR (which only recognizes the rising edge of the output pulse).
Below is a general idea of how I want to control the SCR firing angle:
So I'm thinking I will need some sort of reference point within the code to make the falling edge of the duty cycle be where my output pulse will trigger. That is my only clue how to attack this problem. Please let me know if I was not very clear on certain specifics with this issue.
Best Answer
As far as I understood, you want to clip some portion of the sine wave using an SCR. Also, you want to control the SCR with an Arduino. To do that, as you have noted, you will need a reference point, and that is the start of the sine wave. To achieve what you are trying to do, please follow below instructions.
After the start of the sine wave cycle, start a count-down timer in the software. When the timer finishes counting, fire up the SCR. The SCR will then be using this fire until the end of the sine wave cycle and will stay ON until then. Now, repeat the same for other cycles.
Warning: Below circuits include contact with mains voltage. Please be careful and know how to interact with mains voltage before attempting to build these circuits.
Above circuit create a digital output with respect to mains. It will give a LOW output at SYNC_In whenever a zero-crossing is detected. But be careful, because this will generate an output whenever the AC sine wave crossing zero level in either directions, meaning that this will output at every half cycle, or at 100 Hz if your mains is at 50 Hz.
Now that you have a circuit that tells you whenever a cycle begins, you can create a software that will fire up the SCR, a certain time after a cycle begins. To control the SCR, I would recommend you using an optocoupler.
Here is an example pseudo code that does this job: