Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic help with PST and formating help — Parallax Forums

PropBasic help with PST and formating help

$WMc%$WMc% Posts: 1,884
edited 2011-07-31 11:42 in Propeller 1
Hello All
'
I wrote a little code in PropBasic to read the ADC0831. (I need to read a 0-5volt signal.)
'
The problem I'm haven is the formating to send to the PST window in PropBasic.
'
All I get is a bunch of hieroglyphics in the PST window. I thought I had this down-pat, But its not working.
'
If I use the bst terminal set to HEX$, I get some reasonable values. But set to ASCII I get the hieroglyphics.
'
I would like to read the voltage as a DEC. If it's 2.5volts, I'd like to see 2.5volts on the PST.
'
Heres my code. Any help would be great.
'
This is a test-bed code. I will tweak it if needed.
'
PS. The coding config. is right out of the StampWorks manuel.

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2011-07-30 03:23
    HI Walt,

    your code sends the raw bytes that contain the ADC-information.
    I don't have a ADC0831-datasheet handy. So I can't say what the raw data is.
    The raw data has to be transformed into decimal value and then into a ASCII-coded value. This means each digit 0-9 has to be transformed to ASCII-code through adding the value 48
    If the raw data is already an binary value that directly can be used this transforming is obsolete.

    In the FullDuplexSerialObject is an example-code in SPIN how to do this.
    PUB dec(value) | i, x
    
    '' Print a decimal number
    
      x := value == NEGX                                                            'Check for max negative
      if value < 0
        value := ||(value+x)                                                        'If negative, make positive; adjust for max negative
        tx("-")                                                                     'and output sign
    
      i := 1_000_000_000                                                            'Initialize divisor
    
      repeat 10                                                                     'Loop for 10 digits
        if value => i                                                               
          tx(value / i + "0" + x*(i == 1))                                          'If non-zero digit, output digit; adjust for max negative
          value //= i                                                               'and digit from value
          result~~                                                                  'flag non-zero found
        elseif result or i == 1
          tx("0")                                                                   'If zero digit (or only digit) output it
        i /= 10                                                                     'Update divisor 
    

    the basic principle is to do an integer division by
    1_000_000_000
      100_000_000
       10_000_000
        1_000_000
          100_000
           10_000
            1_000
              100
               10
                1 
    
    to get always the most siginficant digit that is not yet transmitted
    than add value 48 (which can be done as adding + "0" which the compiler translates to + 48
    and then send the byte.

    if the raw data isn't already the decimal value please provide a datasheet how the raw data is encoded

    keep the questions coming
    best regards

    Stefan
  • $WMc%$WMc% Posts: 1,884
    edited 2011-07-30 08:59
    Thanks Stefan
    '
    I thought the incoming stream would all ready be formated.I was thinking of SERIN and not SHIFTIN.Thanks for pointing this out.
    '
    I'll try to convert this to ascii. I'll be back later.
    '
    Thanks again

    link to data sheet ADC0831
    http://www.mouser.com/ProductDetail/Parallax/ADC0831/?qs=%252b86TLfaev29O4m%2fCJ3Pe9A%3d%3d
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-07-30 13:25
    Hi Walt,

    I'm answering here in the forum that the community can benefit from teh answer.

    I don't know details about pro-basic. I assume that shiftin has parameters to determine different amounts of bits and maybe using a clock-pin.
    I assume serin uses parameters more fixed to a certain serial protocol like 8 databits, baudrate, 1 stopbit or something similar.

    The basic principle of both is the same: transmitting data serial.

    Now to get this working in prop-basic take a look into one of the ADC0831 objects in the obex.

    Guiding questions:
    How can objects be found that are about the ADC0831?

    what will be easier to read and understand SPIN or PASM?

    what will be the name of the subroutine that reads in the ADC-value?

    Take a look into that routine
    analyse codeline for codeline what the code does
    translate the functionality of the code into prop-basic

    To make it work in prop-basic.

    Use one of the SPIN-objects to read-in the ADC-value of a fixed voltage-divider from a stabilised voltage-supply.

    Code your prop-basic-routine until it reads in the same value.

    About ASCII-coding:

    write a small SPIN-code that receive single bytes. Send ASCII-coded digits 0..9 with PST.EXE to the prop.
    The propeller must echo back the values which the propeller has received.

    send some "0" and take a look at the echoed back value
    send some "1" and take a look at the echoed back value
    ...
    send some "9" and take a look at the echoed back value

    and you will easily recognise how the coding is done.

    This an answer that avoids consequent direct answering. I don't serve you fried fish. I'm teaching fishing. Because I want you to learn to fish.

    best regards

    Stefan

    by the way what does
    ABB M202 certified
    ABB M211 certified
    mean?

    Asea Brown Bovery certification? If yes certfication in programming? which language?
  • $WMc%$WMc% Posts: 1,884
    edited 2011-07-30 15:45
    Stefen
    '
    Thanks for the reply.
    '
    I have learned how to fish. I have caught some fish.Now I need to now how to cook some fish?
    '
    Its making the compiler happy that I'm struggling with now.
    '
    P.S. ABB M202 and M211 are programing and hardware courses for an ABB DCS system using FBP.This is a function block programming environment.
    '
    This is really a Bailey DCS. ABB bought Bailey and they put their name on the technology.Take a look at Bailey Infi 90
    '
    I need help with cooking fish?
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-07-30 22:40
    Hi Walt,
    now that's a good answer. Just like me mentioning some key-acronyms instead of explaining all the details about ABB

    OK I took it:
    Googling Baily INfi 90: a word by word translation would be "process guiding system"
    googling "DCS": distributed controlled system
    "FBP" Field Bus Plug. If I understand right a mechanical standard how to connect FieldBus-devices with the fieldbus cable. (Profibus etc)

    OK back to the main theme of the thread.
    I'm not sure how I have to understand your question "I need help with cooking fish?" As a statement I would understand it that way

    I'm able to program in SPIN (frying fish) But now I need help programming in PropBasic (cooking fish)

    Now the sentences above are an example of "doing your homework" trying to looking up things in the internet yourself what they mean. If something is interpretable
    writing one or more interpretations asking which one is right.

    In relation with reading the ADC0831-chip looking up how the command shiftin and serin work
    I haven't worked anything with propbasic.
    So I just downloaded the manual and read
    SHIFTIN
    SPI input.
    SHIFTIN datapin, clockpin, mode, var[\bits][,speed]
    If the bits parameter is not specified, 8 bits are received.
    mode: LSBPRE, LSBPOST, MSBPRE, MSBPOST

    SERIN
    Serial input. Prefix baud value "T" for true mode, "N" for inverted mode.

    If SERIN times-out var is not changed. If label is not specified execution continues with the next line of code.
    If "var" is a string, characters are stored until a carrage return is received, timeout is only in effect until the first
    character is received.

    SERIN pin, baud, var {, timeoutms{, label}}

    now your homework in this case is
    reading the datasheet of the ADC0831. If something confuses you attaching the datasheet directly to your actual posting
    (not only a link to a download. You want freeware help and therefore you should make it comfortable for forum-members to answer by providing a direct download)

    quoting the datasheet with a question like: "do I understand right that ....?"

    Same thing with all my other guiding questions.

    keep the concrete questions coming
    best regards

    Stefan
  • BeanBean Posts: 8,129
    edited 2011-07-31 10:41
    Walt,
    You need to convert the value to a ascii string by using the STR function.
    ASCII HUB STRING(4)
    
    ASCII = STR info, 4
    PSTStr ASCII
    

    Bean
  • $WMc%$WMc% Posts: 1,884
    edited 2011-07-31 11:42
    Bean
    ''
    Many Thanks.This fixed it.
    '
    I was leaving STR out of "ascii = STR info, 116" so the compiler kept giving me errors.
    '
    I couldn't figure out what I was doing wrong.So then I started over thinking it, looking for formating issues, etc., Instead of looking for a typo.
    '
    '
    Thanks again
    '
    Thanks for PropBasic.
Sign In or Register to comment.