First of all, I've been working with Arduino for just about 1-2 weeks so please excuse my lack of knowledge. I'm working on a project in which I'm trying to create a DC/AC converter from scratch, controlled by an Arduino.
Anyway, someone at school that worked on a similar project gave me this code for an interrupt. However, it's for an Arduino Uno and I cannot for the life of me figure out which Due register equals each Uno register. I'm comparing between the datasheets for each model, looking after the registers that serve the same purpose, but I must be doing something wrong. For example, from what I understand, Timer/Counter Control Register in Uno would equal TC Channel Mode Register in Due. Yet, whenever I try to verify my code, TC_CMR0 appears undeclared.
Anyway, here's the code I was given:
void interrupt_setup()
{
noInterrupts(); //disable interrupts
TCCR4A = 0;
TCCR4B = 0;
TCNT4 = 0;
TCCR4B |= (1 << CS42);
TCCR4B |= (1 << CS40); //1024 prescaler => 16MHz/1024=15625Hz
TCCR4B |= (1 <<WGM42); //CTC mode
OCR4A = 1560; // for 6.4e-5 seconds -> 1; for 1 second -> 15625 we choose 15625-1
TIMSK4 |= (1 << OCIE4A); //enable timer compare interrupt
interrupts(); //enable interrupts
}
ISR(TIMER4_COMPA_vect) // timer compare interrupt service routine
{
if (HIGH == digitalRead(22)) digitalWrite(22, LOW);
else digitalWrite(22, HIGH);
flag1 = 1; //leads to PID activation
timer = timer + 1;
float power = U_real*I_out;
communication(U_real2,U_real,10,I_out,10,dutycycle,timer,setpoint_U,power,I_out2);
}
Please tell me if I'm approaching this totally wrong or something else that I should do.