Shop OBEX P1 Docs P2 Docs Learn Events
Applied Sensors DS1620 - Tracy Allen's improvement. — Parallax Forums

Applied Sensors DS1620 - Tracy Allen's improvement.

MichelBMichelB Posts: 154
edited 2009-08-02 17:54 in Accessories
Hi all, I tried to improve DS1620.bs2 according to the code from Tracy Allen's App-notes and I need some answers to the following questions:
i) BS2 tell me "Error 140-Variable modifier is out-of-range." for X.BIT15, ii) "LOOP:" don't appear as "screen:", one is in blue, a PBASIC command expected a DO I suppose, the other in black the begin of a routine, iii) what is "\" in "[noparse][[/noparse]x\9]" and in "REP "-"\degC.BIT15", I can't find it in the help.
P.S.: Code attached was deleted.

Post Edited (MichelB) : 8/1/2009 4:34:35 PM GMT

Comments

  • phil kennyphil kenny Posts: 233
    edited 2009-08-01 15:08
    Replace the first line as follows:

    x     VAR    Word                  ' General purpose variable, byte.
    sign  VAR    X.BIT15               ' Sign bit of x (added).
    



    In order to use VAR X.BIT15, X must be declared as a word, not
    as a byte.

    LOOP is a reserved word and cannot be used as a label. Change
    LOOP to LOOP_1 at the start of your loop and also change GOTO LOOP
    to GOTO LOOP_1.

    You will find that there is another syntax error in:

    DEBUG x SDEC degF                ' Show it as a whole number with sign.
    



    Look up the SHIFTIN command under the Help screen and you will find the answer
    to your question about [noparse][[/noparse]x\9].

    phil

    Post Edited (phil kenny) : 8/1/2009 3:15:58 PM GMT
  • MichelBMichelB Posts: 154
    edited 2009-08-01 16:28
    Thank you Phil, OK for "x VAR Word" I've bad copied this line, for the "loop:" it was that I thought and for "DEBUG ? SDEC degF" I change as DEBUG SDEC degF, CR. The program run well now but the display of degC is wrong, "=" is followed by a small "square·. 0". In my humble opinion and with great respect, Mr Tracy Allen must revisit this program. Herewith attached DS1620-01.bs2






    Post Edited (MichelB) : 8/1/2009 4:36:02 PM GMT
  • phil kennyphil kenny Posts: 233
    edited 2009-08-01 17:56
    The DS1620 code listed on Tracy Allen's web site was written for
    an earlier version of PBASIC, most likely version 2.0

    You are running PBASIC version 2.5. A number of changes were made
    in version 2.5 that cause problems with Tracy's original code. The
    syntax errors you encountered were a resullt of these changes.

    Try changing your program as follows:

    old code:
    DEBUG "degC=", REP "-"\degC.BIT15, ABS degC/10, ".", DEC1 ABS degC, CR
    



    new code:
    DEBUG "degC = ", DEC degC/10, ".", DEC1  degC, CR
    



    I don't have a DS1620 to try it with, but it should work for temperatures of
    0 deg C and above and will get you started.

    phil

    Post Edited (phil kenny) : 8/1/2009 6:08:53 PM GMT
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2009-08-02 00:00
    Sorry about that Michel. That page on my web site comes from 1999 when I was working on the Earth Measurements text for Stamps in Class and at that time it was still PBASIC 1.x and some people were still even using the DOS version of the editor. (The Stamps in Class version was later edited by Parallax and brought up to date for PBASIC 2.5 under the new title of Applied Sensors.)

    Anyway, I have not updated the code on the web page, and as you have discovered, it does not compile under PBASIC 2.5. The things that need to be changed are the use of LOOP as a label, and the addition of the {$STAMP BS2} and the {$PBASIC 2.5} directives, and the DEBUG ? SDEC degF. Good catch on that last one. DEBUB ? degF is good syntax, but not with the SDEC. Here is is with those changes, using a DO:LOOP instead of a GOTO. In early versions of PBASIC, there was no DO:LOOP. I threw in the full conversion and display of Fahrenheit with the decimal point. I don't know why you are seeing a small circle after the degC= on the display. The purpose of REP "-"\degC.bit15 is to display a negative sign only if the temperature is negative. That is allowable syntax for any version of PBASIC.

    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    
       x    VAR WORD  ' define a general purpose variable
        sign VAR x.BIT15  ' sign bit of x
        degC VAR WORD  ' define a variable to hold degrees Celsius
        degF VAR WORD  ' to hold degrees Fahrenheit
           ' note: DS1620 has been preprogrammed once
           ' for mode 2: continuous conversions, with CPU
           ' high 13   ' start
           ' shiftout 15,14,lsbfirst,[noparse][[/noparse]12,2]  ' set mode 2
           ' low 13    ' stop
        OUTS=%0000000000000000 ' define the initial state of all pins
             'fedcba9876543210
        DIRS=%1111111111111111 ' as low outputs
           
        HIGH 13                         ' select the DS1620
        SHIFTOUT 15,14,LSBFIRST,[noparse][[/noparse]238]   ' "start conversions" command
        LOW 13                          ' do the command
        DO                          ' going to loop once per second
          HIGH 13                       ' select the DS1620
          SHIFTOUT 15,14,LSBFIRST,[noparse][[/noparse]170] ' send the "get data" command
          SHIFTIN 15,14,LSBPRE,[noparse][[/noparse]x\9]    ' get the data, including sign
          LOW 13                        ' end the command
          x.BYTE1 = -x.BIT8             ' extend the sign to 16 bits
          degC=x*5                      ' convert to 'C*10 (resolution 0.5 'C)
                                        ' & show the result on the PC screen:
          DEBUG "degC=", REP "-"\degC.BIT15, DEC ABS degC/10, ".", DEC1 ABS degC, CR
          degF= degC+2732*9/5-4598      ' 'C*10 to 'F (first to Kelvin*10)
          DEBUG "degF=", REP "-"\degF.BIT15, DEC ABS degF/10,".", DEC1 ABS degF, CR
          PAUSE 1000                    ' 1 second pause
        LOOP                      ' read & display temperature again
    



    edit: added the DEC format modifier in the DEBUG statement for degF. Also capitalization per PBASIC 2.5

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 8/2/2009 5:42:17 PM GMT
  • MichelBMichelB Posts: 154
    edited 2009-08-02 09:39
    Dear Tracy, thank you (and Phil) for your prompt reply. I've modified the code as written and got bad result. Please find herewith attached i) a file .doc showing result with DS1620.bs2 from Applied Sensors and result with your code, ii) DS1620-01.bs2, your code, so you can run it and see where default is. Thank you again, sorry for disturbance and best regards. MichelB
  • phil kennyphil kenny Posts: 233
    edited 2009-08-02 15:32
    The problem seems to be the lack of any format specification in the
    DEBUG command lines.

    If you change your code from

    ' Lines added.
      DEBUG "degC=", REP "-"\degC.BIT15, ABS degC/10, ".", DEC1 ABS degC, CR
      degF = degC+2732*9/5-4598        ' C*10 to F (first to Kelvin*10).
      DEBUG "degF=", REP "-"\degF.BIT15, ABS degF/10, ".", DEC1 ABS degF, CR
    
    



    to

    ' Lines added.
      DEBUG "degC = ", REP "-"\degC.BIT15, [b]DEC[/b] ABS degC/10, ".", DEC1 ABS degC, CR
    '                                      ^^^ 
      degF = degC+2732*9/5-4598        ' C*10 to F (first to Kelvin*10).
    
      DEBUG "degF = ", REP "-"\degF.BIT15, [b]DEC[/b] ABS degF/10, ".", DEC1 ABS degF, CR
    '                                      ^^^ 
    
    



    it will display properly. The DEBUG statement seems to need a formatting
    command. In the case DEC will give proper formatting.

    phil

    Post Edited (phil kenny) : 8/2/2009 3:46:51 PM GMT
  • MichelBMichelB Posts: 154
    edited 2009-08-02 16:24
    Yes my dear Phil, you are a great "Monsieur". Now it runs very well. I'll try to "snip" it in activities of Applied Sensors as it's asked by Tracy Allen as a challenge at the end of page 21 in this book. Thank you again and best regards. MichelB·
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2009-08-02 17:54
    Good catch Phil. I went in and updated that web page to PBASIC 2.5.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.