For the moment lets consider an ideal signal that's 50 Hz and almost looks like a square wave.
From 0 to 180 deg it's say 100 and from 180+ to 360- it's zero.
Now lets think about pulsing it for 100 uS every 100 uS.
With this signal it's easy to find the start or rising edge. This would be the zero cross for an AC signal which we know is not ideal. You can call an ISR (TRIGGER) when this signal goes high easy enough.
Now since you want a 100 uS pulse train, then make an ISR (FIRE) that is to be called every 100 uS starting at the edge.
FIRE might look like:
Disable interrupts
IF SLOT < WHAT_SLOT, then 1$
If CYCLE is TRUE, then TURN SCR ON; CYCLE = FALSE : RETURN from interrupt
IF CYCLE is FALSE then turn SCR off ; CYCLE = TRUE; RETURN from interrupt
1$: CYCLE = FALSE
Return from interrupt
END FIRE
TRIGGER might look like
Disable interrupts
CYCLE = LOW : Set up Timer based call to FIRE every 100 uS
Set SLOT to 0
END TRIGGER
PID could run every X slots or could run by itself every so often.
PID just has to update the slot variable after indexing for % ON.
Caveats:
I didn;t play computer
I didn;t pay any attention to starting at counting at zero or one.
I didn't correct for varying frequency.
I didn;t correct for dead time.
I didn't pretend it is a sine wave with a top and a bottom.
The waveform is super simple and only deal with the first half.
So, the idea is to divide the waveform into slots of on/off which is the trigger length and use that as your basic timing. You start the timing when you get a voltage zero cross. Now, the problem is to handle the weirdness. You have a delayed zero cross, so maybe start some x*100 us later or start at slot 2 and maybe ignore the last two slots. e.g. Don't fire the SCR if in the last two slots.
Do you have to slightly correct for frequency or even correct for frequency. Do you care if it doesn't work in 60 Hz environments?
The idea is to get a consistent trigger during the power cycle without accidentally trigging one at the end or put another way, the SCR firing pulse is not there some time before the next zero cross.
From 0 to 180 deg it's say 100 and from 180+ to 360- it's zero.
Now lets think about pulsing it for 100 uS every 100 uS.
With this signal it's easy to find the start or rising edge. This would be the zero cross for an AC signal which we know is not ideal. You can call an ISR (TRIGGER) when this signal goes high easy enough.
Now since you want a 100 uS pulse train, then make an ISR (FIRE) that is to be called every 100 uS starting at the edge.
FIRE might look like:
Disable interrupts
IF SLOT < WHAT_SLOT, then 1$
If CYCLE is TRUE, then TURN SCR ON; CYCLE = FALSE : RETURN from interrupt
IF CYCLE is FALSE then turn SCR off ; CYCLE = TRUE; RETURN from interrupt
1$: CYCLE = FALSE
Return from interrupt
END FIRE
TRIGGER might look like
Disable interrupts
CYCLE = LOW : Set up Timer based call to FIRE every 100 uS
Set SLOT to 0
END TRIGGER
PID could run every X slots or could run by itself every so often.
PID just has to update the slot variable after indexing for % ON.
Caveats:
I didn;t play computer
I didn;t pay any attention to starting at counting at zero or one.
I didn't correct for varying frequency.
I didn;t correct for dead time.
I didn't pretend it is a sine wave with a top and a bottom.
The waveform is super simple and only deal with the first half.
So, the idea is to divide the waveform into slots of on/off which is the trigger length and use that as your basic timing. You start the timing when you get a voltage zero cross. Now, the problem is to handle the weirdness. You have a delayed zero cross, so maybe start some x*100 us later or start at slot 2 and maybe ignore the last two slots. e.g. Don't fire the SCR if in the last two slots.
Do you have to slightly correct for frequency or even correct for frequency. Do you care if it doesn't work in 60 Hz environments?
The idea is to get a consistent trigger during the power cycle without accidentally trigging one at the end or put another way, the SCR firing pulse is not there some time before the next zero cross.