View Full Version : Tying in more speeds

11-17-2009, 10:34 AM
Hi, I may not explain this right, but I am trying to finish up my final of making a fan run at say· ontime 8000ms high pause· offtime8000 ms low then pause then loop.·However I cant seem to add on· 2 more different speeds· 10000 ms and 500 ms·to· show changing of speeds. I start with do and end with loop. But every time I type in command I cant make it work.Where could I look to or what can I type in for my program to work. Ideas are welcome. My actual program is similar to p138 in process control guide. I am a real novice on this. Thanks.

11-17-2009, 11:13 AM
Attach your actual program to your next post so we can look at it. Also draw a sketch of how you have things connected.

- Stephen

11-17-2009, 11:51 AM
Thanks I will have these items Tuesday.

11-17-2009, 07:10 PM
········ Here is program that does work with our fan. Due to amperage of fan we had to upgrade our resistors and use a·TIP31. and reconfigure·original schematic, for safety reasons.·Our instructor okd this part but left us to figure out command part. I have typed in several things and just cant seem to get correct combo.. I will try to send a schematic soon.·· However·Port/pin··2· tied in with fan is being used in this program and works on the following command:
·'···· ·····[ declarations ]

·fan····· · pin···· 2········· ' fan driver· I/O
·ontime···con····8000····· ' time to leave fan on
·offtime·· con··· 8000····· ' time to leave fan off

·'·········[ main routine]

···· high fan·················· ' energize fan
···· pause ontime··········· ' pause while running
···· low fan··················· ' de-energize fan
···· pause offtime··········· ' pause while off
·· just need to know how to write/incorporate 2 or more speeds in this program to show class of changes in speeds...thanks Russ (novice!!!)

PJ Allen
11-17-2009, 08:05 PM
So, you have an "infinite"·DO...LOOP --·you're trapped.· You need to break out of it.· With a button push?· After·some number of iterations?· How?

It's an assignment, hope I've started you thinking.

11-17-2009, 10:21 PM
Yep! If i could get correct info for Fri show and tell at college., it would be great. I will keep plugging away, but any help it would be appreciated. Our class doesnt care how we got info, as teacher directed me to this forum, but he wants us to understand how basic works. So if someone could help breakingout of this loop??? I could explain it to the class in my presentation with a program that has 2 or 3 different speeds in a same loop.. Thanks Russ

11-17-2009, 10:57 PM
First, make sure your program is set to use the editor software ver 2.5 (click the "Directive" button at the top of the editor page.)

Then look at the editor Help file under "DO". There is a modified version where you can LOOP UNTIL (something occurs). That event can be a switch closure, a counter value, etc. That will let you get out of the loop and go to the second speed loop or readjust the on/off times or whatever you want to do.

It goes without saying that physically drawing a flow chart on paper is the fastest way to understand what your program has to do.


Tom Sisk


11-17-2009, 11:34 PM
Thanks! I do have 2.5 ver and will try WED when next class/lab. I appreciate any more info if needed as I learn more about Basic Stamp and its uses. It seems to be awesome, even for a rookie! Again Thanks and keep info coming. Russ

11-19-2009, 04:45 AM
· Here are my 3 programs and still dont understand how to incorporate all3 together. I have tried ,next ,goto if then, end, loop etc·and several dozens of remedies. No go. My 3 speeds work great by itself, but someone show me what to edit in my program to make all 3 speeds work in one program?· All 3 are 2.5 versions.

···· [declarations]
·fan pin 2 ' fan driver I/O
·on time Con·50 ' time to leave fan on····· (program 1)
·offtime· Con 50 ' time to leave fan off····
·ontime Con 400 ' time to leave fan on····· (program 2)······ (these 3 programs are in actual seperate form
·offtime Con 400 ' time to leave fan off··························· (from each other but still Iam lost)
·ontime Con 10000 'time to leave fan on··· (program 3)
·offtime Con 10000 ' time to leave fan off
·[ main routine]
·high fan ' energize fan
·pause ontime 'pause while running
·low fan 'de-energize fan
·pause offtime 'pause while off
· how should this program read?·· I am correct oneverything hardware wise. Russ


