Shop OBEX P1 Docs P2 Docs Learn Events
Serial Comm problems with laser controller — Parallax Forums

Serial Comm problems with laser controller

ZakZak Posts: 7
edited 2006-06-14 15:01 in BASIC Stamp
Hi

I am using the BS2p, and I am trying to interface over rs232 to a laser controller.· The laser controller does not implement handshaking, so i am doing no flow control at a slow baud rate.· IU am able to send a command over, but I am not able to get a response from a query.· I should be able to have the following conversation with the controller:

Me> :SOUR:VOLT:PIEZ?
It> :77.3V
Me> :SOUR:VOLT:PIEZ 77.2
Me> :SOUR:VOLT:PIEZ?
It> :77.2V




I am just trying to send the first command and get the answer into a variable.· Here is where I am at now:
' {$STAMP BS2p}
' {$PBASIC 2.5}
LcdCls          CON     $0C             ' clear LCD (use PAUSE 5 after)
Baud1200       CON     2063
Baud2400       CON     1021
Baud4800       CON     500
Baud19200 CON 110
Baud9600  CON 240
DispBaud  CON Baud19200
COMBaud CON   Baud2400
resp  VAR Byte(6)
SEROUT 16, COMBaud, [noparse][[/noparse]":SOUR:VOLT:PIEZ?", CR, LF]
SERIN 16, COMBaud, [noparse][[/noparse]STR resp\5]
SEROUT 15, DispBaud, [noparse][[/noparse]LcdCls]
resp(5) = 0
SEROUT 15, DispBaud, [noparse][[/noparse]"::", STR resp]




Even if I replace the byte array with a single byte, i still hang in the same place.

Any suggestions you might have for how to move forward would be greatly appreciated.· In case anyone is interested, the box i am talking to is the vortex 6000 by newfocus.

Thanks
Zak


