Calibrating time measured on pulses received

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
594
1. I have to measure time between two pulse signal coming on two pins.
As soon as rising edge comes on pin 1, I start the timer until second signal on other pin.
So basically time measurement is done between signal on two pins.

2. Code is
while(1)
{
rest all paras;
configure timer;
wait for pulse on pin 1;
start timer;
wait for pulse on second pin; /* when pulse comes on second pin, EXTI ISR read the timer value */
}

3. When I give 1us pulse diff on two pins, on first iteration of loop, I read 1.383us & for subsequent loops I read 1.35us.
(i.e when loop runs for first time)
Similarly for 11us, on first iteration of loop, I read 11.383us & for subsequent loops I read 11.35us.
Similarly for 111us, on first iteration of loop, I read 111.383us & for subsequent loops I read 111.35us.
Similarly for 500us, on first iteration of loop, I read 500.383us & for subsequent loops I read 500.35us or 500.717us.


4. I don't understand why error on first pulse.
5. Is there any method for calibration for measured time also or best way is to do the subtract the offset.
6. External pusles are generated at same pulse via another MCU.
 

ErnieM

Joined Apr 24, 2011
8,377
Vindhyachal: the code you outline does not read a second pulse. No comment is possible until you show us how it loops.

What is the ISR? Where did that happen?
 

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
594
1. I am using 32 bit cortex-m3
2. When first pulse comes, control goes to pin ISR & starts the timer.
3. When second pulse comes, control again goes to pin ISR & stops the timer & read its value
 
Top