TMR1 How it works?


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120

    Question TMR1 How it works?

    Hi,

    I was looking to the Melanie's Olympic Timer project trying to find some
    answers for my project.What I do not understand is how the TRM1 works.How it works backround of
    my main code?How it starts and how it stops?
    Can I store any time the current value of TMR1 in a variable?

    My project:
    I have two PIC's (A&B). 8 photransistors are connected to PORTB of each PIC.
    I have a loop checking the PORTB of the PIC A.If there is a trigger of any phototransistor of PIC A it is sure that I will
    have a trigger from the second group of phototransistors (PICB).I want to measure
    the time (is critical for me accuracy in μsecs) between the trigger in A anb B.

    CAN I DO MY MEASURMENT WITH TMR1.I NEED SOME EXAMPLES TO SEE HOW IT WORKS.
    PLEASE ADVICE


    Thanks in advance
    Regards
    Nikos

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    read the section 4.0 of the OlympicTimer document
    http://www.picbasic.co.uk/forum/atta...4&d=1091819883

    RunningFlag variable start and stop the timer.. at least the increment of. Look at the TickCount section.

    Yes you should be able to Store the TMR1 result at any time without too much effect. But the results you need are not store there. See ...
    Code:
    LCDOut $FE,$80,DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds,".",DEC2 Hundredths
    Last edited by mister_e; - 18th December 2006 at 05:26.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    hi,

    I have already read the OlympicTimer document and it is hard for me to undertand how it works(TMR)?
    That is the reason I am asking you?
    Let's have an example:

    Check all the portb of the PIC A for trigger
    SELECT CASE PORTB
    CASE 00000001
    STORE TMR1 <------
    CASE 00000010
    STORE TMR1 <------
    CASE 00000100
    STORE TMR1 <------
    CASE 00001000
    STORE TMR1 <------
    CASE 00010000
    STORE TMR1 <------
    CASE 00100000
    STORE TMR1 <------
    CASE 01000000
    STORE TMR1 <------
    CASE 10000000
    STORE TMR1
    END SELECT


    How I can do that?How I can start the TMR RUNNING?

    Please advice
    Nikos

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


    Did you find this post helpful? Yes | No

    Talking

    Hello to everyboby and Happy New Year.

    I hope that all of your dreams came true in 2007.
    Back to code now...
    I find, while I search and search, the TEST_ELAPSED_SER.PBP code by Darrel Taylor.
    With this you can view a real time clock with HyperTerminal.
    That is what I need. But Taylor has a TICK every 1/100th of a second=10msec with 4Mhz external osc.
    I want 1msec TICK in a format 0d-00:00:00:000.How I am going to do it?
    What i did but it did not work.
    TIMER1 should be tick every 1000μsec 65536-1000 = 64536 FC18 (HEX).

    Have a look to my code and please let me know where is the faulty?
    I have change in the Elapsed.bas
    1.Ticks var word
    2.TimerConst to 0FC18h
    3.if Ticks = 1000 then
    Ticks = Ticks-1000

    The clock did not working.

    Please if Ticks = 1000 then
    Ticks = Ticks-1000
    Regards
    Nikos Geronikolos
    Attached Files Attached Files

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

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

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

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

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