TMR1 How it works?


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    In changing the Interrupt Handler (ClockCount: ), it has changed the number of system variables it uses. The comparison [if Ticks = 1000 THEN] uses the CMPNE macro which uses the R4 system var.

    So the R4 variable needs to be saved and restored the same way as R0 and R1 are saved in the ClockCount routine.

    And the constant should be $FC20 which is 8 counts less. This accounts for the time it takes to reload the timer.

    HTH,
    DT

  2. #2
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default minimum time for checking all the ports

    Thanks Taylor and Happy New Year,

    I manage to make my RTC with resolution in 1m, following your instructions.
    I test it for 7 hours and I have lost 1sec.That is ok for my project.

    Continioing my project I wonder if I can check all the ports 12 TOTAL (PORTA&PORTB) of the PIC16F628 in a time aproximatelly 500μsec?
    I am going to use 20Mhz osc do the pic faster.

    Please advice
    Nikos

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    In 500μs, you can do all kinds of stuff.

    Checking 2 ports at 20mhz shouldn't take more than 1-2μs. but I guess it depends on what you want to do with it after that.
    <br>
    DT

  4. #4
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default

    Taylor,

    Thanks for your interested.
    So, you said that the following code running in 20mhz take 2μsec:
    ----------------------------
    START:
    If PORTA.1 = 1 THEN
    GO TO SOMEWHERE1
    ENDIF
    If PORTA.2 = 1 THEN
    GO TO SOMEWHERE2
    ENDIF

    GOTO START
    --------------------------

    I need to check all the ports of A&B in a loop.
    1 LOOP SHOULD TAKE MAXIM 500μsec.

    Please advice
    Nikos

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ngeronikolos View Post
    Taylor,

    Thanks for your interested.
    So, you said that the following code running in 20mhz take 2μsec:
    ----------------------------
    START:
    If PORTA.1 = 1 THEN
    GO TO SOMEWHERE1
    ENDIF
    If PORTA.2 = 1 THEN
    GO TO SOMEWHERE2
    ENDIF

    GOTO START
    --------------------------

    I need to check all the ports of A&B in a loop.
    1 LOOP SHOULD TAKE MAXIM 500μsec.

    Please advice
    Nikos
    MPLab has a fine, working simulator in it that will count cycles/time for whatever you want. You just have to set breakpoints at the correct places and keep track of the count in the window. And you can check your .lst file to actually count the number of instruction words used by a particular statement.

    At any rate,

    Clk = 20mhz = 5mhz instruction rate = .2us per instruction

    START: = 0 cycles

    If PORTA.1 = 1 THEN
    GO TO SOMEWHERE1
    ENDIF

    is roughly equivalent to a BTFSS instruction, 2 cycles

    depending on the PIC and options used, checking all bits in Port A and B is 16 checks. Total of 32 cycles just for the checking. Add in 2 cycles for the jump back to the start, 34 cycles.
    So, this loop, not including the GOTO SOMEWHEREs, takes about 34 cycles.

    But, we haven't including any PBP interrupt checking or CLRWDTs yet. So, assume that you have an ON INTERRUPT statement somewhere, add in another 8 cycles (I think, I'll check when I get home) for each interrupt check, which happens before each PBP statement. Same thing for a CLRWDT.

    Total so far = 34 + ( 17 * 8, interrupt check) + ( 17 x 1, CLRWDT ) = 187 cycles. .2us per cycle * 187 cycles = 37.4us per loop not including any goto's. 26738hz loop rate.

    Again, if you have any doubts, check your .LST file generated by the assembler and manually count the number of instructions between the start and end of the loop.

Similar Threads

  1. Simple TMR1 application example needed
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th February 2010, 09:52
  2. TMR1 external LP xtal setup check
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th October 2009, 18:11
  3. Replies: 2
    Last Post: - 7th October 2009, 00:06
  4. Replies: 42
    Last Post: - 14th January 2008, 11:38
  5. Measuring change of frequency with PIC
    By Aussie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 01:47

Members who have read this thread : 1

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