Hello to everybody,
i'm trying to convert a sketch running on arduino MEGA, to arduino DUE, but i've a problem with timer interrupt management.
the sketch is used to command a multichannel triac dimmer and i use timer interrept for sincronize and manage the zerocross signal and the firing of triac.
This is the code running on MEGA:
void setup() {
cli();
TCCR1A = 0x00; // clear
TCCR1B = 0x00; // clear
TIMSK1 = 0x02; // Enable the Output Compare A
OCR1A = 1250; // = 128 steps on 50hz with no timer prescale
sei();
}
ISR(TIMER1_COMPA_vect) {
dimLevel++;
for (int x = 0; x < countTriac; x++)
{
if (canaleTriac[x] = = dimLevel | | canaleTriac[x] = = dimLevel + 1) { // fire second triac
digitalWrite(pinTriac[x], HIGH);
}
}
if (dimLevel == MAX_LEVEL + 1) {
for (int x = 0; x < countTriac; x++)
{
digitalWrite(pinTriac[x], LOW);
}
TCCR1B = 0;
}
}
void zero_cross_detect() {
TCNT1 = 0; // reset timer - count from zero
TCCR1B = 0x09; // start timer with no prescale and reset tcnt1 on compare
start_low_fix = false;
dimLevel = 0;
}
the problem is that arduino due have different functions and registers for timer, and i'm not able to find the right way to write the code
someone found the same problem, or can give me help.
Thanks to everybody that will help me.