Hi Folks,
I am pretty new here, I'm working on a motor driver application on the maple and have a question about interrupts and timers.
My app requires 3 external pin interrupts (however these always call the same function) when a change is detected high/low or low/high.
It also has 2 timed interrupts, one runs at 10khz (so 100 microseconds) and the other runs at 20hz (50,000 microseconds).
My code is as follows for the setup:
// external interrupt setups for hall sensor detection
attachInterrupt(10, calcposition, CHANGE); // on change of state of pin 10, run calcposition function
attachInterrupt(11, calcposition, CHANGE); // on change of state of pin 11, run calcposition function
attachInterrupt(12, calcposition, CHANGE); // on change of state of pin 12, run calcposition function
// internal interrupt setups for timing syncs etc, use Timer 4 which is associated with pins 5, 9, 14, 24. Should avoid conflicts. Is used for 10khz interrupt
Timer4.setChannel1Mode(TIMER_OUTPUTCOMPARE);
Timer4.setPeriod(100); // timer period in microseconds, 100 is equal to 10khz
Timer4.setCompare1(100); // overflow might be small
Timer4.attachCompare1Interrupt(torqueloop); // when the interrupt triggers run the function torqueloop
// internal interrupt setups for timing syncs etc, use Timer ????
Timer3.setChannel1Mode(TIMER_OUTPUTCOMPARE);
Timer3.setPeriod(50000); // timer period in microseconds, 50000 is equal to 50 milliseconds or 20hz
Timer3.setCompare1(50000); // overflow might be small
Timer3.attachCompare1Interrupt(checkparms); // when the interrupt triggers run the function checkparms
I have timer 4 on the 10khz interrupt as I am using pins 6, 7 and 8 as PWM output pins. I have timer 3 on the other timed interrupt.
Should I set the overflow figure (I presume it is in microseconds??) to the same value as the interrupt timer value? as shown above.
Does this look right? any insight is appreciated, I am new to using interrupts but my code absolutely has to have them.
Thanks!