pic18f887 event timer


Closed Thread
Results 1 to 19 of 19

Hybrid View

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

    Default pic18f887 event timer

    I am using a PIC18F887 with the internal oscilator set @ 8MHz. I have a subroutine I need to fire off at a routine basis (nominally every 22ms although I want it a constant that I can tune). Can someone give me a crash course (with as much details so I don't have to ask a bunch of follow on dummy questions) on how I set this up as some sort of timer on an interupt, preferably without using assembly, but if that is the only way, I am willing to try. I have no available IO pins remaining if that matters. I am using no other interupts, but future versions may entail a serial interupt. I only want it to fire after a complete line is executed, which I think is by default, then return to the next line after it runs the routine. I suspect its fairly easy, but I am not sure where to start.

    Thanks,
    Charlie

  2. #2
    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/showthread.php?t=3251
    Be sure to read the first eight post.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    OK. This looks good. Thanks.

    I think the overkill blinking light is the right for me to use. I am unlear what to change to get timer 1 to fire off every 22ms.

    I assume it starts with this seting
    T1CON = $31 ; Prescaler = 8, TMR1ON

    I have two different harware setups I am trying to put it in. Both use the PIC16F887, one with an external 20MHz Osc, the other with an internal 8MHz. It looks like a prescaler of 1:8 is the max, so I suspect I need to do a counter in the interupt routine that only fires my event every nth time to acheive the 22ms event? Is this a big burden or is there a simpler way? Can someone show me some examples of how to do the math to get the event to fire off properly with the two oscillator speeds?


    Thanks,
    Charlie

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Can someone show me some examples of how to do the math to get the event to fire off properly with the two oscillator speeds?
    Charlie, play with the attached little tool to find out.

    How to use it: click on the box enter the new value and press enter.

    Cheers

    Al.
    Attached Files Attached Files
    Last edited by aratti; - 26th October 2010 at 09:54.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default

    Timer 1 is 16 bit.
    At 8 Mhz with a prescale of 1 and a peload of 21537 will give 22.0 mSec
    At 20 Mhz with a prescale of 2 and a peload of 10536 will give 22.0 mSec

    http://www.picbasic.co.uk/forum/cont....-PICMultiCalc
    http://www.picbasic.co.uk/forum/show...3259#post23259
    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 compile errors

    I am not sure if I shoudl reply to this thread or the main interupt thread.

    Anyways, I am getting errors when compiling. It looks like its all with the includes files.

    I have attached a screenshot showing the errors and my code

    Can anyone let me know what I am doing wrong?

    Thanks,
    Charlie
    Attached Files Attached Files

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