11-19-2009, 07:25 AM
As a prof of mine used to say "...you've got a conceptual hangup here!"

Basically, you have three sets of 50% duty cycle which means the motor theoretically is going to run at approximately the same speed. As an exercise, start out by letting the total of ontime + offtime be a constant, say 300. To go slow ontime = 50, offtime = 250, medium speed might be ontime = 150, offtime = 150 and high speed might be ontime=250 and offtime = 50. Note that in your program you have the motor on for 50 mS, off for 50 mS; then on for 400 mS then off for 400 mS; then on for 10 Sec and off for 10 Sec. Not a very smooth running fan!

As mentioned earlier you might use the LOOP UNTIL construct rather than the same do - loop you had way back in the beginning.

For instance, suppose you connected a switches to pin 3 and pin 4. ( I don't know if this is available in your case).


fan pin 2 ' fan driver I/O
switch pin 3
switch2 pin 4
ontime Con 50 ' time to leave fan on (program 1)
offtime Con 250 ' time to leave fan off
ontime2 Con 150 ' time to leave fan on (program 2) (these 3 programs are in actual seperate form
offtime2 Con 150 ' time to leave fan off (from each other but still Iam lost)
ontime3 Con 250 'time to leave fan on (program 3)
offtime3 Con 50' time to leave fan off
[ main routine]
high fan ' energize fan
pause ontime 'pause while running
low fan 'de-energize fan
pause offtime 'pause while off
loop until switch = 1
high fan ' energize fan
pause ontime2 'pause while running
low fan 'de-energize fan
pause offtime2 'pause while off
loop until switch2 = 1
goto main

Tom Sisk


PJ Allen
11-19-2009, 07:52 AM
"Free your mind and your *** will surely follow."· --Anon--

Hit PBASIC Help, look·up FOR...NEXT, change up your on and off values.

11-19-2009, 08:12 AM
·I get the· grasp of changeup of variables and can see where 50% duty cycle is wrong when you showed me!!! Example 300ms total. I guess when we was doing play for a purpose we lost that in translation on my teams part. I can do that very easy however as for multiple pinouts or ports we are not that advanced yet to do this, so I just have 1 port, ·port 2, is this still possible to run?. So I·my next question at the end of program is what do I type loop, next etc.to incorporate this or is it there in black and white and not comprehending what has been giving to me?·I have looked at basic commands and being a rookie it is still foreign to me. That is I can say.·Again I really appreciate your valuable help. We have put my project on hold until I can communicate to my team correct thoughts. Again thanks to all!! Russ

11-19-2009, 08:22 AM
If 1 port only port 2 is used, can I put loop until in each offtime and do I put a pause also in between cycle times? I am looking at book and pbasic as of now Tom and PJ. Thanks again russ

11-19-2009, 08:25 AM
Never mind about pause command I see it now. I will keep on trying!!!!!!

11-19-2009, 08:31 AM
Never mind on loop either/ go to main is command I see now also! I will be in class Friday to tweak and learn and do the best I can on this. The only thing I am unsure is using only 1 port part if this can go on my part. It works seperately on each program as I said before.. Thanks again! Russ.

PJ Allen
11-19-2009, 09:42 AM
Well, that was a bust.

' {$STAMP BS2}
' {$PBASIC 2.5}
a VAR Word
FOR a = 0 TO 500 ' hi
FOR a = 0 TO 500 'med
FOR a = 0 TO 500 ' lo
PAUSE 5000 ' nothing

PWM 0, 255, 5000 ' hi
PWM 0, 128, 5000 ' med
PWM 0, 64, 5000 ' lo
PAUSE 5000

GOTO speeds

11-19-2009, 09:53 AM
No it wasnt /isnt a bust> I will try all including this one. Thanks PJ counsel of despair. Appreciate it! Russ