POT example with BS2
carguy
Posts: 3
I am looking for an example on how to read the value of a pot with BS2. The POT function only exists under BS1 according to the Help.·I tried to run the POT.bas example under the BS1 folder, but I could not make that work. I got a message stating no BS1 module connected to my computer. I have the BASIC Stamp Homework board.
My goal is to use one (or multiple) pots to affect the output of a square wave. If the pot had a scale of 0 to 100, then I was hoping to do something like:
POT 0, 100, level
time = 100 - level
HIGH 14
PAUSE time
LOW 14
Just looking for some examples or input. Thanks.
My goal is to use one (or multiple) pots to affect the output of a square wave. If the pot had a scale of 0 to 100, then I was hoping to do something like:
POT 0, 100, level
time = 100 - level
HIGH 14
PAUSE time
LOW 14
Just looking for some examples or input. Thanks.
Comments
You can size the capacitor to get the range of values you prefer.
value var word
DO
HIGH 2
Pause 10
RCTime 2,1,Value
debug ? value
Loop
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Personal Links with plenty of BASIC Stamp info
StampPlot - Graphical Data Acquisition and Control
AppBee - XBee ZigBee / IEEE 802.15.4 Adapters & Devices
I want to build a circuit in which I can turn a knob/dial to increase/decrease the rate at which a square wave is generated somewhere else in the circuit. For example, assume the knob/dial has a scale of 1,000 to 10,000. I was hoping to do something like
IF Scale < 5,000
· Square_Wave =· 50% Duty Cycle
ELSE
· Square_Wave =·80% Duty·Cycle
ENDIF
In this example, I want Scale to represent RPM. So,
Convert RPM to Cycles Per Minute (need two revolutions for 1 cycle in a four stroke engine)
CPM = RPM / 2
Calculate Cycles per Second
CPS = CPM / 60
Calculate time for one cycle in mS
Cycle = 1000 / CPS······· '·1 second·/ CPS * 1000
What kind of input device can I use to allow changing the Scale; thus, altering the square wave output. I am also a little confused on how to make the code work, but that maybe related to figuring out what hardware to incorporate and interrupt its value.
Thanks.
Step 1 is to become comfortable with reading the value of a variable resistor using the RCTIME statement. Read the section in the PBasic Manual on the RCTIME statement and try the examples to see how it behaves. Plot out the values you get from the RCTIME compared to the rotation of the variable resistor and decide how you want to assign cycle time or frequency values to the RCTIME values (best to create an equation that fits the relationship).
Step 2 is to generate pulse trains using the PULSOUT or HIGH/LOW and PAUSE statements. The PAUSE statement has a resolution of only 1ms, so sometimes you can use two PULSOUT statements, one to the pin you want to use, the other to an unused pin (just to provide a time delay) for the "off time".
Step 3 is to combine these so the position of the resistor gets read from time to time (maybe once a second or so) and used to set the time delays for the pulse train. This would cause an interruption in the pulse train which may or may not be acceptable. If this interruption is not acceptable, you would need to use some kind of external circuitry to generate this with the Stamp controlling the external generator.
I tried different capacitors and different lengths of PAUSE. Perhaps I just never got the right combination. I would have thought with the code above, the waves however long would have been relatively compressed together (close together), but that did not seem to be the case. I could have done something wrong though. Any advice?
My ultimate goal is to build a little black box with multiple variables that a user can change which alter a square wave output. The box would have an easy place to connect a scope to view the affects on the square wave. The wave represents injector pulse width. The variable inputs would be:
RPM 1,000 - 10,000
Intake Air Temperatue 0 - 50* C
Manifold Pressure 20 - 300 kPa
It would be nice to be able to display the values of each variable as well as provide smooth transition/resolution throughout the given scale. Any thoughts on getting to this ultimate goal or how much something like this would cost to build. It doesn't sound like the BS2 will do this.
Thanks.