I want to use the timer interrupt to generate a series of sequential pulses.
Basically each call increment a counter which I then check and based on the value I know which pulse to start or stop...
Here's what I came up with...
Timer1.initialize(5); // 5 uS (yes?)
Timer1.attachInterrupt(do_isr); // callback
void do_isr()
{
if (in_isr)
{
return;
}
in_isr = true;
interrupts();
if (timer == 0)
{
PINC = 0x01; // pulse on
}
else if (timer == TX_PULSE)
{
PINC = 0x01; // pulse off
}
// one or two more if statements for other pulses //
timer++;
if (timer >= WAIT_PERIOD) // cycle over, start again //
{
timer = 0;
}
noInterrupts();
in_isr = false;
}
First off, are there any issues with the code?
Am I packing too much into the ISR?
Would using two or more interrupts be of any advantage (sharing the load)?
Is there a better way to approach this?
The "16 instructions" in 1µs pretty much answers the question...
Here's what I am trying to do...
Increment a counter...
Check the value against three stored values...
Set/Unset three outputs based on the results...
Obviously I cant do this with 16 instructions, so how would I go about doing this with timer interrupts?
I currently do this inside the main loop and the entire process take 300µs (leaving 1300µs before the next cycle for the rest of the code), but delayMicroseconds wastes a lot of valuable processing time...