Timer1 usage in PIC18F252


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Generally no. If you are interrupt driven, and you need an interrupt every 'x' seconds then your ISR would reload the registers with the appropriate values as soon as possible (to insure correct timing). There is no need to reload them upon exit.

    In PBP, I normally run in "pseudo-interrupt" mode. I sit in a tight loop polling PIR1.0 until it goes true, clear that bit, reload TMR1H and TMR1L then enter my main routine. After the routine, I go back to the polling mode.

    I put all my high-priority items (such as checking the serial port interrupt bit) in the tight loop, and all the normal stuff in the main program. I avoid pauses whenever possible and instead rely on the timer to provide timing information.
    Charles Linquist

  2. #2
    EShatara's Avatar
    EShatara Guest


    Did you find this post helpful? Yes | No

    Default Thanks

    >Generally no. If you are interrupt driven, and you need an interrupt every 'x' >seconds then your ISR would reload the registers with the appropriate >values as soon as possible (to insure correct timing). There is no need to >reload them upon exit.

    That's what I meant...thank you

    >In PBP, I normally run in "pseudo-interrupt" mode. I sit in a tight loop >polling PIR1.0 until it goes true, clear that bit, reload TMR1H and TMR1L >then enter my main routine. After the routine, I go back to the polling >mode.

    I already have a tight loop polling my serial port looking for a charaacter. Are you saying I can use the timer without having it generate an interrupt?

    Hadn't thought about that....That could be quite easy to implement in my code.

    Thanks .... chris

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Yes, here is a quick code example:


    FastLoop:
    IF PIR1.0 = 1 THEN
    PIR1.0 = 0
    TMR1H = TimerPreloadValue.Highbyte
    TMR1L = TimerPreloadValue.Lowbyte
    GOSUB MainProgram
    ENDIF
    IF PIR1.5 = 1 THEN
    Gosub KeyboardInputRoutine ' HSERIN clears PIR1.5
    ENDIF

    GOTO FastLoop

    MainProgram:

    'Do something here every time the timer rolls over

    RETURN




    ' This works perfectly as long as your 'Main Program' never takes as long as the timer period. The code sits in the FastLoop waiting for either a keyboard input or a timer timeout. When the timer timeout occurs, then the MainProgram is executed. If you output data in your MainProgram, that data will be output at a regular interval regarless of the length of your program.
    Just remember - stay away from PAUSEs in your main program whenever possible!
    Charles Linquist

  4. #4
    EShatara's Avatar
    EShatara Guest


    Did you find this post helpful? Yes | No

    Default Thanks again

    Thanks Charles...you've been most helpful....Chris

Similar Threads

  1. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 11:49
  2. Help with TIMER1 + SLEEP
    By Yodoad in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd May 2009, 15:07
  3. Time Period of Timer1
    By arnol34 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th May 2007, 00:31
  4. Timer1 and Interupt wierdness
    By mind in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd August 2005, 01:24
  5. Use of Timer1 with 16F819
    By Barry Johnson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th January 2005, 16:25

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