Shop OBEX P1 Docs P2 Docs Learn Events
Pulling out 1 digit from binary number — Parallax Forums

Pulling out 1 digit from binary number

TeamPikeTeamPike Posts: 3
edited 2004-11-08 19:00 in BASIC Stamp
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

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-08 02:10
    Bryan,

    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
  • TeamPikeTeamPike Posts: 3
    edited 2004-11-08 06:22
    For various reasons, I will use the computer to generate the PWM signal for each motor. I plan to use a one byte character to controll all the motors. The computer will be constantly·sending some character. If no motors are to be running, then it will be sending a one byte value of %00000000. Zero meaning off. The computer will never send more than one byte to controll the submarine. The first two bits, are the info for the first motor. Lets say I want to turn it on to move forward. Then I would send %10000000. But now I went too far forward and need to back up, so I send %01000000. So, the plan is to set up some code like this that is constantly looping:

    '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
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-08 14:24
    Actually, this is a "no brainer" -- if I'm understanding correctly. What you want to do is receive a character, than map the bits in that character to various IO pins? If that's what you're looking for, you're in luck with the BASIC Stamp.

    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
  • TeamPikeTeamPike Posts: 3
    edited 2004-11-08 16:28
    Jon,

    Thanks for your help, thats exactly what I needed to know! yeah.gif· Now, do you know how to use vb6 to generate a PWM signal?smilewinkgrin.gif



    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.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-08 19:00
    There are lots of VB6 resources on the Internet ... Google is your friend!

    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
Sign In or Register to comment.