Pulling out 1 digit from binary number
TeamPike
Posts: 3
Hello,
I am a 4H leader of a club that makes ROV Submarines. I am currently trying to prove the the entire club that using a basic stamp will be the best way. So far, I only have one problem. It might getting a little confusing so try your best to follow me.
There are 4 motors to control. Each one will also need reverse. To send controls to the stamp I want to send ascii code. But I will be putting it together using Binary thinking. the first digit (10101010) says motor one goes forward, the second digit says motor 1 goes back. Each 'set' of two digits is for one motor.
I can't figure out how to either, A: put each digit, when received, into an array, or B: Using DIG to select each digit. I've been having problems with B (DIG) because even though I saved the incoming signal as Binary (BIN), when I got use the variable later, it's been converted to an ascii code.
Thank you for any help!
Bryan
I am a 4H leader of a club that makes ROV Submarines. I am currently trying to prove the the entire club that using a basic stamp will be the best way. So far, I only have one problem. It might getting a little confusing so try your best to follow me.
There are 4 motors to control. Each one will also need reverse. To send controls to the stamp I want to send ascii code. But I will be putting it together using Binary thinking. the first digit (10101010) says motor one goes forward, the second digit says motor 1 goes back. Each 'set' of two digits is for one motor.
I can't figure out how to either, A: put each digit, when received, into an array, or B: Using DIG to select each digit. I've been having problems with B (DIG) because even though I saved the incoming signal as Binary (BIN), when I got use the variable later, it's been converted to an ascii code.
Thank you for any help!
Bryan
Comments
Perhaps you can clarify: Are you using one byte per motor, or one nibble per motor which gives you two motors per byte? It would probably help if you could explain (and diagram with values) what your control stream should look like. PBASIC is incredibly flexible, and once we know what your control stream is supposed to look like, we can help you with a bit of code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
'Motor one controls
Pin1State=Bit1
Pin2State=Bit2
Three more blocks would be needed. Again, something like this:
'Motor two controls
Pin3State=Bit3
Pin4State=Bit4
'Motor three controls
Pin5State=Bit5
Pin6State=Bit6
'Motor four controls
Pin7State=Bit7
Pin8State=Bit8
Basicly, the bit, being only 0 or 1, will set a pins' state. Each pin will have some circuitry to get a reverse for a motor. But the reason for doing it this way, is so I can solve the following situation:
Motor 1 and 2 are used to move forward/backward, and turning. To go straight, I send %10100000. To go back I send %01010000. To turn to the left or right I send either %10010000 or %01100000.
Does this clear it up a bit? I hope so, it's confusing to try to explain it. But please don't suggest I use RC gear or something else. There are several strong reasons why I need to use a basic stamp.
Thanks Again for any help,
Bryan
The easiest way around this would be to map the byte to one of the two 8-bit pin groups, OUTL and OUTH. Let's say, for example, you went with OUTL. Your code is as simple as:
· SERIN pin, baud, [noparse][[/noparse]cmdByte]
· OUTL = cmdByte
This will map the bits directly -- P0 will get the value from cmdByte.Bit0; P7 will get the value from cmdByte.Bit7.
If, due to design constraints, your IO mapping isn't that clean, PBASIC still makes it pretty easy -- you just have to map the bits manually. If, for example, you were using pins 4 - 7 for motors 1 and 2, and pins 8 - 11 for motors 3 and 4 you could do this:
· SERIN pin, baud, [noparse][[/noparse]cmdByte]
· OUTB = cmdByte.NIB0
· OUTC = cmdByte.NIB1
Finally, if things are all over the place, you can map things pin by pin:
· SERIN pin, baud, [noparse][[/noparse]cmdByte]
· OUT0 = cmdByte.BIT0
· OUT2 = cmdByte.BIT1
· ...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Thanks for your help, thats exactly what I needed to know! · Now, do you know how to use vb6 to generate a PWM signal?
Thanks Again!
Bryan
PS. This basic stamp is going to be using on an inexpensive ROV Submarine. Each team - there are 4 teams - gets about $300 to spend. But we will be using a basic stamp on our ocean going sub which will cost about $20000. Shows you how much we (4h club) trust Parallax.
If I were doing it, I would create a control panel with radio-buttons that let me select a motor or combination of motors (not all combinations are valid, so this shouldn't be giant list). Once a new selection is made the value is transmitted to the BASIC Stamp using the MSComm control. If you look in our Nuts & Volts section on the web site you'll find a couple articles about sending values to a BASIC Stamp using VB6.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office