Electronic – arduino – How to trigger an SCR after a certain time since the start of a cycle of mains voltage

arduino

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:
The output pulse should vary it's position within the Arduino code
What I've been finding:
The output pulse length will adjust which is irrelevant for my application
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:
enter image description here
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.

enter image description here

enter image description here

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:

while (true)
{
    // control_value variable holds the value that tells us after how much time
    // since the start of the sine wave, we should fire the SCR.
    unsigned char control_value;

    unsigned char timer1;
    bit SYNC_Control;

    while (1)
    {
        while (SYNC_Signal)
        {
        } // SYNC signal is LOW each time a cycle begins. Wait for first LOW.

        // We have got a SYNC signal. Invert the
        // control bit so that we trigger once at every two SYNC signals.
        SYNC_Control = ~SYNC_Control;

        if (!SYNC_Control)
        {
            // This is not the signal we want.
            goto end; // Exit the function. The function will search for an another SYNC signal next time.
        }

        // _50_us is a timer and increments every 50 microseconds.
        // _500_us is a timer and increments every 500 microseconds.

        // Record the beggining time of the cycle and use it as reference.
        timer1 = _50_us;

        while ((unsigned char) (_50_us - timer1) < control_value)
        {
        } // Wait until control_value*50us is passed.  

        TRIAC_Gate = 1; // Then fire the SCR.
        delay_ms(1);
        TRIAC_Gate = 0; // SCR is ON now, we do not need to set this pin high anymore.
end:
        NOP();
    }
}