I have added a third timer interrupt to my code and it's having a strange effect. (Mega 644)
I've added Timer 2 in phase correct PWM mode, set tgo interrupt at bottom. It works as expected because dependant on a flag in the ISR it moves a stepper motor and changing the timings produces expected changes in the speed of the stepper.
But the new ISR causes another routine that calculates sidereal time from the reading from an RTC to be wildly out every few calculations.
Of course I thought it was a variable being changes that needed to be popped on and off the stack or something like that, but no, I've gradually commented out more and more code. Here are two ISRs, the first is OK :
But this code causes the havoc:
TIMER2_OVF: in status,SREG out SREG,status reti
Now as the only real difference is the length of the routine, I wondered if I had got something wrong in the setup so the ISR is being called continuously? Can anyone see anything wrong here, because I can't?
;8 bit timer used for controlling the speed of slew movements, so approx 17 Hz for slowest move (1x tracking) up to arournd 3400Hz for fastest moves ldi temp,0<<WGM21|1<<WGM20 ;Phase correct PWM (up and down) interrupt at bottom, count in OCR2 sts TCCR2A,temp ldi temp,1<<WGM22|0<<CS20|0<<CS21|1<<CS22 ;Timer prescaler/64 = 256 KHz basic clock sts TCCR2B,temp ldi temp,36 ;chosen by experiment9 sts OCR2A,temp ;divides by previous number*2. then count interrupts to gives slower moves, divide by 215 gives appox 17 hz or slowest move ;tweak the value loaded to OCR2a to give most relaibe fast move, then tweak divisons to give stepped speeds