int a=0;
int b =0;
void setup()
{
pinMode(47,INPUT);
pinMode(49,INPUT);
pinMode(44,OUTPUT);
pinMode(45,OUTPUT);
pinMode(46,OUTPUT);
//TCCR5A = 0; // Clear the TCCR5A register
//TCCR5B = 0; // Clear the TCCR5B register
// Set the Timer mode to Normal mode
// TCCR5B &= ~(1<<WGM52);
// TCCR5A &= ~(1<<WGM50);
//TCCR5A &= ~(1<<WGM51);
// Set the Clock Select bits to use the external clock source on T5 pin (pin 47)
//TCCR5B |= (1<<CS50);
//TCCR5B &= ~(1<<CS51);
//TCCR5B |= (1<<CS52);
// Reset the Timer 5 counter
//TCNT5 = 0;
/*TCCR5A = 0; // Init Timer1
TCCR5B = 0;
TCCR5A = B01010100; //a 1 is need in the A reg to turn each pin
TCCR5B |= B00000011; // Prescalar = 64
TCNT5 = 63035; // Timer Preloading
TIMSK5 |= B00000001;
//OCR5A = 5000; // Timer CompareA Register
//OCR5B = 5000;
// OCR5C = 5000;
//TIMSK5 |= B001110; // Enable Timer COMPA Interrupt
*/
// Set up Timer 5
TCCR5A = 0; // Clear the TCCR5A register
TCCR5B = 0; // Clear the TCCR5B register
// Set the Timer mode to Normal mode
TCCR5B &= ~(1<<WGM52);
TCCR5A &= ~(1<<WGM50);
TCCR5A &= ~(1<<WGM51);
// Set the Clock Select bits to use the external clock source on T5 pin (pin 47)
TCCR5B |= (1<<CS50);
TCCR5B &= ~(1<<CS51);
TCCR5B |= (1<<CS52);
// Reset the Timer 5 counter
TCNT5 = 0;
Serial.begin(9600);
Serial.println(TCCR5A,BIN);
Serial.println(TCCR5B,BIN);
Serial.println(TIMSK5,BIN);
}
void loop()
{
a=digitalRead(47);
//Serial.print("Counter Ticks COMPAIR = ");
//Serial.println(TCNT5);
Serial.print("Counter Ticks OVERFLOW = ");
Serial.println(a);
// Serial.print("Counter Ticks = ");
//Serial.println(TCNT5);
delay(250);
}
ISR(TIMER5_COMPA_vect)
{
//Serial.print("Counter Ticks COMPAIR = ");
//Serial.println(TCNT5);
OCR5A =OCR5A+5000 ; // Advance The COMPA Register
// Handle The 100ms Timer Interrupt
}
ISR(TIMER5_COMPB_vect)
{
//Serial.print("Counter Ticks COMPAIR = ");
//Serial.println(TCNT5);
OCR5B += 5000; // Advance The COMPA Register
// Handle The 100ms Timer Interrupt
}
ISR(TIMER5_COMPC_vect)
{
//Serial.print("Counter Ticks COMPAIR = ");
//Serial.println(TCNT5);
OCR5C += 5000; // Advance The COMPA Register
// Handle The 100ms Timer Interrupt
}
ISR(TIMER5_OVF_vect)
{
TCNT5 = 63035; // Timer Preloading
// Handle The 100ms Timer Interrupt
//...
}