As I understand you try to switch the DC side. In that case, if you replace the TRIAC with a MOSFET you can switch it on and off. A TRIAC switches itself off upon zero crossing, you can't switch it off any other way.
Need better image of that schematic to see what you're trying to do. Again an image of the expected waveform would be very helpful in this case.
Basically, with the MOSFET approach, what you need to do:
ISR () { // linked to a CHANGE on the zero crossing signal.
zeroCrossed = micros(); // Record the microsecond time.
zeroDetected = true;
}
loop() {
if (micros() - zeroCrossed >= 5330) {
// switch off MOSFET
else if (micros() - zeroCrossed >= 3000 && zeroDetected) {
zeroDetected = false; // ensure this can run only once per detected interrupt.
// switch on MOSFET
}
}
If you have more to do in your loop() and you're likely to be a little late in timing, you could use a timer interrupt for this.
When a zero crossing is detected, set the timer at 3000 us, when it's triggered set a new timer at 2330 us later and switch on the MOSFET, the next time switch off the MOSFET and reset the timer. Use a bool flags to keep track of which stage you are.
ISR () { // linked to a CHANGE on the zero crossing signal.
zeroCrossed = micros(); // Record the microsecond time.
zeroDetected = true;
set timer at 3000 us.
}
timerInterrupt() {
if (zeroDetected) {
set timer at 2330 us.
switch on the mosfet
zeroDetected = false;
else {
switch off the timer (no more timer interrupts until set again in the ISR())
switch off the mosfet
}
}