Performing a loop every 10ms


Closed Thread
Results 1 to 40 of 41

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Posts
    10

    Default Performing a loop every 10ms

    Hello. I am not sure how to setup my PIC16F877A to run a looping section of my code every 10ms. A rate gyro must be read every 10ms consistently so that my integeration calculations don't go crazy. I've read the Timer0 section of the datasheet but I just don't understand it well enough to achieve what I want. I am using PIC Basic PRO.
    If I have missed an important piece of information here please ask me for it.
    Thankyou.

  2. #2
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Post needed

    Can you display your code so that I will have an idea on what's going on.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi, Wassup

    As Timer 0 is a 8 bits timer ... and we suppose clock is 4Mhz ( ... )

    I will be necessary to have a counting loop in the interrupt stub , because interrupts will occur every 256 µs as a maximum

    The other solution is to use Timer 1 that has a 16 bits counting range ... and won't need any calculations.

    Have a SEARCH for "PicMultiCalc" from Mr E. it's a nice tool to help for Timer designs ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    ...256 µs as a maximum
    ??

    Minimum?

    Maximum?

    I must be on the other side of the mirror.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    ??

    Minimum?

    Maximum?

    I must be on the other side of the mirror.


    The other side of the Bosphor, certainly !!!

    1x 1µs = 1µs ... 256x 1µs = 256µs ...

    so, the maximum period is 256 µs ...

    what was requested for, is a period duration of 10 ms ... or a 10,000 timer count !

    Tell me if I'm wrong !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    The other side of the Bosphor, certainly !!!

    Alain
    Depends on what side you are standing at.


    Quote Originally Posted by Acetronics View Post
    1x 1µs = 1µs ... 256x 1µs = 256µs ...

    so, the maximum period is 256 µs ...

    what was requested for, is a period duration of 10 ms ... or a 10,000 timer count !

    Tell me if I'm wrong !!!

    Alain
    The "maximum" means fastest then.

    Also, what do we get from TMR0 at 4Mhz at 1:4 prescaler ?
    I get roughly 1.03ms.

    I may be doing a wrong math here.
    Last edited by sayzer; - 8th February 2008 at 19:11.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wasssup1990 View Post
    Hello. I am not sure how to setup my PIC16F877A to run a looping section of my code every 10ms. A rate gyro must be read every 10ms consistently so that my integeration calculations don't go crazy. I've read the Timer0 section of the datasheet but I just don't understand it well enough to achieve what I want. I am using PIC Basic PRO.
    If I have missed an important piece of information here please ask me for it.
    Thankyou.
    Use an LED for initial testing, make blinky first, otherwise, I'll bet you'll drive yourself crazy trying to get it to work right.
    One 'easy-ish' way to get it to work...
    Set up timer 0 to interrupt on overflow, get an 'On Interrupt' stub to work blinking an LED. Change the Tmr0 prescaler to 1:64. You'll get an interrupt every 16.384ms instead of 10ms. Yes, it's a bit longer than what you want, but you can easily scale the results from the 16.384ms interrupt to make them look like the results from a 10ms interrupt.
    16384/10000 = 1.6384.
    No, PBP can't divide by a fractional number...but, you multiply it up by a large number and divide it back down by a whole number, keeping the ratio the same to keep the numbers correct...i.e.
    16384/10000 = 1.6384 which is the same as
    32768/20000 = 1.6384 which is the same as...and so on and so on...
    Or, set up Tmr1 as a 16 bit timer that kicks off every 10ms...just like the other guys said...
    But $20 says you're biggest problem will be understanding how to get the interrupt to work in the first place...

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 16:48
  2. Serin to Serin2 ??
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 03:56
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. newbie Q - edge detection?
    By RMCRAVEN in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 9th October 2006, 08:20
  5. Newbie question:
    By Izone in forum mel PIC BASIC
    Replies: 2
    Last Post: - 26th February 2006, 16:24

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