Timerone Question (1uS)

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?

All advice gratefully accepted...

Mike

You say 1µs (1 microsecond) in your title, Do you mean that or 1 millisecond.

In 1µs the Arduino can only do 16 instructions and your code will require far more than that.

Please tell us what you want to do rather than how you think it might be achieved.

...R

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...

Much appreciate the help...
Mike

Please answer the question in my last paragraph in Reply #1 so that we can make sensible suggestions.

Generating 1µs pulses with a 16MHz MCU is not going to leave much scope for other computations.

...R

I did...

I managed to solve the problem...
I extended the interrupt time to 1562µs and put the normal serial code inside the ISR...

Thanks for the help...
Mike

MikeOToole:
I did...

I had been hoping for a higher level description such as "I am trying to control a coffee grinder" or "I am trying to measure termite boring time"

Anyway, glad you have a solution.

...R