Calculating time delay between two inputs?


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Yes i do not have obligation to use f84, and i know f877 has Timer1(16bit). Let us check this;

    i will use 4MHZ xtal and f877, and it has 16 bit timer ~= 66ms is more than enough for me.

    So i do not need to use watchdog timer prescaler commands and i just need to use,

    OPTION_REG.5=1 and OPTION_REG.5=0 commands for timer right?
    Last edited by grimmjow; - 15th October 2010 at 21:52. Reason: typing error

  2. #2
    Join Date
    Oct 2010
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    i've looked up f877 datasheet and TMR1 has its own control register (we can enable and disable it) and it's two paired (TMR1H and TRM1L)

    i am not sure but this is algorythm as i understand, if TMR1L=255 then TRM1H=TMR1H+1

    and if i sum them up, timepassed=TRM1H*255+TMR1L i can find time in useconds.

    Thanks for your helps.

    Quote Originally Posted by grimmjow View Post
    Yes i do not have obligation to use f84, and i know f877 has Timer1(16bit). Let us check this;

    i will use 4MHZ xtal and f877, and it has 16 bit timer ~= 66ms is more than enough for me.

    So i do not need to use watchdog timer prescaler commands and i just need to use,

    OPTION_REG.5=1 and OPTION_REG.5=0 commands for timer right?

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


    Did you find this post helpful? Yes | No

    Default

    Ioannis,
    Thanks for catching the typo! As for the prescaler not clearing, I actually thought about that but the datasheet says that writing to TMR0 does clear the prescaler (when it is assigned to TMR0) so it shouldn't be an issue. Now, with the '877 it's of little importance anyway.

    grimmjow,
    Yes, TMR1 on the 'F877 is controlled thru its own control register and you get its 16bit value almost like you shown:

    timepassed = TMR1H * 256 + TMR1L

    Make sure you stop the timer before reading it or you MAY get weird results if the low byte happens to roll over between you reading it and the high byte.

    And no, you don't need to use any prescaler since the 16bit wide timer allows you to measure 65535us which is far more than you need.

    Good luck!
    /Henrik.

  4. #4
    Join Date
    Oct 2010
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Thanks a lot for your helps, HenrikOlsson and Ioannis.

    It is great for beginners to ask pros like you. i will try these codes and im pretty sure that it'll work. I'll let you know if i have problems about some parts again.

    Have a nice day.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Henrik: I missed that part about the prescaler on F84. Good one!

    grimmjow:

    remember to declare timepassed as a word variable.

    Given that you will still be using 4MHz crystal, the timer step will be 1usec.

    Ioannis

  6. #6
    Join Date
    Oct 2010
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    Henrik: I missed that part about the prescaler on F84. Good one!

    grimmjow:

    remember to declare timepassed as a word variable.

    Given that you will still be using 4MHz crystal, the timer step will be 1usec.

    Ioannis
    Thank you Ioannis, i'm using it as word.

    Btw circuit works fine thnx for your efforrs both Ioannis and HenrikOlsson

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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