TMR1 How it works?


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    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

  2. #2
    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