Hi,
I'm building a rangefinder project that transmits a signal on each Timer 0 interrupt on compare match (via PD3. It is my transmitter pin). And the MCU receives the amplified square wave from the receiver on PD5 (which is the INT0 pin) for processing of time and hence distance etc.
My question is where does timer 1's Input capture fit into all this?
I'm planning on having 2 different functions that are called:
startTIMER(); // This will be placed in the transmitter code function
// Enables Timer 1's input capture, starts counting
stopTIMER(); // This will be placed in the receiver code function
// Stops Timer1, records elapsed time and converts into ms
Since I'm sending a burst on each interrupt it will start the timer 1. And then on a receive where it performs an interrupt (INT0) it will stop the timer via the function stopTIMER() that will be placed within the ISR at the end.
2 issues:
For input capture to work from my understanding is that the receive signal must come to the ICP pin. However my signal is coming to the PD5 pin (INT0).
And lastly once I stop the timer via TCCR1B = 0x00;, the value of ICR1 (sorry im saying this from the top of my head its late night) will give me the time in ms?
I've read the material from various places and people say and do different things so I'm kinda confused sorry.
What I have done here is for the initialization of Timer 1, this was done in main:
TCCR1B = 0x01; // Enable Capture on falling edge, with prescaler of 1
TIMSK = 0x20; // Enable Input Capture Interrupt Enable
I made it capture on a falling edge since my receiver interrupt (INT0) is set to trigger on an falling edge. Also I'm using a 16MHz crystal.
From here on I'm not sure how to start it off would like some advice thanks.
I'm building a rangefinder project that transmits a signal on each Timer 0 interrupt on compare match (via PD3. It is my transmitter pin). And the MCU receives the amplified square wave from the receiver on PD5 (which is the INT0 pin) for processing of time and hence distance etc.
My question is where does timer 1's Input capture fit into all this?
I'm planning on having 2 different functions that are called:
startTIMER(); // This will be placed in the transmitter code function
// Enables Timer 1's input capture, starts counting
stopTIMER(); // This will be placed in the receiver code function
// Stops Timer1, records elapsed time and converts into ms
Since I'm sending a burst on each interrupt it will start the timer 1. And then on a receive where it performs an interrupt (INT0) it will stop the timer via the function stopTIMER() that will be placed within the ISR at the end.
2 issues:
For input capture to work from my understanding is that the receive signal must come to the ICP pin. However my signal is coming to the PD5 pin (INT0).
And lastly once I stop the timer via TCCR1B = 0x00;, the value of ICR1 (sorry im saying this from the top of my head its late night) will give me the time in ms?
I've read the material from various places and people say and do different things so I'm kinda confused sorry.
What I have done here is for the initialization of Timer 1, this was done in main:
TCCR1B = 0x01; // Enable Capture on falling edge, with prescaler of 1
TIMSK = 0x20; // Enable Input Capture Interrupt Enable
I made it capture on a falling edge since my receiver interrupt (INT0) is set to trigger on an falling edge. Also I'm using a 16MHz crystal.
From here on I'm not sure how to start it off would like some advice thanks.