PDA

View Full Version : Pic not timing correctly



atwoz
- 5th December 2007, 18:18
First of all, I want to say hello to everybody in these forums. Thanks for giving some of your time to helping out people.

I have an Issue with all the pics I program. I've read that when you work with interrupts in PBP, when they are activated, they wait for the last command to finish before they begin.
That is, if you are in a 50 second pause when it happens, you'll have to wait for the pause to end before the interrupt becomes active.

To avoid this all you have to do is to use the For..next command. Here is where I have trouble.

When I do:
----
pause 1000
----
It pauses exactly for 1 second, but when I try to do the same using for...next:
----
for b0 = 0 to 1000
pause 1
next b0
----
It doesn't pause for 1 second, it speed up and pauses for like 0.3 seconds. I've tried everything but nothing fixes this, I've tried with several pics and they all have the same problem.

By the way, I use them in Internal oscillator mode but I also tried using a 4 mhz crystal and it happened again.

thanks again!

mister_e
- 5th December 2007, 18:52
B0 have to be a WORD sized variable unless it will only consider the 8 less significant bits. In this case 1000 will be considered as 232... hence why your timing is off. (232/1000=0.232 of expected value)

You can override most problem using ASM interrupt or Brilliants Darrel's Instant interrupts.

Dave
- 5th December 2007, 18:52
atwoz , What type of variable is "b0" defined as? If it is declared as a byte it is only counting to 255..... Declare it as a word..

Dave Purola,
N8NTA

mister_e
- 5th December 2007, 18:59
euh yeah... 255 if in a loop... OOPS! :o http://www.mister-e.org/Pics/pan

atwoz
- 5th December 2007, 21:25
Yeah, that was the problem, thanks a lot for your time!