pic18f887 event timer


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    http://www.picbasic.co.uk/forum/show...7472#post17472
    Has the example to set the pre-scaler.
    Then in your code for the pre-load.
    Code:
    PreLoad     VAR WORD
    PreLoad =  21537 
    TMR1L = PreLoad.LowByte
    TMR1H = PreLoad.HighByte
    Then in the interrupt routine
    Code:
    TMR1L = PreLoad.LowByte   ' Load the timer with preload value.
    TMR1H = PreLoad.HighByte
    Maybe....
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Aug 2005
    Location
    NC, USA
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    cool. I had it in the begining, did not have it in the interupt. Firing every 22ms on the scope.

    So, this will not mess up anything as far as I2C or serial? or is that dependent on what I do during the interupt? (The final interupt will take about 10-14ms and fire off every 22ms)

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    So, this will not mess up anything as far as I2C or serial? or is that dependent on what I do during the interupt? (The final interupt will take about 10-14ms and fire off every 22ms)
    You need to get in and out of an interrupt routine as quick as possible.
    So if the I2C and serial stuff is handled out side then you should be good.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Aug 2005
    Location
    NC, USA
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    In order to get in and out quick I will need to use another timer I guess. I need to fire off serries of 8 pulses every 22ms. The high pulses will range from 400us to 1800us with a 400uslow pulse/pause between each one. So I am looking for some advise as to the best approach. Would be the best approach it with a second timer or the same one? I guess if I use the same one I can add up all the small pulses and then wait the difference of 22ms and repeat, but I am not sure if that is as reliable as using two timers, perhaps simpler though. If two timers, should I use timer1 (the 16 bit one for the shorter pulses since their accuracty is more critical than the 22ms) and timer0 or timer2 for the 22ms event. Is there any big deal with changing the preload value for the shorter pulses each time?

    In either approach, can I use a case select inside the interupt routine to remember where I am in the interupt pulse train each time I return, or is there something I have to do to pass variables in and out of the interupt routine.

    Thanks,
    Charlie

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I probably worded that wrong. Just make sure you finish before the next period and/or leave enough time to do whatever else you need to do.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Aug 2005
    Location
    NC, USA
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    I have finished puting the original non interupt code into the new program. any reason why PORTB.2 is all of a sudden reading high all the time. I can ground it out with a switch and it will not change state. I when back to the old program and the pin funtions fine, so I assume its something to do with the new interupt, since that is all that has changed, but I can't figure out what. Any suggestions. Thanks

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Just for giggles can you post your current code? Preferably in code tags...
    Dave
    Always wear safety glasses while programming.

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