Shop OBEX P1 Docs P2 Docs Learn Events
Errors in publications. — Parallax Forums

Errors in publications.

I would like to thank all who responded in helping me understand the spin code. The Book "Programming and customizing the multicore PROPELLER microcntroller."
The book on page 140 has a typo in the code on page 140. The statement "rc.time(18, 1, @tDecay)" should be "rc.rctime(18, 1, @tDeacy)". I never would have figured
it out by my self. I take apart the program to try to figure out how it works?? But if I can not get it to work? I cannot play with it! I Smile-umed the code would be error free. I have it running now and can move on to the next program. I am sure parallax try's to publish a good a book as they can. But a typo for someone like myself who has not a clue what is going on can stop me dead in my tracks. Thanks for the support good people of forum. 16 feb 2019(sat)

Comments

  • PublisonPublison Posts: 12,366
    edited 2019-02-16 17:28
    You might have mis typed this line
    PUB Go | tDecay
    

    I( ran the code from the book and seems to compile OK.
  • You can download code from here:
    https://www.dropbox.com/s/qo8swwt9fanj0sf/Propeller Book.zip?dl=0

    You need a free login registration.
  • @Iguanaman, welcome to the forum. I would have quit a long time ago if there was no forum!
    I want to add one thing: In my opinion, one of the best learning tools is the "Propeller Education Kit" PDF which you can find in the Propeller tool under the HELP tab. You can start at chapter four. It will give you a solid understanding of Spin programming.
  • GenetixGenetix Posts: 1,754
    edited 2019-02-16 23:55
    Iguanaman,

    The program is correct.

    Look at page 141 of the Propeller Manual for OBJ or the object block declaration.
    https://www.parallax.com/sites/default/files/downloads/P8X32A-Web-PropellerManual-v1.2.pdf
    {{
    ┌──────────────────────────────────────────┐
    │ Test Simple RCTIME.spin v1.0             │
    │ Author: Andy Lindsay                     │               
    │ Copyright (c) 2010 Parallax Incorporated │               
    │ See end of file for terms of use.        │                
    └──────────────────────────────────────────┘
    }}
    
    CON
       
      _clkmode = xtal1 + pll16x         ' Crystal and PLL settings.
      _xinfreq = 5_000_000              ' 5 MHz crystal x 16 = 80 MHz
    
    OBJ
    
    ' Symbol  : ObjectName ********** This comment was added *****
      rc  : "RC Time"                   ' RC decay/growth object
      pst : "Parallax Serial Terminal"  ' Serial communication object
             
    PUB Go | tDecay
    
      pst.Start(115200)                 ' Start Parallax Serial Terminal
    
      repeat                            ' Repeat loop
        waitcnt(clkfreq/10 + cnt)       ' Refresh display at 10 Hz
    
        rc.time(18, 1, @tDecay)         ' Measure P17 decay circuit
    
        ' Display measurement
        pst.Str(String(pst#CE, pst#HM, "tDecay = "))             
        pst.Dec(tDecay)
    
    DAT
    {{
    ┌───────────────────────────────────────────────────────────────────────────┐
    │                    TERMS OF USE: MIT License                              │     
    ├───────────────────────────────────────────────────────────────────────────┤
    │Permission is hereby granted, free of charge, to any person obtaining      │
    │a copy of this software and associated documentationfiles (the             │
    │"Software"), to deal in the Software without restriction, including        │
    │without limitation the rights to use, copy, modify, merge, publish,        │
    │distribute, sublicense, and/or sell copies of the Software, and to         │
    │permit persons to whom the Software is furnished to do so, subject to      │
    │the following conditions:                                                  │     
    │                                                                           │     
    │The above copyright notice and this permission notice shall be included    │
    │in all copies or substantial portions of the Software.                     │
    │                                                                           │      
    │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS    │
    │OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,│
    │FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    │
    │THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER │
    │LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    │
    │FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        │
    │DEALINGS IN THE SOFTWARE.                                                  │
    └───────────────────────────────────────────────────────────────────────────┘
    }}
    
    Also if you look at the RCtime object you will see that there is PUBlic method called Time.
    Public means that an outside object can call that method, while PRIvate methods can only be called within the same object.
    {{
    ────────────────────────────────────────────────────────────────────────────────────────
    File: RC Time.spin
    Version: 0.66
    Date: 2010.01.20
    Author: Andy Lindsay
    Copyright (c) 2009 Parallax Incorporated  See end of file for terms of use.
    
    Resource Documents and Code Examples
    
      "MeasureTime.zip" contains:
         
         - "Documentation.MeasureTime.Spin" has information about RC decay measurements
            and examples of using this object's methods in application code.
    
         - "MeasureTime.zip" three example programs that use this object to take RC decay
           measurements.  The measurements are displayed in the Parallax Serial Terminal.
    
    To-Do List:
      • Add PULSIN
      • Add Duty Cycle  
        
    ────────────────────────────────────────────────────────────────────────────────────────
    }}
    
    CON
    
      SEQUENTIAL      = 0                                ' Mode constants
      PARALLEL        = 1
      REPEATED        = 2
      CHARGE_TIME     = 2
      TIME_OUT        = 3
      SAMPLE_INTERVAL = 5
      CONFIG_MODE     = 6
    
    VAR
    
      long cog, tI, TC, mode, params[6], stack[40], repetitions
    
    PUB Start(pin, state, chargeTimeTicks, timeOutTicks, sampleTicks, resultAddr) : repsAddr
    {{Start process that repeatedly takes RC measurements at a sampling rate.
      - pin..............the pin to take RC measurements on
      - state............starting state of the measurement.
                         1 -> decay, 0 -> growth
      - chargeTimeTicks..Clock ticks for charging (or discharging) the circuit.
                         Minimum 2775 clock ticks.
      - timeOutTicks.....Clock ticks elapsed before the measurement times out.
      - sampleTicks......Number of ticks in the sample interval.  Must be at least
                         chargeTimeTicks + timeOutTicks + 5000
      - resultAddr.......Address of the variable that stores the latest RC
                         measurement result
      - repsAddr.........Returns the address of the variable that stores the current
                         measurement number, or 0 if the cog failed to launch.
    }}
      stop                                          ' Stop the cog if it's already running
      mode:=REPEATED                                ' Set mode to 2
      ChargeTime(chargeTimeTicks)
      TimeOut(timeOutTicks)
      SamplingInterval(sampleTicks)
      cog := cognew(MeasureLoop(pin, state, resultAddr), @stack) + 1  ' Launch the cog 
      if cog                                                          ' Return 0 or address of
        repsAddr := @repetitions                                      ' repetitions variable
      
    PUB Stop
      '' Stops RC decay measurements - frees a cog
      if cog                                        ' If cog is running
        cogstop(cog~ - 1)                           ' Stop the cog and clear cog
      mode := 0
    
    PUB SetMode(value)                              ''Configure mode
      mode := value                                 ''  value = #SEQUENTIAL or #PARALLEL
    
    PUB ChargeTime(ticks)                           ''Configure charge time
      params[CHARGE_TIME] := ticks #> 2775          ''  ticks - Charge time in clock ticks
                                                    ''  must be at least 2775 ticks 
    PUB TimeOut(ticks)                              ''Configure timeout
      params[TIME_OUT] := ticks                     ''  ticks - Timeout in clock ticks
    
    ''NOTE: This timeout value is not precise.  For a precise timeout, use MeasereTime.ASM
    ''      instead.
    
    PUB Time(pin, state, resultAddr) : done           ''RC Time Measurement
    ' ********** This is the method that the demo program is calling **********
    {{Measures growth/decay time.
      - pin..............the pin to take RC measurements on
      - state............starting state of the measurement.
                         1 -> decay, 0 -> growth
      - resultAddr.......Address of the variable that stores the latest RC
                         measurement result
      - done.............sequential mode - same as measurement
                         parallel mode   - 0 if failed to launch a cog
                                         - nonzero if success
    NOTES:
      1) The charge time defaults to 0.1 ms, and the timeout to 10 ms.  You
         can change these values by calling the ChargeTime and TimeOut methods.
      2) Mode defaults to SEQUENTIAL, so this method waits for the measurement to
         finish.  If you instead want to take parallel measurements or have the
         parent object's code move on and check for the result later, use the
         Mode method and set to PARALLEL.  Example - time.Mode(time#PARALLEL).                    
    }}
      if params[CHARGE_TIME]==0                     ' Check charge time
        ChargeTime(clkfreq/10_000)                  ' if zero, then set to default
      if params[TIME_OUT] == 0                      ' Check timeout               
        TimeOut(clkfreq/100)                        ' if zero, then set to default    
      case mode                                     ' check mode
        SEQUENTIAL:                                 ' If sequential
          measure(pin, state, resultAddr)           '   call measure
          done := long[resultAddr]                  '   return done = measurement
        PARALLEL:                                   ' if parallel, return done <> 0 if cog
          done := (cog := cognew(measure(pin, state, resultAddr), @stack) + 1)
    
    PRI measure(pin, state, resultAddr) | t, temp
      ' RC Decay Measurement
      ' For insights into how this code works, see the Counter Modules and Circuit
      ' Applications Lab in Propeller Education Kit Labs: Fundamentals book.
      case state                                    ' Set to measure decay or rise
        1: ctra[30..26] := %01000
        0: ctra[30..26] := %01100                     
      ctra[5..0] := pin                             ' Configure counter module
      frqa := 1                                  
      tI := cnt                                     ' Mark current time
      tC := tI + params[CHARGE_TIME]                ' Calculate charge time
      outa[pin] := state                            ' Configure I/O pin
      dira[pin]~~
      waitcnt(tC)                                   ' Wait for charge
      phsa~                                         ' Clear phase accumulator
      dira[pin]:=0                                  ' Set I/O pin to input
      ' Wait for either timeout or change in state
      repeat until cnt-tC => params[TIME_OUT] OR ina[pin] <> state
      ' Fix interpreted code overhead in result and store at variable address
      long[resultAddr]:=(phsa-588)#>0
      if mode == PARALLEL                           ' If Parallel mode
        cogstop(cogid)                              ' Cog self-stops
    
    PRI MeasureLoop(pin, state, resultAddr) | t, dt
      ' This method gets called if by the start method for repeated measurements at a given
      ' sampling rate.
      t:= cnt                                       ' Mark current time
      repeat
        measure(pin, state, resultAddr)             ' Measure RC decay
        repetitions++
        waitcnt(t+=params[SAMPLE_INTERVAL])
    
    PRI SamplingInterval(value)                     ''Set sampling interval
                                                    ''  ticks - Sample interval in clock ticks
      params[SAMPLE_INTERVAL]:= value #> (params[CHARGE_TIME] + params[TIME_OUT] + 25_000)
                                                    ''  Should be at least
                                                    ''    charge time + timeout + 25000
    DAT
    {{
    ┌──────────────────────────────────────────────────────────────────────────────────────┐
    │                           TERMS OF USE: MIT License                                  │  
    ├──────────────────────────────────────────────────────────────────────────────────────┤
    │Permission is hereby granted, free of charge, to any person obtaining a copy of this  │
    │software and associated documentation files (the "Software"), to deal in the Software │ 
    │without restriction, including without limitation the rights to use, copy, modify,    │
    │merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    │
    │permit persons to whom the Software is furnished to do so, subject to the following   │
    │conditions:                                                                           │  
    │                                                                                      │  
    │The above copyright notice and this permission notice shall be included in all copies │
    │or substantial portions of the Software.                                              │
    │                                                                                      │  
    │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   │
    │INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         │
    │PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    │
    │HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION     │
    │OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE        │
    │SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                │
    └──────────────────────────────────────────────────────────────────────────────────────┘
    }}
    
Sign In or Register to comment.