Basic Stamp timer command question
CSCNET
Posts: 3
Hello everyone.· I am a new member trying to write a Program for my Basic Stamp to run a timer at 1/125 HZ @ 70%.· I have tried the PWM command with no success and am now working with the Pulsout command.· I am able to program the 70 duty cycle with the Pulsout but how do I get the 1/125 Hertz?· Can anyone lead me in the right direction?
Thanks
Thanks
Comments
As you've figured out, the PULSOUT statement is better for what you want to do. The problem is controlling the "off" time. The best way to do this is to use an unused I/O pin if you have that and alternate PULSOUTs on the pin you want and the unconnected I/O pin. The PULSOUT for the unconnected I/O pin will cause an accurately determined short delay for the "off" time and the PULSOUT on the desired I/O pin will cause an accurately determined "on" pulse. This will be in a loop and the GOTO or DO / LOOP will cause a short delay, so you'll have to adjust the "off" time PULSOUT accordingly.
So if I use pin 9 as my high and pin 10 as my low I believe each of these uses 140 microseconds.· I am going to need to do some math to figure out the DO LOOP or·GOTO on this one.
Do I use the·"Pulsout·PIN 9, 700" command first and then the GOTO?· Will the GOTO command then give me my 1/125 Hertz·if I use the right number of Highs and Lows (8000 microseconds)?
Thanks again
myloop:
pulsout 9,700 ' On a BS2, this causes pin 9 to be toggled for 1400us
pulsout 10,3300 ' On a BS2, this causes pin 10 to be toggled for 6600us
goto myloop ' This starts the pulse sequence over again
There's a little overhead associated with each of these statements. Tracy Allen has a good analysis of the execution time of various statements. Go to www.emesystems.com and select the "app-notes" link at the bottom of the page.
I also need to run a timer at 1/1000HZ @ 70%.· Would the same program work for it?
(First) 125HZ = T = 1/125 = .008 msec/.000001 = 8000 microseconds @ 70% duty cycle
(Second) 1000HZ = T = 1/1000 = .001 msec/.000001 = 1000 microseconds @ 70% duty cycle
Pulsout 9,86····· Based on your last email this should toggle for 172us.
Pulsout 10,413····· Based on your last email this should toggle for 826us
Does this make sense?
Thanks for your help