Shop OBEX P1 Docs P2 Docs Learn Events
Transmitting Garbage — Parallax Forums

Transmitting Garbage

Shawn LoweShawn Lowe Posts: 635
edited 2008-08-31 17:59 in General Discussion
Okay, here is my kegarator program to date. However, Stamplot and debug (TR's DBTerm) just wont display any data (good data; DBterm just shows ????). I have a resonator in ( didn't before) so, can anyone tell what's wrong? Do you have to format the data like you do when you print ascii on a LCD?

' =========================================================================
'
'   File...... Kegarator_v1.0.SXB
'   Purpose... Tempurature controller for homebrew kegs
'   Author.... Shawn Lowe
'   E-mail.... [url=mailto:livinlowe2006@yahoo.com]livinlowe2006@yahoo.com[/url]
'   Started...
'   Updated...
'
' =========================================================================
' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Reads value from an ADC0831 that is connected to a LM34 Tempurature Sensor
' Note that the SpeedMult feature is used with SHIFTIN to bump the clock
' speed up to ~332 kBits/sec (ADC0831 max is 400). This value will control a 
' RC-4 board from EFX-TEK in order to control the compressor on a freezer to 
' regulate tempurature on homebrew in Cornilius Kegs.
' -------------------------------------------------------------------------
' Revision Notes:
' 1.0 -- Basic functionality
' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------
DEVICE   SX28, OSCHS2, TURBO, STACKX, OPTIONX
FREQ   20_000_000
ID   "beercool"
' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------
Cpin   PIN  RA.2 OUTPUT  ' shift clock
Dpin   PIN  RA.1 INPUT  ' shift data
CS   PIN  RA.0 OUTPUT  ' chip select
TX  PIN RB.1 OUTPUT  ' transmit to PC / Stampplot
RC4   PIN  RB.0 OUTPUT  ' transmit to RC4

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------
temperature VAR Byte   ' main variable
tmpB1   VAR  Byte    ' working variables
tmpB2           VAR     Byte
tmpW1  VAR Word
' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------
IsOn            CON     1
IsOff           CON     0
App_Mod_On CON %1000   ' not currently used
App_Mod_Off CON %0000
BaudMode        CON     "OT38400"
CR  CON 13
' =========================================================================
 PROGRAM Start
' =========================================================================
' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------
DELAY_MS        SUB     1, 2                    ' delay in milliseconds
TX_BYTE         SUB     1                       ' transmit a byte
TX_STR          SUB     2                       ' transmit a string
TX_BYTE_PC      SUB     1                       ' transmit a byte
TX_STR_PC       SUB     2                       ' transmit a string
RESET_RC4       SUB     0                       ' reset the RC-4
SET_RC4         SUB     1                       ' set RC-4 relays
Get_ADC  SUB     0,1   ' get adc reading
' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------
Start:

  DELAY_MS 250                                  ' let RC-4 power up
  RESET_RC4
  HIGH CS      ' make CS output, no ADC
  LOW Cpin      ' make clock 0-1-0
Main:
  
  temperature = Get_ADC
    
  'watch temperature, 8, udec
  TX_BYTE_PC temperature
  TX_BYTE_PC CR
  TX_STR_PC "TEST"
  If temperature >= 38 then
 SET_RC4  %1000
  EndIf
 
  If temperature <= 34 then
 SET_RC4  %0000
  EndIf
  DELAY_MS 500
  'BREAK
GOTO Main
 
 
' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------
' Use: aVar = GET_ADC
' -- reads ADC0831 and places value into 'tmprtr'
FUNC Get_ADC
  CS = 0      ' activate ADC0831
  SHIFTIN Dpin, Cpin, MSBPOST, tmpB1\1, 4  ' start conversion
  SHIFTIN Dpin, Cpin, MSBPOST, tmpB1, 4  ' shift in the data
  CS = 1      ' deactivate ADC0831
  RETURN tmpB1
ENDFUNC
' -------------------------------------------------------------------------
' Use: DELAY_MS duration
' -- replaces PAUSE

SUB DELAY_MS
  IF __PARAMCNT = 1 THEN
    tmpW1 = __PARAM1
  ELSE
    tmpW1 = __WPARAM12
  ENDIF
  PAUSE tmpW1
  ENDSUB
