Shop OBEX P1 Docs P2 Docs Learn Events
Serout command - advice please — Parallax Forums

Serout command - advice please

FardeenFardeen Posts: 9
edited 2004-12-18 18:57 in BASIC Stamp
I am trying to get a signal from ADC0831 (8 bit analog to digital converted) and want to send that serially out via RS232 to Labview.
I am pretty sure there is something wrong with my SEROUT COMMAND as I can see output coming out of the ADC on my debug screen and am pretty sure that my labview code is perfect.
Am I sending the right data??? I think I am not stroing it properly but dont know how to correct it.
Can anyone advice me what to do please??










'{$STAMP· BS2}······· 'STAMP directive (specifies a BS2)
'
[noparse][[/noparse] Initialization ]
CS CON 2
CLK CON 1
RD1 CON 0········ ' Read Signals via Specified Pins
'CS2 CON 3
RD3 CON 4
TD16 CON 16······ ' Transmit data serially
baud CON 16624··· ' N9600 for BS2
sig VAR Byte···· ' Bytes to store the signals
DEBUG CLS········ ' Start display.
looping:
'
[noparse][[/noparse] Declarations ]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte

'
[noparse][[/noparse] Main Routine ]
GOSUB RDSIG1········· ' Read the signal
GOSUB Calc_Volts···· ' Calculate the signal in voltage form
GOSUB Display········ ' Display the results
SEROUT TD16, baud, [noparse][[/noparse]RD1]
GOTO looping

'
[noparse][[/noparse] Subroutines ]
RDSIG1:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN RD1,CLK,MSBPOST,[noparse][[/noparse]adcBits\8]
RETURN

Calc_Volts:
v = 5 * adcBits / 255
r = 5 * adcBits // 255
v2 = 100 * r / 255
v3 = 100 * r // 255
v3 = 10 * v3 / 255
IF (v3 < 5) THEN skip_a_line
v2 = v2 + 1
skip_a_line:
IF (v2<100) THEN skip_out
v = v + 1
v2 = 0
skip_out:
RETURN

Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR, CR, "Decimal value: ", DEC3 adcBits
DEBUG CR, CR, "DVM Reading: "
DEBUG DEC1 v, ".", DEC2 v2, " Volts"
RETURN
PAUSE 1000
RETURN

Comments

  • FardeenFardeen Posts: 9
    edited 2004-12-17 19:07
    I forgot to mention that I want to receive 8 bits binary data via COM port at the receing end.
    Please advice.
    Thanks
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-17 19:11
    Yes, there's a problem.

    The 'TD16' and the DEBUG statements are sending the data to the same place. That is:

    SEROUT 16, 84 + 16384, [noparse][[/noparse]"hi"] and
    DEBUG "hi"

    do EXACTLY the same thing. The 'DEBUG' baud rate is 9600, 'inverted'. Pseudo-pin 16 is the programming port to your PC.

    Thus, Labview is getting nothing. Now, if you don't do the "GOSUB Display", it may work.

    One other factor is only one program can open the serial port at a time. I believe the IDE 'releases' the port when it's not programming the device, IF you have closed all 'DEBUG' terminal windows, so you could bring up Labview and Labview could have the port.

    Otherwise, your 'DEBUG' terminal window will block LabView from connecting to the BS2.

    Also, you've made RD1 (the thing in your SEROUT statement)·a CONstant, so you are always outputting zero.· You probably want to output 'v' or 'r' or something that depends on the value read by the ADC, no?

    Post Edited (allanlane5) : 12/17/2004 7:17:02 PM GMT
  • FardeenFardeen Posts: 9
    edited 2004-12-17 19:21
    I tried doing removing the DEBUG commands and use SEROUT to transmit the same data as above but i am getting junk displays while same data is being displayed correctly by DEBUG command.

    I am· not quite sure why that is happening. COuld anyone please help.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-17 19:32
    I don't know what you want to send to LabView.

    If LabView wants the 8 'raw' ADC Bits, then you need a single SEROUT statement:

    SEROUT 16, 84+16384, [noparse][[/noparse]adcBits]

    And, with your current setup, you cannot have BOTH a 'debug' screen output AND Labview getting input at the same time.· You're trying to use the same serial port for both purposes.
  • SofalogicSofalogic Posts: 49
    edited 2004-12-18 18:57
    I was looking at your code. I may be wrong but I think·code for·9600 n 8 1 is "84" You may want to double check this.

    Sofa
Sign In or Register to comment.