Inverting binary with basic stamp and solid state relay
bigfresh
Posts: 16
I'm trying to program my basic stamp (board of education basic stamp 2) to control 5 record players, using binary, relayed by the COMFILE SSR8 cubloc.com/product/01_03ssr8.php. I dont have the code in front of me but i believe the lines to turn all the turntables on for 5 seconds and then off for 5 seconds is:
DIRH= %11111
OUTH = %00000 <--on
PAUSE 5000
OUTH = %11111 <-- off
PAUSE 5000
So as you can see the way I have to program the board is inverted. 0 means on. 1 means off. Someone told me that the SSR8 reads the code inverted. Or perhaps the Basic Stamp is sending it inverted. Either way it would be a lot easier for my brain to send commands as 0 meaning off and 1 meaning on. Any clues? I've read about the SEROUT command but cant get anything to work.
Another question. Is it possible to declare PAUSE within a variable?
e.g.: A = PAUSE 5000
That throws me an error.
Thanks for any help!
DIRH= %11111
OUTH = %00000 <--on
PAUSE 5000
OUTH = %11111 <-- off
PAUSE 5000
So as you can see the way I have to program the board is inverted. 0 means on. 1 means off. Someone told me that the SSR8 reads the code inverted. Or perhaps the Basic Stamp is sending it inverted. Either way it would be a lot easier for my brain to send commands as 0 meaning off and 1 meaning on. Any clues? I've read about the SEROUT command but cant get anything to work.
Another question. Is it possible to declare PAUSE within a variable?
e.g.: A = PAUSE 5000
That throws me an error.
Thanks for any help!
Comments
A = 5000
Pause A
on CON %00000
off CON %11111
OUTH=on
OUTH=off
this is probably not going to be the eventual answer because you might need to control the on off switching of each player independently but it serves as an example thats easier on the mind and the kind of thing that you can do.
Jeff T.
yes i will definitely want to control the players independently so i'm going to need to find something else...or just reorient my thinking to inverted binary, but that seems really dumb.
That's the symbol for bitwise inversion:
· A = %00100···'write this as 1=on, 0=off
· B = ~A······ 'Therefore, B = %11011
·
OUTH = %00100
PAUSE 5000
OUTH = %10011
PAUSE 5000
OUTH = %10001
PAUSE 5000
OUTH = %10111
PAUSE 5000
and so on and so on....
so im trying to invert the entire output
The only way I can see that you can do what you appear to want to do, is to use five hardware inverters on the output pins of each pin port.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Genius is one percent inspiration and ninety-nine percent perspiration."
Thomas Alva Edison
www.solarbotics.com/products/74ac14n/
What you need is a 7404 (74xx04) hex inverter. They should be available most anywhere, but I noticed that Solarbotics doesn't offer them - sorry.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Genius is one percent inspiration and ninety-nine percent perspiration."
Thomas Alva Edison
Nevermind.
Rather than using additional hardware, such as a hex inverter (which should work), couldn't one simply use the inverted form of baudmode ? That is, 16468 instead of 84, for a BS2?
Just asking <grin>
Terry
SEROUT 0, 16468 ................?
Setting that aside and dealing with the task of allowing you to enter a logic 1··equals on and transparently inverting it for·an output that equals 0 then PJ Allen's suggestion of the tilde operator is the ideal solution. The bitwise invert (~) does exactly the same thing to the value as adding a hex inverter to your circuit, so unless you have current limitations you are wasting your time
You don't say where or how you are setting the values of the binary output but your example of OUTH followed by a PAUSE repeatedly is not an economical·or versatile way to switch the outputs. Where you have code that repeats often it is better placed inside a sub routine, for example
Output_values:
OUTH = ~switch_value······· 'entering a value of %00001 would output a value of %11110 switching on player 1
PAUSE Pause_value··········· 'you can vary the pause time here
RETURN
If you need assistance on how you would pass a value to·a sub routine post more details of where and how you want to control the record players.
Jeff T.
and now as you say i should declare a subroutine
Now every digit of the binary corresponds with a record player (5 record players). I want to turn the record players on and off indiscrimiately, and irregularly so they cant be included in a loop i can repeat.
So if i were to call that subroutine every time i want a different record player state wouldnt i have to do this:
...and so on and so on....
That is actually less economical than the repetitive code than i had originally! But it is more versatile. Got any improvements?
Thanks,
Brian
EDIT: P.S: What i would really love is to just declare binary values one after another with only a call to the subroutine at the end, and only change the pause value when i have to. So i could kind of have a visual map of what is going on....
Post Edited (bigfresh) : 2/27/2008 7:04:22 PM GMT
RANDOM switch_value
switch_value=switch_value//32 +1
GOSUB Output_values
Jeff T.
' {$STAMP BS2}
pause_value VAR Word
switch_value VAR Word
MAIN:
· pause_value = 5000
· switch_value = %10000 : GOSUB OutputValue
· switch_value = %01000 : GOSUB OutputValue
· switch_value = %00100 : GOSUB OutputValue
· switch_value = %00111 : GOSUB OutputValue
· switch_value = %00100 : GOSUB OutputValue
· switch_value = %01000 : GOSUB OutputValue
· switch_value = %10000 : GOSUB OutputValue
· pause_value = 2000
· switch_value = %11111 : GOSUB OutputValue
· switch_value = %11110 : GOSUB OutputValue
· GOTO MAIN
OutputValue:
· OUTH = ~switch_value······· 'entering a value of %00001 would output a value of %11110 switching on player 1
· PAUSE Pause_value··········· 'you can vary the pause time here
· RETURN
many many thanks,
Brian
Explain how you've connected the SSR8 because there's more to worry about than just the logical on state. Driving the 8 optocouplers (LEDS) may be too much current for the stamp. My memory is vague· but I believe the stamp is quite limited in the total current it can handle on a port. The SSR8 was designed for use with Cublocs (Atmel mega 128s) which has a much higher current handling capability.
You need to make sure 8 SSRs turned on at once don't exceed the stamp's capability. If there is a danger of over-current then you can use transistors (3904 or 3906, or ULN2803 since there are 8 inputs).
·
And having reviewed the CuBloc site, I think you'll definitely need the Darlington chip -- but only one.· It looks like the CuBloc boards incorporate optically isolated digital outputs already, so the Relay board control signals will require higher currents than the BS2 can put out by itself.· ulm2803 should do it though.
Post Edited (allanlane5) : 2/27/2008 9:06:54 PM GMT
anyhow, as of a few days ago i have everything setup and running and no burnouts..........
In regard to the Baudmode approach; 84 works on the DEBUG port, so I'm assuming (yeah, I know) that 16468 will work on the other pins. I'm not in a position to test...
The command to use the pin would be something like SEROUT "pin-number", baudmode, [noparse][[/noparse]serialdata in hex format]
The brackets are necessary. There are options for flow control and time-out if permission is never received from the other end.