Shop OBEX P1 Docs P2 Docs Learn Events
Bit Signaling — Parallax Forums

Bit Signaling

Bill ChennaultBill Chennault Posts: 1,198
edited 2007-09-17 00:54 in BASIC Stamp
All--

I need some very limited communication between BS2 microcontrollers. My signaling amounts to a single byte. It seems to me that the processor overhead and unavoidable (?) waits induced by use of SERIN and SEROUT may be avoided in my limited-communications case.

To be more precise, I want one Stamp (the "master")·to tell the other how to control a motor via an HB25 (the HB25 is controlled by the "slave" BS2.) To do this, all I need is·one·bit of the byte from the master to instruct the slave to PULSOUT either forward or reverse to the HB25. The remainding 7 bits of the byte will represent the speed. (I may not have 127 speeds. I may only have 20, or less. This will reduce programming overhead and execution time. For example, if there were only 10 speeds, then I would have increments of 25 to·ramp up·from 750 to 1000 or ramp down from 750 to 500.)

Here is a sample of what I am contemplating . . .

Forward, speed "10": 00001010
Reverse, speed "10": 10001010

I have plenty of pins on both the master and slave to dedicate 8·pins on each to this bit signaling via HIGH and LOW statements executed by the master.

I THINK the code would look something like this on the master . . . in the specific case shown above:

Forward, speed 10

LOW 7······· '· forward
LOW 6······· '· speed bit
LOW 5······· '· speed bit
LOW 4······· '· speed bit
HIGH 3······ '· speed bit
LOW 2······· '· speed bit
HIGH 1······ '· speed bit
LOW 0······· '· speed bit

Reverse, speed 10

HIGH·7······ '· reverse
LOW 6······· '· speed bit
LOW 5······· '· speed bit
LOW 4······· '· speed bit
HIGH 3······ '· speed bit
LOW 2······· '· speed bit
HIGH 1······ '· speed bit
LOW 0······· '· speed bit

Of course, Stop would be represented by sending a speed of zero with either the forward or reverse signaling.

This would allow 8 pins on the master to represent my command byte. Each of these 8 pins on the master would, of course, be connected to corresponding pins on the slave. The slave would have simple code to detect the status of the eight input pins dedicated to communication with the master. (I do not know exactly what the circuit looks like, master-pin to slave-pin. I think a resistor is involved. Maybe that will be another question?)

In MY MIND, this scheme would be as fast as possible and not entail the enforced waits involved with SEROUT/SERIN.

Am I correct in this thinking? If not, will you please set me straight?

Thanks!

--Bill

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.

Comments

  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-09-16 17:03
    All--

    Ha! A little Parallax Google search (well, more than a little!) reveals that I asked a VERY similar question some months ago and got good answers from a bunch of folks, including Mike Green . . .
    Theoretically, you could just connect the two pins together assuming that the two Stamps have a common ground connection. In practice, you should use a current limiting resistor to connect the pins, anywhere from 220 ohms to 10K in value, just in case you have a programming error and the two pins both get set to output mode at opposite levels (one low and one high) which would cause a short circuit and possibly burn out one or both I/O pins. said...
    (replace this text with what was said)
    Thanks . . . again, Mike (and everyone else)!

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-16 23:28
    Bill,
    You may want some kind of handshake bit each way. In your case, if the slave is constantly checking the master and it doesn't matter if the same value is send to the HB-25 multiple times, it won't matter whether you use this or not. The idea is that the master toggles the handshake out line from low to high and the slave is periodically watching for this. The slave reads the value and acts on it, then toggles its handshake line from low to high. When the master sees the slave's handshake line go from low to high, it knows the slave has read the value, so it toggles its handshake line from high to low to signal to the slave that it's seen the response. When the slave sees the master's handshake line go to low, it sets its handshake line to low and the whole cycle can begin again.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-09-17 00:38
    Mike--

    As always, I beg your indulgence with my ignorance.

    My thought is that the persistence of the master's I/O state would be an advantage because the master provides all instructions to the slave. If the instructions do not change, then every time the slave looks at its I/O pins (I've decided five pins are·enough for my purposes) it will simply skip all the code that performs analysis to do . . . whatever, because nothing has changed.

    If the master changes the state of the I/O pins in order to provide the slave with new instructions, then the new state of the master's I/O pins will be "sitting there waiting" for the slave the next time it goes through its very tight little loop looking for something to do.

    The Propeller, as Martin H. suggests, would be a FAR better device than my idea of "connected" (can't hardly call them networked) Stamps. However, I WANT to do it this way to learn a little bit. The NEXT machine will be Propeller based. (I believe each cog·is a·20·MIPS device, while even the fastest Stamp is only a 19 KIP machine. Imagine! A thousand times faster, plus 32 bit instructions! I need to finish this project and begin bugging you guys on the Propeller forum.)

    I would certainly appreciate your insight into this scheme. Without doubt, I am missing something, maybe a lot.

    Thanks.

    --Bill
    ps I intend to connect BS2 modules pin to pin with a 1k resistor. All BS2 modules will be on the same breadboard and powered by the same 7.2v battery. Therefore (again, my thinking!), all BS2 share a common ground, already. Am I on the right track?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-17 00:48
    As I mentioned, you can do your project without the handshake pins. I was describing the general case of parallel Stamp to Stamp communication.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-09-17 00:54
    Mike--

    Got'cha. You did mention it. I didn't read it well.

    How about the grounding "question" in my ps?

    --Bill



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
Sign In or Register to comment.