Hi,
Im trying to learn timers. But i just cannot understand what i'm doing wrong. trying to set prescaler to 8 to have 0.5us ticks.
the test code that i have is:
volatile int timeTicks;
void setup(){
Serial.begin(115200); // start serial
TCCR3A=0; // Clear A control bits
TCCR3B=0; // Clear B control bits
TCCR3A = (0 << WGM33) | (1 << WGM32) | (0 << WGM31) | (0 << WGM30); / Set CTC Mode
OCR3A = 2; // Set Compare to two ( 2x 0.5us = 1us )
TIMSK3 = (1 << OCIE3A); //Set timer mask 1
TCNT3=0; //Reset timer counter
TCCR3B = (1 << CS31) ; Select prescaler ( 16MHz with 8 prescaler is 0.5us pulse )
//sei();
}
void loop() { // print timer ticks in every one millisecond should be around 1000 because tick is every us)
Serial.println(timeTicks);
delay(1);
}
ISR (TIMER3_COMPA_vect) { //Add timertick on rollover an reset ticks every 60000 to have even numbers)
//timeTicks++;
if(++timeTicks < 60000)
return;
if (timeTicks = 60000) timeTicks = 0;
}
still i get output like this:
222
3222
3222
3222
3222
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3223
3224
3224
3224
the 1us i'm trying to aim is now about 27ms
something is cleatly wrong and i have gone several guides and processor specs thru dun i don't see the problem