Shop OBEX P1 Docs P2 Docs Learn Events
SEROUT and 12Bit ADC — Parallax Forums

SEROUT and 12Bit ADC

sumguy16sumguy16 Posts: 21
edited 2005-11-30 01:10 in General Discussion
I am working on a wireless ADC. I have completed the prototype using a BS2, now for the hard part: switching to the SX20. I've just started working the SEROUT command with SX/B and have succesfully sent data across a wireless network. I cannot however transmit variables, I can only transmit constants. Here is my code:

i var byte

TX_Byte sub 1

Start:

pause 200

for i = 0 to 20
    TX_Byte i
    pause 20
next    
goto Start

TX_Byte:
    SEROUT ra.0, T19200, __PARAM1
return




I don't understand why this doesn't work, when I use hyper terminal I get a bunch of garbage, and when I change i to a constant the value is transmitted?

Also, I'm using a 12bit ADC and I would like to possibly use a 16bit ADC, any advice as to transmitting a 12bit value when I'm dealing with an 8bit byte?

And lastly, is it possible to transmit at 19200Bps @ 4MHz? Right now I'm running at 50MHz which isn't necessary and is a waste of power.

Thanks for reading!
Adam

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-25 12:03
    The reason it doesn't work is that you're using one of SX/B's internal work variabled (__PARAM1) inside you subroutine. If you do a Ctrl-L and look at the listing you'll see that __PARAM1 is used as part of the code that generates SEROUT. Add a set of work variables that you can use to hold passed parameters for your program, then you can update your program like this (from the SEROUT example in the help file):

    ' Use: TXBYTE theByte {, repeats }
    ' -- first parameter is byte to transmit
    ' -- second (optional) parameter is number of times to send

    TXBYTE:
    · temp1 = __PARAM1············ ·' char to send
    · IF __PARAMCNT = 1 THEN······ ·' if no repeats specified
    ··· temp2 = 1·················· ' - set to 1
    · ELSE
    ··· temp2 = __PARAM2
    · ENDIF
    · DO WHILE temp2 > 0
    ··· SEROUT Sout, Baud, temp1··· ' send the character
    ··· DEC temp2
    · LOOP
    · RETURN

    Another thought -- you should send printable ASCII characters to Hyperterminal; use "A" TO "Z" in your loop instead of 0 TO 20.· You should be able to do 19.2K with a 4 MHz resonator (note, you cannot do serial with the internal oscillator), but I'd probably bump to 8 MHz to be safe.· Once you get the basic serial stuff going (should be easy, I do it all the time and have no problems with HyperTerminal) then you can transmit like you do with your BASIC Stamp: one byte at a time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 10/25/2005 12:31:02 PM GMT
  • sumguy16sumguy16 Posts: 21
    edited 2005-10-27 03:05
    Alright I got the SX transmitting values that are not constants, but now I'm stuck on reading a 12Bit adc. I saw the code snippet in the SX/B Help, but it wasn't very detailed. I'm still confused how to handle a 12Bit input with 8Bit variables. Here is my code that I'm using, I just get a bunch of garbage in Hyperterminal and the PBASIC debugger:

    DEVICE          SX18,  OSCHS1, TURBO, STACKX, OPTIONX
    FREQ            4_000_000
    
    PROGRAM Start
    
    ' Program Variables
    i var byte
    temp var byte
    measure var byte
    batt var byte
    
    config VAR byte
    startB VAR config.0 ' Start bit for comm with ADC.
    sglDif VAR config.1 ' Single-ended or differential mode.
    oddSign VAR config.2 ' Channel selection.
    msbf VAR config.3 ' Output 0s after data xfer complete.
    
    ' Program Subroutines
    TX_Byte sub 1
    ADC_Read sub 0
    
    ' Program Pins
    Sout var ra.0
    CS var rb.0
    CLK var rb.1
    DIO_n var rb.2
    
    ' Program Constants
    Baud CON "T19200"
    
    '==== Program ====
    Start:
        ' Output Line:   @measurementBbatt
        ADC_Read
        TX_Byte "@"
        TX_Byte measure     
        TX_Byte "B"
        TX_Byte batt
        pause 200
    goto Start
    
    '======================================
    '==== Analog to Digital Subroutine ====
    '======================================
    ADC_Read:
    config = config | %1011 ' Set all bits except oddSign.
    LOW CS ' Activate the ADC.
      LOW CS
      SHIFTOUT DIO_n, Clk, LSBFIRST, config\4         ' send config bits
      SHIFTIN  DIO_n, Clk, MSBPOST, measure\4        ' get data (upper nibble)
      SHIFTIN  DIO_n, Clk, MSBPOST, batt\8        ' get data (lower byte)
      HIGH CS
    return
    '===============================
    '==== Serial Out Subroutine ====
    '===============================
    TX_Byte:
        temp = __PARAM1
        SEROUT Sout, Baud, temp
    return
    
    



    I would be grateful if someone could point me in the right direction, this is my first major project that I have done on the SX. Trying to make the jump to where the professionals play...

    Thanks,
    Adam
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-27 03:17
    SX/B doesn't handle 16-bit values as single units; you may want to have a read through Al Williams' or Guenther Daubach's books as they both discuss working with values beyond 8-bits. If you can do it in assembly you can apply it to SX/B.

    If you'll tell me specifically what ADC you're using I'll write a demo for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 10/27/2005 3:33:44 AM GMT
  • sumguy16sumguy16 Posts: 21
    edited 2005-10-27 03:51
    the LTC1298, I would appreciate the demo very much.

    Adam
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-27 05:57
    Okay, this program works.· Interestingly enough, I found a mention of the LTC1298 in the SX/B help file ... at the end of the section on SHIFTIN.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • sumguy16sumguy16 Posts: 21
    edited 2005-10-27 06:56
    WOW! Talk about results, I can't thank you enough for the demo, it works flawlessly. I'm sure you hear this a lot, but Parallax keeps on surprising me with their customer service, keep up the good work and I'll keep buying.

    Thanks again Jon,
    Adam
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-27 15:32
    Glad it works for you -- now buy Parallax products as Christmas gifts for all of your friends and family; share the joy! tongue.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • sumguy16sumguy16 Posts: 21
    edited 2005-11-29 08:46
    Alright I have my project working on a bread board exactly how I want to and of course when I make the proto board version it all goes to hell. I have been able to transmit data over SEROUT so I know the problem lies with the ADC, I have been in the process of verifying my solder joint for the last three days so I feel that it is a software issue.

    The output with the bread board version is something like: V0FFF%0000
    Where the first character determines the measurement type, next the value of the meaurement on ch1 seperated by a % sign and then the last value of ch2 is displayed. With the proto board version I get: V‚‚‚* with two blocks after the asterisk. I have read things about bit shifting, but I am not sure why this would come up from transferring from a bread board to a pc board.

    I thought that this process would be a matter of switching pin assignments in the code, but I guess not...

    Any ideas would be greatly appreciated,
    Adam from Seattle
  • PJMontyPJMonty Posts: 983
    edited 2005-11-29 18:15
    Adam,

    On your proto board, what are you using for a clock for the SX? A resonator, a TTL clock, or the internal 4 MHz clock?
      Thanks, PeterM
  • sumguy16sumguy16 Posts: 21
    edited 2005-11-29 23:12
    Murata 4MHz xtal
  • NateNate Posts: 154
    edited 2005-11-30 01:10
    I have issues when using crystals with my SX's.· I have not had the same problems when using the Murata resonators (4 or 50 MHz).· I have also had good luck using TTL clocks.

    I also find that the SX is really sensitve to the lead length between the SX and the clock source.· Now when I do a PC layout, the first thing that goes on, and as close to the SX as I can get it, is the clock source.

    Nate
Sign In or Register to comment.