' -------------------------------------------------------------------------
' Use: TX_STR [noparse][[/noparse]string | label]
' -- "string" is an embedded string constant
' -- "label" is DATA statement label for stored z-String
SUB TX_STR
  tmpW1 = __WPARAM12                            ' get address of string
  DO
    READINC tmpW1, tmpB1                        ' read a character
    IF tmpB1 = 0 THEN EXIT                      ' if 0, string complete
    TX_BYTE tmpB1                               ' send character
  LOOP
  ENDSUB
' -------------------------------------------------------------------------
' Use: TX_BYTE byteVal
' -- transmit "byteVal" at "BaudMode" on pin "RC4"
SUB TX_BYTE
  SEROUT RC4, BaudMode, __PARAM1
  ENDSUB

' -------------------------------------------------------------------------
' Use: TX_STR [noparse][[/noparse]string | label]
' -- "string" is an embedded string constant
' -- "label" is DATA statement label for stored z-String
SUB TX_STR_PC
  tmpW1 = __WPARAM12                            ' get address of string
  DO
    READINC tmpW1, tmpB1                        ' read a character
    IF tmpB1 = 0 THEN EXIT                      ' if 0, string complete
    TX_BYTE_PC tmpB1                            ' send character
  LOOP
ENDSUB
' -------------------------------------------------------------------------
' Use: TX_BYTE_PC byteVal
' -- transmit "byteVal" at "BaudMode" on pin "TX"
' -------------------------------------------------------------------------
SUB TX_BYTE_PC
  SEROUT TX, BaudMode, __PARAM1
ENDSUB
 
' -------------------------------------------------------------------------
' Use: RESET_RC4
' -- resets RC4 to ensure things aren't on that shouldn't be at power up
SUB RESET_RC4
  TX_STR  "!!!!!!RC4"                           ' header (ensure sync)
  TX_BYTE %00                                   ' address
  TX_BYTE "X"                                   ' reset command
ENDSUB
' -------------------------------------------------------------------------
' Use: SET_RC4 relayBits
' -- turns on specified relays ( kegerator will only use one)
SUB SET_RC4
  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!RC4"                                ' header
  TX_BYTE %00                                   ' address
  TX_BYTE "S"                                   ' set command
  TX_BYTE tmpB2                                 ' relay bits
ENDSUB

 

Any Ideas? If I do have to format the data, is it the same routine?

Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe


When all else fails.....procrastinate!

Comments

  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-23 02:17
    How are you connecting to the PC? You're using OT38400 -- if you don't have a pull-up on the line and you're not going through an inverter you may get junk.
  • Shawn LoweShawn Lowe Posts: 635
    edited 2008-08-23 03:08
    Jon-
    I am going through an (efx-tek) serial inverter. I am also going through a usb to serial adapter, and I can see the sx sending data by the led on the usb 2 ser adapter

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-23 04:24
    If you're not powering the serial inverter you need to add a pull-up on your circuit.
  • Shawn LoweShawn Lowe Posts: 635
    edited 2008-08-23 22:00
    Jon/ Everyone:
    I applied 12V power to the inverter, still nothing. I changed from OT38400 to T38400, zip. Should I try N38400?

    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-23 23:39
    Shawn,

    See the attached programs -- both are working when tested with HyperTerminal. I've taken some liberties and updated your code to more efficent routines.

    When using the Serial Inverter you have to power it AND have a pull-up on the TX pin. Also, when defining pins that are OT mode you need to make them an input and then write one to the pin so you don't get a false start.

    You can go directly into the USB-to-Serial converter. You need to change the PC baud mode to N38400, remove the and redefine the pin. I've attached a second version of the program that works that way.

    If you happen to be using a Prop-SX as your controller you can use RA.3 as your TX pin in True mode -- will make connections easier.

    [noparse][[/noparse]Edit] File corrected for SX/B 1.51.03 -- see below.

    Post Edited (JonnyMac) : 8/31/2008 6:02:17 PM GMT
  • Shawn LoweShawn Lowe Posts: 635
    edited 2008-08-31 17:25
    Jon-
    Sorry its taken so long for me to get to this, I really apprieciate your help, but work has been crazy! Anyway, the compiler is having heartache about the TXS_RC4 sub, and I'm not fully aware of what your additions do so I can't tell what it's problem is.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-31 17:59
    Whoops, I was using a newer version of the compiler than you have. Here's a version that works with 1.51.03.
Sign In or Register to comment.