Post Edited (Zak) : 6/12/2006 7:50:46 PM GMT

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-06-12 20:16
    You don't indicate how the message from the Laser is terminated. I believe the BS2 waits for either 5 bytes, or a 'CR' character, before it returns with the syntax you're using. It's also possible that the Laser is replying before the BS2 is in the SERIN -- but I don't think that should hang it.

    Oh, wait, you're using the pseudo-port "16". You're aware that everything written to that port is 'echoed' back to the sender, right? That could confuse the Laser.

    And where are you hanging, anyway? And how do you know?
  • ZakZak Posts: 7
    edited 2006-06-12 20:21
    Ummm, The laser controller manual says that commands should be terminated using the newline character, which i believe is 0x0A, or LF. And yes, I want to use the serial port for RS-232. I am on the demo board right now, and that is the way that the I/O for rs232 is accessed right? Is there any way of accessing it in some other way so that this doesnt happen?

    And with the hanging, SERIN waits for data to come over on the wire. If I add a timeout by doing:
    SEROUT 16, COMBaud, [noparse][[/noparse]":SOUR:VOLT:PIEZ?", CR, LF]
    SERIN 16, COMBaud, 2000, handle, [noparse][[/noparse]STR resp\5]
    goto resume
    handle:
    ....handle it somehow
    resume:
    ...keep going

    Then it just continues on with the string uninitialized after waiting the two seconds.

    Thanks for your reply. I did not know that information about the pseudo port. Seems like that would confuse a lot of things.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-13 01:53
    Zak,

    ·· Do you have a BASIC Stamp Logic Analyzer or Scope?· If so you could watch the line to see how quickly the data is being returned.· That might indicate whether or not the device is sending data before the BS2 is ready to receive it.· Are the commands you're sending affecting the device, regardless of not getting a response?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ZakZak Posts: 7
    edited 2006-06-13 14:35
    Hi, I don't have any of that stuff. I have, however, switched things around so that the programming cable is in the serial port and I am now trying to address the device using a serial cable, with pins 2 and 3 connected to pins on the stamp, and pin 5 connected to VSS. Now I cannot even issue a simple command to the device. Before, I was seeing fragments of error messages as I was displaying them. Hopefully, now I can view what's going on in the debug window. If anyone could help me figure out how to hard wire this rs232, that would be awesome. Thanks for the reply chris.
  • ZakZak Posts: 7
    edited 2006-06-13 14:58
    This is it now:

    Baud2400 CON 1021
    Baud4800 CON 500
    Baud19200 CON 110
    Baud9600 CON 240
    DispBaud CON Baud19200
    COMBaud CON Baud2400

    COMOUT CON 13
    COMIN CON 14
    r VAR Byte

    resp VAR Byte(6)

    DEBUG "Sending Message", CR, LF
    DEBUG ":SOUR:VOLT:PIEZ 70.0", LF
    SEROUT COMOUT, COMBaud, [noparse][[/noparse]":SOUR:VOLT:PIEZ 70.0", CR, LF]
    DEBUGIN r ''see if voltage on device changed.
    'Device Has Addressed and Remote leds, neither come on.


    Update: I am now using the rig up that I made for the rs232 communication going to HyperTerminal. There is just the stamp and the computer now for the testing. Thanks to all for help.

    Ugh this is frustrating. The Terminal program is giving no response over rs232 with the above program. Is there something that I am missing with only using the three wires? Thats what the laser controller uses. Any ideas?

    Post Edited (Zak) : 6/13/2006 4:34:26 PM GMT
  • steve_bsteve_b Posts: 1,563
    edited 2006-06-13 16:35
    Hi Zak,

    you are sending out i/o 13 and receiving on i/o14. Just note that these are not the physical pins of the actual stamp, but labeled pins (don't have an image on this computer to reference to say what it actually is).

    If that isn't what's mucking you up, then you should be aware that if you use port 16 for your serial tasks, you use the TRUE values (1021 for 2400baud)....but if you use any other I/O, you MUST use the Inverted numbers (see the PBasic help file under SERIN.....so for 2400baud it would be 17405 for inverted.

    Now, your stamp is then sending out a pseudo-RS232 signal.....typical RS232 voltages are -12V to +12V (or 8volts....not much of a standard if it's never the same). Most devices don't care about the negative voltage as they usually only detect whether the voltage is over/under a certain threshold...which is usually about 1.8 volts or so (some say 2.5).
    So, you should expect long distances to be achieved running rs232 from a stamps I/O pin.
    Now....here's the tricky part.
    Normal logic levels are 0volts and 5volts. 0volts = logic 0 and 5volts = logic 1; this is the binary that makes the computer world hum!
    Well, proper RS232 is inverted.....so a logic 0 = -12V and a logic 1 = +12V (these are known as spaces and marks).
    So, when you tell the stamp to send serial data out of one of its I/O ports in an inverted fashion, a logic 1 = 0volts and a logic 0 = 5volts.

    When you are talking to a serial device (computer/modem/gps/etc.) you must use inverted when coming out of an I/O port (I/O not being the programming port).
    Now, you can talk to other stamps in either true or inverted....just so long as the other end is set to match.

    Hope I didn't get too wordy!

    Cheers

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • ZakZak Posts: 7
    edited 2006-06-13 16:44
    That sounds like it makes sense, and yes, I have noticed with a meter that the signals coming in are negative and too big. Does this mean that I need to use other circuitry to bring down the inputs coming from the laser controller? Will the basic stamp understand that -12 is 0 and +12 is 1?

    Do I need to adjust the outputs of the i/o pins for sending to the laser controller so that the 0 turns to a -12 and the 5 turns to a +12 somehow?

    Thanks a lot for this information
  • steve_bsteve_b Posts: 1,563
    edited 2006-06-13 16:56
    Zak, are you sending AND receiving with your stamp?

    A quick look (hint hint) at the PBasic help file will give you some tips on how to handle serial comms with your stamp.

    Essentially you need to put in a current limiting resistor...it goes inline with your receiving line from your device under test.
    The stamp has internal clamping diodes that can handle the 12volts....but it's the current that it can't handle. So, check the SERIN command under the help file and note the circuit there.

    Within your code, you simply need code what your baudvalue is (the SERIN command has a table with the appropriate values) and it'll understand if your incoming signal is inverted or not....

    Cheers

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • ZakZak Posts: 7
    edited 2006-06-13 16:58
    IT works!!! Thanks for your help!
  • ZakZak Posts: 7
    edited 2006-06-13 17:24
    Ok, I Got the circuit, makes sense, however I am still hving problems with the stamp interfacing with the controller. Should the controller be able to understand based on what you were saying steve that 0V is 1 and 5V is 0, or do I need to amplify the output coming from the stamp?
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-06-13 18:05
    Typically, you would use a Maxim MAX232 chip on the TX side coming out of the BS2 going to your device. The MAX232 turns the 0 to 5 volt signal the BS2 generates into the +12 to -12 signal your external device wants. The MAX232 uses 4 external capacitors as a charge pump to create the + and - voltages at the chip, so you don't need extra power supplies.

    The 'sense' (Inverted or not) of the SEROUT signal depends on if you have a MAX232 in there or not, or if your external device is using a MAX232 or not. There's no standard definition of what's "Inverted", unfortunately, so you may have to experiment.

    How close is your Laser device, anyway? If it's further than 10 feet, you may be forced into using the MAX232. Note there do exist reasonably priced adapters ($15 or so) from www.kronos-robotics.com and others to simplify using the MAX232.
  • Tom WalkerTom Walker Posts: 509
    edited 2006-06-13 18:09
    The easiest way to handle this is to use a MAX232 chip to handle the 5V to '232 conversion issues...both ways. It's cheap and easy to implement (lots of examples). You might be able to use port 16 and its native "I'll just steal the +-12V from the sending device" trick, but I wouldn't bet the silicon on it...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • steve_bsteve_b Posts: 1,563
    edited 2006-06-14 15:01
    Hey Zak,

    Allan and Tom are right....you may need to use a MAX232 chip ( go to www.maxim.com for specs...can be ordered from digikey).
    The MAX232 requires 5capacitors to get the "charge pump" running. I personally like using this one...however, if you want to limit the number of components on a board, the MAX233 works the same as the MAX232, but the 233 has the capacitors built in. Makes for a cleaner looking project!

    In my experience, my laptop has had no problem understanding the lower voltage levels coming from one of my stamp I/O ports. I've also talked to other devices the same way without the MAX chips....however, this won't always be the case, so some experimenting is required.
    As far as whether the device knows things are coming at it inverted or not....well, if it's a normal RS232 port, it expects them to be RS232 signals (so yes, it'll translate a -12V/0V as a logic 1 and +12V/5V as a logic 0....no additional work is required at that point).

    Cheers

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
Sign In or Register to comment.