Trying to measure time between two pulses on different pins.


Results 1 to 27 of 27

Threaded View

  1. #21
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Trying to measure time between two pulses on different pins.

    Hi Ryan,
    I fixed ADCON1 (= 7) and TRISB to output on B.3 and now I have a pulse! The only problem is that it seems to be 38.1Hz
    That 38.1Hz tells me that your interrupt rate is 76.2(939)Hz, which is exactly what you get when you have 16bit timer free-running at 5MHz. (20Mhz / 4 / 2^16).

    On the 16F648 TMR0 is 8 bits wide with an 8bit prescaler shared with the WDT....
    On the 18F2320 TMR0 is configurable to be either 8 bit OR 16 bit wide with its own dedicated 8 bit prescaler.

    Going by your description alone and not seeing the actual code my guess is you've got the timer configured in 16 bit mode. That'll work too but the code needs to be changed to use the full 16 bit timer instead of the 8bit timer AND 8bit prescaler of the 16F648.

    Not knowing what "TMR0 = TMR0 + 94" for me is doing exactly (maybe preloading timer 0 so it overflows earlier or something?) and it has a nice integer there to play with, I changed it to various things, but no difference in the 38.1Hz.
    Yes exactly. In the original code where we had a 8 bit timer, "restarting" the timer at value of 94 each interrupt (which isn't REALLY what happens but it's easier to understand) will cause it to overflow in 162 ticks (256-94) instead 256 ticks. With a a 16bit timer running at 5MHz, "restarting" the timer at 94 to in the ISR will only change the interrupt rate by approximately 0.11Hz which is probably why you think you don't see it change.

    /Henrik.
    Last edited by HenrikOlsson; - 3rd September 2014 at 21:09.

Similar Threads

  1. Measure time in mS between two pulses
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 7th March 2011, 07:20
  2. time measurement between 2 pulses
    By xvladx in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 27th April 2010, 17:33
  3. calculate time between pulses
    By hell_pk in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 20th October 2007, 16:49
  4. Count pulses between VARIABLE TIME
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2007, 12:44
  5. Timed pulses on 2 pins
    By Danie Joubert in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th March 2004, 07:38

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts