Calibrating time measured on pulses received

Discussion in 'Embedded Systems and Microcontrollers' started by Vindhyachal Takniki, Feb 23, 2015.

  1. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    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.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,447
    3,362
    For starters, tell us which MCU you are using.
     
  3. ScottWang

    Moderator

    Aug 23, 2012
    4,855
    767
    He just talks to himself and ignore all others, you and me and all members didn't exist.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    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?
     
  5. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    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
     
Loading...