Voting Circuit on a BS2 from photocell outputs
TheForsythe
Posts: 12
I'm pretty new to the basic stamp. I really need a hand with the creating a voting circuit on the basic stamp. There are 13 photocells that i will have hooked up with comparators on a separate bread board. The output (high or low) will be put into the basic stamp board. When any 10 or more of the 13 photocells are high, i need to get a high signal. When less than 10 of the photocells are high, i need to receive a low signal. If anyone can help me it would be greatly appreciated. Thank You!
Comments
Welcome to the forum!
The way I would go about this is to read all of the inputs at once using the INS operator, and assign it to a word variable. Then mask off the three unused bits. Next, isolate each 4-bit nybble and use that as an argument to a GOSUB routine which looks up the one-bit count from a table in EEPROM. Do that four times, adding the result to the total, and you'll have your count.
The slower (but simpler) way to do it would be to take the variable to which INS was assigned, and check each bit one-by-one by shifting right and using the .BIT0 attribute to add to your count.
-Phil
In lieu of building a comparator board, you could just use your photocells (phototransisitors are better) in a simple voltage divider arrangement. One series resistor (properly selected to yield working voltages) and one photocell/phototransistor per channel and you're finished. Leave the LM339s to fight another battle another day.
-Phil
-Phil
-Phil
+1.
The time you saved not building comparators is well invested into learning about the Stamp.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Elevator Capacity Check!", CR
LightCount VAR Byte
DO
'DEBUG CLS
LightCount = 0 ' Initialize counter to 0
IF IN13 = 0 THEN Hold 'Wait for elevator door to close
Counter:
PAUSE 2000 'Pause for 2 seconds while people get settled
IF IN0 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN1 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN2 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN3 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN4 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN5 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN6 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN7 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN8 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN9 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN10 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN11 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN12 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
DEBUG DEC LightCount, CR ' Output number of photocells that are not seeing light
IF LightCount > 9 THEN OUT15 = 1 ELSE OUT15 = 0 ' Turn on LED when 10 or more photocells see light
Hold:
IF OUT15 = 1 THEN hold UNTIL IN13 = 1
IF OUT15 = 0 THEN Hold
IF IN13 = 0 THEN Hold
LOOP
If anyone could help me it would be greatly appreciated!
This will wait for IN13 to go high, turn off OUT15, then wait for IN13 to go back low. That last part is important if your whole program is in a loop, in case the reset button is held down too long.
-Phil
-Phil