Shop OBEX P1 Docs P2 Docs Learn Events
Process Control, Activity 2 — Parallax Forums

Process Control, Activity 2

ocean billocean bill Posts: 15
edited 2011-10-25 07:37 in Learn with BlocklyProp
Hi All,
StampPlot is not plotting or receiving data for Activity 2, Chapter 6. I successfully plotted Activity 1. Activity 2 uses the same circuit (Fig-1). I loaded the program AdcSpanOffset.bs2 and used the macro sic_pc_adc_span_offset.spm and StampPlot Pro V3_7.

I performed the following sequence:
1. Loaded and ran AdcSpanOffset.bs2
2. Closed Debugger
3. Verified "ADC Span" is set to 5 and ADC Offset' is set to 0 in StampPlot
4. Pressed connect and plot in StampPlot

The lower left "T' turned to green, but the "R" did not flash red as in Activity 1. No plotting occurred.

I checked and double checked my circuit wiring and the code after cut & paste as shown below:
' -----[ Title ]-----------------------------------------------------------
' Process Control - AdcSpanOffset.bs2
' Tests the spanning and offset input range of the ADC 0831 using PWM
' {$STAMP BS2}
' {$PBASIC 2.5}

' -----[ Declarations ]----------------------------------------------------
ADC_ByteValue VAR Byte    ' Analog to Digital Converter data
V_Offset      VAR Byte    ' Offset voltage read from StampPlot
V_Span        VAR Byte    ' Span voltage read from StampPlot
TempF         VAR Word    ' Calculated temp in hundredths of degree F

ADC_CS        PIN 13      ' ADC Chip Select pin
ADC_Clk       PIN 14      ' ADC Clock pin
ADC_Dout      PIN 15      ' ADC Data output

ADC_VRef      PIN 10      ' Pin for PWM to set ADC voltage span
ADC_Vminus    PIN 11      ' Pin for PWM to set ADC Offset

' -----[ Initialization ]--------------------------------------------------
PAUSE 1000                ' Allow connection stabilization

' -----[ Main Routine ]----------------------------------------------------
DO
  GOSUB ReadSP
  GOSUB SetADC
  GOSUB ReadADC
  GOSUB CalcTemp
  GOSUB UpdateSP
  GOSUB PlotPoint
  PAUSE 100
LOOP

' -----[ Subroutines ]-----------------------------------------------------
ReadSP:
  DEBUG CR,"!READ [(txtADCoffset),*,10]",CR   ' obtain offset volt. in tenths
  DEBUGIN DEC V_Offset
  PAUSE 50
  DEBUG "!READ [(txtADCspan),*,10]",CR        ' obtain span voltage in tenths
  DEBUGIN DEC V_Span
  PAUSE 50
  RETURN

SetADC:
  PWM ADC_Vminus, V_Offset * 255/50,100       ' Apply PWM to set offset volt.
  PWM ADC_Vref, V_Span * 255/50,100           ' Apply PWM to set span voltage
  RETURN

ReadADC:                                               ' Read ADC 0831
  LOW ADC_CS                                           ' Enable chip
  SHIFTIN ADC_Dout, ADC_Clk, MSBPOST,[ADC_ByteValue\9] ' Clock in ADC data
  HIGH ADC_CS                                          ' Disable ADC
  RETURN

CalcTemp: ' y = mx + b
          ' where y=temp,
          ' m = (change in output)/(change in input) = voltage Span/255
          ' x = ADC value read, b = offset, y = temperature in hundredths
          ' temperature = (Span/255)Byte + Offset
  TempF = (V_Span * 1000)/255 * ADC_ByteValue + (V_Offset * 1000)
  RETURN

UpdateSP:
  DEBUG "!O txtByteBin = ", BIN8 ADC_ByteValue,CR, ' Update w/ binary ADC val
        "!O txtByte = ", DEC ADC_ByteValue,CR      ' Update w/ decimal ADC val
  DEBUG "!O txtTemp = [", DEC TempF,",/,100]",CR   ' Update w/ temperature/100
  RETURN

PlotPoint:
  DEBUG "!FCIR (txtByte),(txtTemp),0.3A,(WHITE)",CR ' Plot white circle at
  PAUSE 100                                         ' byte, Temp as X,Y
  DEBUG "!FCIR ,,,(BLUE)",CR                        ' Plot again in blue
  RETURN

Thanks for taking the time to look at this. Any help is appreciated.
Ocean Bill

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2011-10-20 13:59
    I took the liberty of putting CODE tags around your code to make it more readable for those trying to help you.
  • ocean billocean bill Posts: 15
    edited 2011-10-21 12:46
    Thanks sylvie369. That does indeed make it more functional.
  • ocean billocean bill Posts: 15
    edited 2011-10-21 12:54
    To further clarify, I am using the downloadable "Process Control Text.pdf": http://www.parallax.com/Portals/0/Downloads/docs/prod/sic/Web-PC-v1.0.pdf
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2011-10-23 11:06
    If you see the TX light blink, but get no Rx coming back, it may need a code tweak - DEBUGIN can cause issues sometimes if it misses data, there is no timeout. Try replacing the READSP routine with one using SERIN instead (you can also try hitting reset a couple times on the BASIC Stamp, helps sometimes).
    ReadSP:
      DEBUG CR,"!READ [(txtADCoffset),*,10]",CR   ' obtain offset volt. in tenths
      SERIN 16,84,100,Timeout,[DEC V_Offset]
      PAUSE 50
      DEBUG "!READ [(txtADCspan),*,10]",CR        ' obtain span voltage in tenths
      SERIN 16,84,100,Timeout,[ DEC V_Span]
      PAUSE 50
    Timeout:
      RETURN
    

    Give it a shot, let me know how it goes,
    -Martin
  • ocean billocean bill Posts: 15
    edited 2011-10-24 09:57
    Thank you Martin!
    That bit of code did the trick and StampPlot is receiving and plotting data. I suppose as computer processing gets faster and faster, adjustments have to be made from when the original code was written.
    Ocean Bill
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2011-10-25 07:37
    Glad to hear it worked for you, thanks for the update.
Sign In or Register to comment.