Hi
I'm using an atmega328 to build an engine controller for a final year project and I've run into a problem I can solve.
I initially used the 16bit timer1 as a counter for the encoder, and then periodically fetched the value for TCNT1.
However, using timer1 as a counter prevents the servo function from working, which I need to actuate the engine trottle.
I've tried using timer0, but that seemed to disable the serial com, and I can't figure out how to use timer2 as a counter.
If anyone can help setting up timer2 as a counter, or knows of another method of using a high speed encoder (up to 5000 inputs per second) and servo motor together, i'd be extremely grateful.
This is the timer 2 setup thats not working:
TIMSK2 = 0; // Disable timer2 interrupts
ASSR = 0b01000000; // Enable external clock as source
// ASSR | 0b00100000; // Set to asnychronous mode ???
// Apparently timer must be asnychronous to use the external source
TCCR2A = 0; // Disable Waveform Generation Mode
TCCR2B = 0; // Use clock with no prescaler
TCNT2 = 0; // Clear the counter
TIFR2=0; // Clear the interrupt flag register
TIMSK2 = 1; // Enable overflow interrupts