Shop OBEX P1 Docs P2 Docs Learn Events
Do I have a corrupted memory block? — Parallax Forums

Do I have a corrupted memory block?

turbosupraturbosupra Posts: 1,088
edited 2012-02-23 15:50 in Propeller 1
Ok, after 3 hours of banging my head against the desk, I figured out if I used result := @adc1Result, I get the first screen capture, but if I use result := @adc2Result it works as shown in the second screen capture, that is the only change I'm making. Do I have a corrupted memory block on my protoboard? I'm sorry I can't attach the objects, but the work firewall blocks that.

Also, how can I concatenate this line s2.Concatenate(result, string(ch)) ?

  { Have methods
        1. collect adc data, format it, save it to globlal variable
        2. send global variable values in formated type over serial/method also receives serial data and decodes/updates global variables

  }

CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
  CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq  
  MS_001   = CLK_FREQ / 1_000

  
con

  #1, HOME, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR, #16, CLS      ' PST formmatting control


con

  RX1 = 31
  TX1 = 30
  SDA = 29
  SCL = 28

  CS  =  7
  CLK =  8
  DIO =  9
 

VAR

long numerator
long denominator
long constantMultiplier 
long additionAnswer
long subtractionAnswer
long multiplicationAnswer
long divisionAnswer
long adc1Result2

long captureAnalogData1Stack[20]

Byte adc1Result[128] 
Byte adc2Result[128]
Byte string1value[128]





OBJ
'pst : "Parallax Serial Terminal"
strings : "Strings"
s2 : "Strings2"
f : "Float32"
fm : "FloatMath"
fs : "FloatString"
term: "FullDuplexSerial"
adc  : "jm_mcp3208_ez"


PUB Main   

  term.start(RX1, TX1, %0000, 115_200)
  cognew(captureAnalogData1, @captureAnalogData1Stack)

  term.str(string("Starting"))
    term.str(String(13))
  repeat

    
    waitcnt(clkfreq + cnt)


PUB captureAnalogData1 | t, ch, analog, adcNumber, localIndex, zresult 

  adcNumber := 1
  localIndex := 0
  adc.init(CS, CLK, DIO)                                        ' start adc driver
  
  waitcnt(MS_001 + cnt)                                         ' let objects load

  t := cnt

  repeat

    localIndex := 0

        
    repeat ch from 0 to 7
      {term.str(string("ch")) 
      term.dec(ch)                                              ' display channel #
      term.str(string(": "))
      term.dec(adc.read(ch, adc#SE))                            ' display channel value
      term.tx(CLREOL)
      term.tx(CR)
      term.dec(adcNumber)
      term.str(string("-"))
      term.dec(ch)
      term.str(string(":"))
      term.dec(adc.read(ch, adc#SE))
      term.str(String(13)) }   

      adc1Result~
      adc2Result~
      result := @adc1Result
      s2.Concatenate(result, string("1"))
      s2.Concatenate(result, string("-"))   
      's2.Concatenate(result, string(ch))
      s2.Concatenate(result, string(":"))
     
      term.str(string("adc2Result is: "))
      term.str(result)
      term.str(String(13)) 
      'result := (adcNumber) + (string("-")) + ch + (string(":")) + (adc.read(ch, adc#SE)) 
      
      
      term.str(String(13))
      term.str(String(13))
      waitcnt(t += constant(MS_001 * 500))
      
    waitcnt(t += constant(MS_001 * 500))                        ' update every 100ms      




corruptedprop1.png


corruptedprop2.png

Comments

  • turbosupraturbosupra Posts: 1,088
    edited 2012-02-23 14:44
    I can also change the variable portion of the code (see bolded part) to the below and it works correctly as shown in the screen capture below
    VAR
    
    long numerator
    long denominator
    long constantMultiplier 
    long additionAnswer
    long subtractionAnswer
    long multiplicationAnswer
    long divisionAnswer
    long adc1Result2
    
    long captureAnalogData1Stack[20]
    [b]Byte placeHolder[128][/b]
    Byte adc1Result[128] 
    Byte adc2Result[128]
    Byte string1value[128]
    
    


    corruptedprop3.png
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-23 15:15
    Try making your stack bigger. Twenty longs may be a bit skimpy.

    -Phil
  • turbosupraturbosupra Posts: 1,088
    edited 2012-02-23 15:26
    I answered my own question about the string conversion

    Thanks Phil, that did it! What do you usually set your stacks for?


    Try making your stack bigger. Twenty longs may be a bit skimpy.

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2012-02-23 15:38
    You can always make the placeholder just a single byte, then in your code add a line to display the placeholder value. Init the byte to some value, then if it is getting changed you know that your stack is too small and the next slot is getting used.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-23 15:50
    I bet the concatenate method needs the strings to end with zero. The arrays will only be all zeros the first time through the loop.
    adc1Result~
          adc2Result~
    

    Will only clear the first element of the array.

    You should use:
    bytefill(@adc1Result, 0, 128)
          bytefill(@adc2Result, 0, 128)
    

    to clear the arrays.
Sign In or Register to comment.