Performing a loop every 10ms


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 41
  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
    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...

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

  8. #8
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Thankyou

    Wow, thankyou for all of your replies.

    I forgot to mention that my crystal is 20MHz and both CCP1 and CCP2 are being used for HPWM.

    I found PicMultiCalc and it is saying that I can use the 8-bit timer (Timer0) for an error of 0.371%. It says that if I use the 16-bit timer I will get an error of 0%. Now I have decided that I will use the 16-bit timer only if it won't interupt my HPWM. The HPWM is driving two motors. I am not at all familure with these timers and I don't know how to set them up or know when to start my 10ms loop so that the gyro can be read at the start of every loop at 100Hz (10ms intervals). Integration calculations and other processes are carried out after the gyro has been read. If all calculations and procesess have been done before the next loop should start, the processor should wait until the timer flag or whatever signals the loop to start over.

    FYI I am making a balancing robot.

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wasssup1990 View Post
    Wow, thankyou for all of your replies.
    Said it before, I'll say it again...
    Start simple...
    Get the LED blinking at a known rate under an interrupt drive (or just get an LED blinking ), get the HPWM working on all channels in all situations, get the interfaces working, THEN tie them all together.
    Otherwise you'll be shooting yourself in the foot wondering why...no more...just wondering WHY!!!!

  10. #10
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Smile

    Well ok; so it's just a trial and error thing then? I'll just experiment with the PICMULTICALC values by plugging them into the right registers and i'll see how I go. BTW I have no idea of how to use an interupt. Anyhelp in using interupts in PBP relating to what I need will be very much appriciated.
    I was hoping someone here has done what I want done before. Or perhaps someone could link me somewhere, but thanks for all of your help.

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wasssup1990 View Post
    Well ok; so it's just a trial and error thing then? I'll just experiment with the PICMULTICALC values by plugging them into the right registers and i'll see how I go. BTW I have no idea of how to use an interupt. Anyhelp in using interupts in PBP relating to what I need will be very much appriciated.
    I was hoping someone here has done what I want done before. Or perhaps someone could link me somewhere, but thanks for all of your help.
    The old 'inverted pendulum' trick has been done a lot by various people using various processors...but in the end, it's all up to the guy behind the keyboard.
    Read the book, work your way up to it...otherwise, again, your foot will end up with holes in it...

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


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by wasssup1990 View Post
    FYI I am making a balancing robot.
    You should browse the parallax site ...

    They already did it ( and they share it !!! ) ... and moreover their basic is PbP compatible !!!

    ... at least TONS of understandable solutions to your headaches ...

    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 " !!!
    *****************************************

  13. #13
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    I saw that balancing robot on the paralax website. It doesn't use a gyro and an accelerometer. Useless on a sloped surface.

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wasssup1990 View Post
    I saw that balancing robot on the paralax website. It doesn't use a gyro and an accelerometer. Useless on a sloped surface.
    Differential GPS, one on each corner of a 4 cornered base... Solves everything!

  15. #15
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Ok I got the timer going, but brace yourself for a possible kalman filter question. I havn't found a single website that can explain kalman filters in laymens terms.

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


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by wasssup1990 View Post
    I saw that balancing robot on the paralax website. It doesn't use a gyro and an accelerometer. Useless on a sloped surface.

    ... ROFL !!

    THEY show you how to interface with the sensors, YOU write the program for your own requirements and dreams, with YOUR sensors.

    Not just a cut and paste party ...

    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 " !!!
    *****************************************

  17. #17
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wasssup1990 View Post
    Ok I got the timer going, but brace yourself for a possible kalman filter question. I havn't found a single website that can explain kalman filters in laymens terms.
    And you probably won't find one.
    Best explanation I can offer is that a Kalman filter makes a best 'future guess' based on the accuracy of it's past 'future guesses'.
    If the Kalman filter isn't sure of itself, it's 'future guess' goes out the window.
    I remember this from working the INU's on -130's. Ring Laser Gyro based INU's. The aircrews wouldn't believe the INU's position, so they'd update the things fairly often from TACAN or RADAR or whatever, even handheld GPS's. Then they'd whine when they got back because the INU would start drifting really badly inflight. The crews would come back and whine, we'd explain to them that they had ruined the INU's confidence by telling the INU it wasn't where it thought it was even though the difference between where the INU thought it was and where the crew told it that it was was very small. But of course, the aircrews knew better, because they're officers, and have degrees right?
    We'd have to go out and run a ground align on the INU about a half a dozen times and each time, just let the INU cook by itself for awhile to build up it's confidence. At first it would sit there and drift away from the spot the aircraft was on. After a couple of time, the drifting would get less and less and eventually, it wouldn't drift at all.
    But all that explanation doesn't help a person write any code now does it?

  18. #18
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    This post above and the post about the PicMultiCalc have been the most usefull to me in this thread. PicMultiCalc taught me a little bit of how timer0 works, and the post above taught me in laymens terms what the kalman filter does. The post two poitions up by Acetronics is not usefull and this person has probably no life. (:

  19. #19
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wasssup1990 View Post
    This post above and the post about the PicMultiCalc have been the most usefull to me in this thread. PicMultiCalc taught me a little bit of how timer0 works, and the post above taught me in laymens terms what the kalman filter does. The post two poitions up by Acetronics is not usefull and this person has probably no life. (:
    Well, then let me not help you out a bit more...
    If I could edit my Kalman filter post down to nothing but agreement with post #16, I would, but I can't.
    And a Kalman filter is a helluva lot more complicated than the 'layman's terms' I laid out...and probably beyond your level of comprehension by a few orders of magnitude...
    So, when you get a chance, here's what you do....
    Step outside and go play a one handed game of hide and go #@$^&^@ yourself...
    Last edited by skimask; - 13th February 2008 at 05:14.

  20. #20
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    East Tonto, You got leftover DoNuts older than this Kid . . .But ... LMAO
    Last edited by Archangel; - 13th February 2008 at 20:42.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  21. #21
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    East Tonto, You got leftover DoNuts older than this Kid . . .
    East Tonto? Huh? Where am I? Too rough?

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


    Did you find this post helpful? Yes | No

    Talking The Caïman Filter,the one that bites ...

    If that page doesn't give you enough to understand those filters ...

    http://www.cs.unc.edu/~welch/kalman/

    There's no more to do for you than sell hotdogs, bretzels or pizzas ( even donuts ) in the street ...

    I also remember having seen some of these filters used in UAV's ...

    So, I suspect more a SEARCHing problem than an Understanding problem ...

    But it's me ...

    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 " !!!
    *****************************************

  23. #23
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    If that page doesn't give you enough to understand those filters ...

    http://www.cs.unc.edu/~welch/kalman/

    There's no more to do for you than <font color=red>sell hotdogs, pretzels or pizzas ( even donuts ) in the street ...</font color>

    I also remember having seen some of these filters used in UAV's ...

    So, I suspect more a SEARCHing problem than an Understanding problem ...

    But it's me ...

    Alain
    Hi Alain,
    I looked at the whitepaper on that website . . . is that really math or pop art?
    You wanna buy a hot dog?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Talking

    Hi, Joe

    Was somewhat like that when I first discovered Fuzzy Logic ...

    You know what ???

    I DO HATE Maths ... But will surely enjoy a good Hotdog !!! _ Making Hoddogs is a full job. Programming Pic too.

    LOL !!!

    Alain
    Last edited by Acetronics2; - 14th February 2008 at 10:30.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  25. #25
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Thumbs down

    What a group of people. This forum is sad. It seems like we have a serious case of arrogant and negatively biased people. It's sad that such a potentially useful topic had to end like this. I only wanted some simple help and it seems some people have different reasons for being here. Whether it be belittleing people or actually giving them a hand in solving a problem. I certainly won't be recommending people come here. I certainly hope you idiots stick to this corner of the website and don't infect anywhere else. I've never encountered such a negative group of people like this on any other forum. Well done. ):
    For those people who know they did no wrong, are not responsible.
    I hope the site admin read this.
    Last edited by wasssup1990; - 14th February 2008 at 09:40. Reason: grammer

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


    Did you find this post helpful? Yes | No

    Default

    Whatever happened to people that want to learn.. Seems like all anyone wants these days is their problems solved for them with as little effort as possible on their part.

    That is what is really sad.

    Here we have a group of people willing to help others in a fairly complicated field, for no compensation whatsoever. From all walks of life and technical backgrounds, willing to share their knowledge.

    I do hope that people like wasssup will wise up. If they do not, and more of the world is filled with people like that... I fear for the future.
    Dave
    Always wear safety glasses while programming.

  27. #27
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wasssup1990 View Post
    What a group of people. This forum is sad. It seems like we have a serious case of arrogant and negatively biased people.
    You're in the minority that thinks this way.

    It's sad that such a potentially useful topic had to end like this.
    Useful to...YOU. If it wasn't useful to...YOU...then you wouldn't be whining.

    I only wanted some simple help and it seems some people have different reasons for being here.
    You wanted it handed to you on a platter so you could modify it and call it your own and impress your teachers or your buddies...whatever...

    Whether it be belittleing people or actually giving them a hand in solving a problem. I certainly won't be recommending people come here.
    If you couldn't figure this out, what makes you think your recommendations will hold any water in the first place?

    I certainly hope you idiots stick to this corner of the website and don't infect anywhere else. I've never encountered such a negative group of people like this on any other forum. Well done. ):
    Negative, maybe...but if it'll trip you off into trying to make your own solutions work rather than getting somebody else to do it, then you're probably better off in the long run...ya think?

    I hope the site admin read this.
    Probably will, might laugh, might cry...you think they read everything? Probably do...not a LOT of traffic here to filter thru.

  28. #28
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I do hope that people like wasssup will wise up. If they do not, and more of the world is filled with people like that... I fear for the future.
    I had a guy in my shop this morning, 32 years old, and I thought he was a smart guy, messes with electronics, etc.etc. Had a flat tire and didn't know how to change it so he called a tow truck. $200USD for the call!!! And he was here at the shop. He could've walked 15 feet and asked me to help him out...
    That's the kind of crap the world is facing sooner more than later...

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I had a guy in my shop this morning, 32 years old, and I thought he was a smart guy, messes with electronics, etc.etc. Had a flat tire and didn't know how to change it so he called a tow truck. $200USD for the call!!! And he was here at the shop. He could've walked 15 feet and asked me to help him out...
    That's the kind of crap the world is facing sooner more than later...
    That fellow could have been just plain LAZY. Either way, he has a problem.

    Does this all boil down to the way kids are raised now days?
    Dave
    Always wear safety glasses while programming.

  30. #30
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    That fellow could have been just plain LAZY. Either way, he has a problem.
    Does this all boil down to the way kids are raised now days?
    I don't think so... I acted up, my parents/relatives/adult around the block/etc, they all let me know it up-side the head.
    Might be the way those morons in 'high places' on their high-horses are telling us we have to raise kids nowadays...
    Remember getting slapped up-side the head in the grocery store by Mom 'cause you were messing around? Try and do that these days... Amazing how much a guy CAN'T get away with these days...

    Oh....you're talking about the guy in my shop!!!
    Ya, I've just figured out he's an idiot and/or Lazy...
    So we're all rubbing it in that the guy can't change a flat tire...and we'll probably continue to do so for another few weeks/months. (BTW - I took a look at his vehicle, the instructions, with pictures, are right there in his owner's manual in the glove box and a picture diagram in plain view on the trunk lid (boot cover?)...this guy is now in my book as useless...)

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


    Did you find this post helpful? Yes | No

    Default

    When I was growing up and Mom said that she was getting a SWITCH...She was not referring to an electrical component
    Dave
    Always wear safety glasses while programming.

  32. #32
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    When I was growing up and Mom said that she was getting a SWITCH...She was not referring to an electrical component
    Ya, mine too...it think it was an OKMU switch...One kid, multiple uses...for some reason, I begin to think that I was always the one that turned that switch on........and it seems like it never turned off!

  33. #33
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Thumbs down

    There you go people, my point has been backed up by these last few replies. I notice there are alot of assumptions being made.
    E.g. 1 From skimask: "You wanted it handed to you on a platter so you could modify it and call it your own and impress your teachers or your buddies...whatever..."

    Now that is some assumption. You jumped to that conclusion skimask, I know some other people on this form may do that, but all I needed was a somewhere to start. Go and look at my first post. See how innocent that looks? I guess the assumptions started right there. (:

    E.g. 2 From mackrackit: "Whatever happened to people that want to learn.. Seems like all anyone wants these days is their problems solved for them with as little effort as possible on their part."
    This person made the same assumption. What made you think I just wanted the answer straight up? It would have helped if someone could step me through how to set up Timer0.

    Acetronics thought this was a cut and paste party. All I needed was some guidance.

    Hmm I wonder what's going to be said next?
    Last edited by wasssup1990; - 15th February 2008 at 03:20.

  34. #34
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wasssup1990 View Post
    Hmm I wonder what's going to be said next?
    Allow me.... ('cause most will )
    Post #1 = +
    Post #2 = +
    and so on...
    Post #15 = +
    Post #16 = +
    Post #17 = NEGATIVE - and it'll all downhill from there...thanks to...anyone...anyone...yep, you guessed it...

  35. #35
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It's suppoased to be a loop every 10ms.
    Not an insult every 10 ms.

    It's like a "Pack of Wolves".
    And wasssup didn't start anything.

    Y'all need to mellow out, and write some code.

    Here's mine...

    Code:
    ReadingTaken VAR BIT
    TRM0IF       VAR INTCON.2
    TMR0IE       VAR INTCON.5
    TimerReload  CON 60
    
    OPTION_REG = %11010111   ; Assign Prescaler to TMR0, 1:256, internal clock
    TMR0 = TimerReload       ; Load timer for first delay
    TMR0IF = 0               ; Clear the interrupt flag
    ReadingTaken = 0         ; indicate reading hasn't been taken yet
    
    TMR0IE = 1               ; Enable TMR0 interrupt
    ON INTERRUPT GOTO TakeReading
    
    Main:
        If ReadingTaken then ; Wait for reading to be taken
            ReadingTaken = 0 ; Indicate the reading has been handled
    
            ; -- Reading has been taken, do something with it here --
        endif
    
    GOTO Main
    
    DISABLE
    TakeReading:
        TMR0 = TimerReload   ; reload timer for next period
        TMR0IF = 0           ; Clear the interrupt flag
    
       ; -- this is called every ~10.036ms -- (with 20mhz OSC)
       ;    Take your reading
    
       ReadingTaken = 1      ; Tell main loop that a reading has been taken
    RESUME
    ENABLE
    HTH,
    DT

  36. #36
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Thumbs up

    Thankyou Darrel
    Admin has come to the rescue.

    Thankyou for that usefull code. If I ever use any of it I will put credit to you in my source code and whoever else you think deserves credit for it.

    I hope I never run into trouble like this again on this forum. I'm just a electronics and programming hobbiest needing a little programming help. I didn't need any of that rubbish above.

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


    Did you find this post helpful? Yes | No

    Wink

    MHhhhhh,

    Thinking to it, Darrel is perfectly right ... ( as most of time ! )

    We are here for programming pics tricks ... and Everything else is just "optionnal". May be this thought could avoid further fighting parties ...

    Here are My two cents !

    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    It's suppoased to be a loop every 10ms.
    Not an insult every 10 ms.

    It's like a "Pack of Wolves".
    And wasssup didn't start anything.

    Y'all need to mellow out, and write some code.

    Here's mine...

    [code]ReadingTaken VAR BIT
    TRM0IF VAR INTCON.2
    TMR0IE VAR INTCON.5
    TimerReload CON 60

    ....


    Minor correction to DT's code above:
    TRM0IF VAR INTCON.2 should be TMR0IF VAR INTCON.2

    Also, I agree with DT. Here is my code thingie with my approach:

    1.03mS interrupt at 4 MHz, 1:4 Prescaler Assigned to TMR0.
    This works the opposite way of what DT does.
    DT's code interrupts every 10mS, my code interrupts every 1mS.
    Work on either one.


    Code:
    <font color="#008000">@ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF
    
    </font>SetAll:
      <font color="#000080"><b>CLEAR
    </b></font>TRISA = <font color="#FF0000"><b>%00000000       
    </b></font>TRISB = <font color="#FF0000"><b>%00000000       
    </b></font>CMCON = <font color="#FF0000"><b>7               
    </b></font>VRCON.<font color="#FF0000"><b>7 </b></font>= <font color="#FF0000"><b>0
    </b></font>VRCON.<font color="#FF0000"><b>6 </b></font>= <font color="#FF0000"><b>0
    
    </b></font>PORTA = <font color="#FF0000"><b>0
    </b></font>PORTB = <font color="#FF0000"><b>0
    
    </b></font>TimeAdder <font color="#000080"><b>VAR BYTE
    
    </b></font>OPTION_REG.<font color="#FF0000"><b>5 </b></font>= <font color="#FF0000"><b>0     </b></font><font color="#000080"><i>' TMR0 internal clk select bit.
    </i></font>OPTION_REG.<font color="#FF0000"><b>3 </b></font>= <font color="#FF0000"><b>0     </b></font><font color="#000080"><i>' Prescaler Assigned to TMR0.
    </i></font>OPTION_REG.<font color="#FF0000"><b>2 </b></font>= <font color="#FF0000"><b>0     </b></font><font color="#000080"><i>' Bit 2,1,0 : 1:4 prescaler.
    </i></font>OPTION_REG.<font color="#FF0000"><b>1 </b></font>= <font color="#FF0000"><b>0 
    </b></font>OPTION_REG.<font color="#FF0000"><b>0 </b></font>= <font color="#FF0000"><b>1
    
    </b></font>T0IE <font color="#000080"><b>VAR </b></font>INTCON.<font color="#FF0000"><b>5  </b></font><font color="#000080"><i>'INTCON.5 = 1 ' Enable TMR0 interrupt.
    </i></font>T0IF <font color="#000080"><b>VAR </b></font>INTCON.<font color="#FF0000"><b>2  </b></font><font color="#000080"><i>'INTCON.2 = 0 ' TMR0 interrupt overflow bit. Must be cleared in software.
    
    </i></font>T0IF = <font color="#FF0000"><b>0           </b></font><font color="#000080"><i>' Cleared.
    </i></font>T0IE = <font color="#FF0000"><b>1           </b></font><font color="#000080"><i>' Enable TMR0 interrupt.
    </i><b>ON INTERRUPT GOTO </b></font>TMR0_Int
    
    Begin: 
        <font color="#000080"><b>IF </b></font>TimeAdder = <font color="#FF0000"><b>10 </b></font><font color="#000080"><b>THEN </b><i>' We have 10mS cycle.
           </i></font>TimeAdder = <font color="#FF0000"><b>0       </b></font><font color="#000080"><i>' Clear time adder.
           'Do something here.
           '. 
           '..
           '...
        </i><b>ENDIF
        
        
        GOTO </b></font>Begin
    
    
    
    <font color="#000080"><b>DISABLE
    </b></font>TMR0_Int:       <font color="#000080"><i>'This routine is called every 1.03mS. Act Fast here.
        </i></font>TimeAdder = TimeAdder + <font color="#FF0000"><b>1
        </b></font>T0IF = <font color="#FF0000"><b>0  </b></font><font color="#000080"><i>' Clear interrupt flag bit.
        </i><b>RESUME                   
    ENABLE     
        
        
    </b></font>
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  39. #39
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer
    Minor correction to DT's code above:
    TRM0IF VAR INTCON.2 should be TMR0IF VAR INTCON.2
    WooHoo!, Somebody's paying attention. I love it!
    Dang dyslexia.

    Thanks Sayzer!
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    WooHoo!, Somebody's paying attention. I love it!
    Dang dyslexia.

    Thanks Sayzer!
    <br>
    Attention is in my heart,
    Reading and posting is never hard,
    Let be friends, don't post assault,
    Share the knowledge, you won't lose a byte.


    P.S. - I am in finals going toward award.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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