// Test Program to evaluate T1 Capture performance // Input configured for falling edge detection // Application Requirement Range is 1ms-10s // T1 clocked at 16MHz // Capture input (coupled with 4n7 and 1K Pullup) // Input using D8 (PB ) pin // Calibrated TTL Test Generator with // 0.1Hz-100kHz Output range // // 24-01-24 V1.00 #define ICP_INPUT 8 void setup() { pinMode(ICP_INPUT, INPUT_PULLUP); delay(100); init_InputCapture(); Serial.begin(115200); } void loop() { InputCapture_out(); delay(1000); } volatile unsigned long ICP_val = 0, T1OVF_Ctr = 0; /****************************************************************************** *Function: void InputCapture() *Description: *Parameters: None *Return Value: None ******************************************************************************/ void InputCapture_out() { double Freq = 0.0; if(ICP_val > 0) Freq = 16000000.0 / (double) ICP_val; Serial.print("ICP: "); Serial.print(ICP_val); Serial.print(" OVF: "); Serial.print(T1OVF_Ctr); Serial.print(" F: "); Serial.println(Freq, 4); } /****************************************************************************** *Function: void init_ICP() *Description: setup for ICP *Parameters: None *Return Value: None ******************************************************************************/ void init_InputCapture() { TCCR1A = 0; TCCR1B = 0; TIMSK1 = 0; // ICNC1 ICES1 – WGM13 WGM12 CS12 CS11 CS10 TCCR1B = (1<