Go Down

Topic: 0.1ms ISR (Read 319 times) previous topic - next topic

Hakuin

Hello!

I have a project  using an Arduino Mega 2560.

In this project the internal timer is used to call the ISR service routine every 0.1ms.
Code: [Select]

...
  cli();
 
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0; 
  OCR1A = 1599; //top
  TCCR1B |= (1 << WGM12); //-> clear timer on compare match
  TCCR1B |= (1 << CS10); //no prescaler

  sei();
 TIMSK1 |= (1 << OCIE1A);
...


ISR(TIMER1_COMPA_vect)
{
... // Set outputs to generate 0.1ms puls
}



This is working fine but I'm getting temperature problems. The timer is not exact enough. Sometimes I need to use OCR1A = 1599; Sometimes I get up to 1606;


As far as I know the next step should be an external RTC or quarz to get better results but I'm stuck.
Currently I would try to attach the 32mHz signal of a ds3231 RTC or a temperature compensated quarz.
I have read I can use this external signal as input for timer 2 but without prescaler.

Or I would need an external 0.1ms source.

Any ideas on how to go from here ?
Looking forward hearing from you!
Best regards!

AWOL

Quote
Currently I would try to attach the 32mHz signal of a ds3231 RTC
32mHz is one cycle every 31.25 seconds

Delta_G

32mHz is one cycle every 31.25 seconds
You can do that with the blink without delay style.  You don't need an interrupt to catch something once every 30 seconds. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

MorganS

Look at the TimerOne library.
"The problem is in the code you didn't post."

jremington

#4
Jan 30, 2019, 07:46 pm Last Edit: Jan 30, 2019, 07:47 pm by jremington
Quote
I have read I can use this external signal as input for timer 2
Timer2 can be used as a counter and an RTC if a 32 kHz low power watch crystal and appropriate capacitors are connected to the crystal oscillator pins.

This would be more for a bare bones Arduino, and probably not an option with a commercial Mega2560 board.

I believe that all of the other timers can use an external signal on an I/O pin as a clock source.

Go Up