PDA

View Full Version : Program Loop Timing Jitter



Djim
09-18-2008, 11:41 AM
Hi, I was trying to make a repeating PWM loop on a BS2 through an output pin that is 50us ON and 9000us OFF.· Tried this using pulsout for the 50us and pause for the 9ms: these are put into a program loop.· I need the repetition rate to be very precise, i.e. I need something like 50us +-10us for on and the 9500us +-10us for off.·· Apparently pulsin is triggered by an interrupt and faces significant timing variation and the program loop execution cycles may also be adding to timing jitter.·

Any suggestions on how this might be accomplished?· I also looked at PWM, SEROUT; would those be better possibilities?

thanks

Phil Pilgrim (PhiPi)
09-18-2008, 11:54 AM
Show us your code.

-Phil

Djim
09-18-2008, 12:03 PM
Its basically this: (BS2)

Setup:
HIGH 0 ' make P0 low (LED off)
Main:
PULSOUT 0, 25 '50us pulse
PAUSE 9 ' Pause 9ms
GOTO main
END

Phil Pilgrim (PhiPi)
09-18-2008, 02:10 PM
I'm looking at the output from your program on a scope, and it's rock-steady — not a bit of jitter. But this is what I would expect from a BASIC Stamp, since it's completely deterministic, with no interrupts.

-Phil

BTW, which is it for "off"? 9000µsec or 9500µsec. Your first post gives both figures. Once I have that, I can give you a way to nail the timing a lot closer.

Post Edited (Phil Pilgrim (PhiPi)) : 9/18/2008 6:20:42 AM GMT

allanlane5
09-18-2008, 08:05 PM
+1 Phil. Once you "get it right" there's no jitter in the timing. Now, reading the tokens and executing them takes some time, so you'll probably have to adjust the PAUSE command to 8 mSec, then put in a PULSOUT to some un-used pin to get the exact part of a millisecond you need so that the whole loop meets your timing requirements.

Oh, and usually "jitter" means a back-and-forth inaccuracy in some timing signal. If the signal is rock-steady, just not quite correct, that's "inaccurate", not "jitter".

Djim
09-18-2008, 08:12 PM
Hi,

Thanks for the info.·· For the purposes of this discussion the off time can just be 9ms.· Buts thanks for the valuable suggestion on using pulsout on another pin if you need off time more or less than 1ms that will be valuable.

I am going back to the scope this am to make sure there is not a mistake.·· I was measuring the jitter with an NI card running 100mhz but maybe there is something funny going on there.··

How many command lines per sec can a BS2 run?

thanks

Phil Pilgrim (PhiPi)
09-19-2008, 12:09 AM
allanlane5 beat me to it with the second PULSOUT suggestion. Actually, you can get rid of the PAUSE altogether and use the second PULSOUT to take up all the slack.

-Phil

Djim
09-19-2008, 01:01 AM
Thats what I tried, good suggestion. In looking at this more closely on the scope, it appear to be the GOTO loop that is adding to the timing jitter. Still looking at this more closely. Note for clarity: I am looking for repeatability, not accuracy.
thanks

allanlane5
09-19-2008, 01:14 AM
I was going to say the BS2 does not use a timing interrupt -- but I believe the PAUSE statement DOES in fact use an internal timer interrupt to 'wake up' every so often, which will inject some 'jitter' into the process.

Phil Pilgrim (PhiPi)
09-19-2008, 01:17 AM
I don't know what kind of jitter your scope is seeing. Mine shows less than 2 µsec (0.02%), as the attached time-exposed trace reveals. It could be that your scope is not getting a clean trigger, which would cause it to display an apparent jitter. But I can assure you, it's not coming from the Stamp.

Here's the program I used for the scope trace:




' {$STAMP BS2}
' {$PBASIC 2.5}

HIGH 0
DO
PULSOUT 0, 25 '50us pulse
PULSOUT 1, 4364
LOOP




But your original program didn't jitter either.

-Phil

Post Edited (Phil Pilgrim (PhiPi)) : 9/18/2008 5:23:53 PM GMT

Phil Pilgrim (PhiPi)
09-19-2008, 01:20 AM
allanlane5,

PAUSE does not use a timing interrupt. You might be thinking of SLEEP and NAP.

-Phil