Stamp-O-Scope display Chapter 5 Parallax book: Basic Analog and Digital 1.3 version
Keith Hilton
Posts: 150
in BASIC Stamp
I can not get my Stamp-O-Scope to work. I am referring to Chapter 5 Parallax book: Basic Analog and Digital 1.3 version. As the text said, I changed the code of the Program Listing 4.1 to the code changes listed on pages 91 and 91 of the book. The code ran, but I did not have a triangle wave form. I had a row of dots up the Debug display on the left side. I know my circuit is correct, because it ran with the circuit on page 83--Figure 4-8, D/A Circuit with a buffer. What is extremely confusing is this: On page 92 it says to modify the Display subroutine to look like this:
Display:
v3 = adcBits / 8
DEBUG REP " "\v3, "*", CR
RETURN
Then in the book when they start explaining the code on page 96 they have something totally different for the Display. Here is what is on page 96.
Display:
DEBUG REP " "\adcBits/4, "*", CR
RETURN
I tried running the code Display both ways, and neither way displayed the triangle wave form. I want to find out what I am doing wrong, and get a triangle wave form on my Debug display. Here is my code below. My circuit is exactly the same as the circuit diagram on page 83.
' {$STAMP BS2}
' {$PBASIC 2.5}
'Basic Analog and Digital--PL5_1R0,bs2
'Digital Voltmeter (DVM) . D/A Converter Added
'
[Declarations]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte
n VAR Nib
'
[ Initialization ]
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS
'Start display.
DO
FOR n = 7 TO 15
GOSUB Main
NEXT
FOR n = 14 TO 8
GOSUB Main
NEXT
LOOP
'
[ Main Routine ]
Main:
GOSUB DAC
GOSUB ADC_Data
'GOSUB Calc_Volts
GOSUB Display
RETURN
'
[ Subroutines ]
DAC:
DIRB = 15
OUTB = n
PAUSE 50
RETURN
ADC_Data:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8]
RETURN
Calc_Volts:
v = 5 * adcBits/ 255
r = 5 * adcBits // 255
v2 = 100 * R / 255
v3 = 100 * R // 255
v3 = 10 * v3 /255
IF (v3 >= 5) THEN v2 = v2 +1
IF (v2 >= 100) THEN
v = v + 1
v2 = 0
ENDIF
RETURN
Display:
v3 = adcBits / 8
DEBUG REP " "\v3, "*", CR
RETURN
Display:
v3 = adcBits / 8
DEBUG REP " "\v3, "*", CR
RETURN
Then in the book when they start explaining the code on page 96 they have something totally different for the Display. Here is what is on page 96.
Display:
DEBUG REP " "\adcBits/4, "*", CR
RETURN
I tried running the code Display both ways, and neither way displayed the triangle wave form. I want to find out what I am doing wrong, and get a triangle wave form on my Debug display. Here is my code below. My circuit is exactly the same as the circuit diagram on page 83.
' {$STAMP BS2}
' {$PBASIC 2.5}
'Basic Analog and Digital--PL5_1R0,bs2
'Digital Voltmeter (DVM) . D/A Converter Added
'
[Declarations]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte
n VAR Nib
'
[ Initialization ]
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS
'Start display.
DO
FOR n = 7 TO 15
GOSUB Main
NEXT
FOR n = 14 TO 8
GOSUB Main
NEXT
LOOP
'
[ Main Routine ]
Main:
GOSUB DAC
GOSUB ADC_Data
'GOSUB Calc_Volts
GOSUB Display
RETURN
'
[ Subroutines ]
DAC:
DIRB = 15
OUTB = n
PAUSE 50
RETURN
ADC_Data:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8]
RETURN
Calc_Volts:
v = 5 * adcBits/ 255
r = 5 * adcBits // 255
v2 = 100 * R / 255
v3 = 100 * R // 255
v3 = 10 * v3 /255
IF (v3 >= 5) THEN v2 = v2 +1
IF (v2 >= 100) THEN
v = v + 1
v2 = 0
ENDIF
RETURN
Display:
v3 = adcBits / 8
DEBUG REP " "\v3, "*", CR
RETURN
Comments
Double-check your ADC_Data and Display routines because they look different than what I see the 1.4 text.
LOW CS turns on the ADC because Chip Select in an Active-Low input, and HIGH CS turns it off.
Also, in the DEBUG command adcBits should be divided by 4 and not 8 since we're using a 4-Bit DAC.
ADC_Data:
HIGH CS
LOW CS
LOW CLK
Nothing in chapter 5, pages 91 and 92 was said about changing the: HIGH CS
What you did was add it right before the RETURN. Which seemed the right thing to do.
Also: I can't understand why on page 92 they list the code change for Display, then on 96 when explaining the Display code, the have something totally different.
OK, I ran the code with your changes Genetix, and the triangle wave form did not appear. I got the same results as before, just a straight line up and down, on the left side of the Debug screen. I need to get this triangle wave form working.
On page 92 the book says to change the Display: routine to this.
Display:
DEBUG REP " "\adcBits/4,"*", CR
RETURN
However in your forum post you said that on page 92 the book asks for you to modify the Display routine code to look like this.
v3 = adcBits / 8
DEBUG REP " "\v3, "*", CR
RETURN
What you see on page 92 and what I see on page 92 is different.
Then on page 96 they start explaining the code. The code I see on page 96 is the same as on page 92.
Display:
DEBUG REP " "\adcBits/4,"*", CR
RETURN
I don't see where you are getting the code you reference.
v3 = adcBits / 8
DEBUG REP " "\v3, "*", CR
RETURN
That may be where you are going wrong. I wonder if you have a different version of the book? Are you getting your copy from our site?
Best Regards,
Miguel Rodriguez
Parallax Inc. Tech Support
Display:
DEBUG REP " "\adcBits/4,"*", CR
RETURN
or
Display:
v3 = adcBits / 8
DEBUG REP " "\v3, "*", CR
RETURN
Try running the code either way. Look at your Debug screen and you get a row of dots up the left hand side, when you should get a triangle wave form.
' {$STAMP BS2}
' {$PBASIC 2.5}
'Basic Analog and Digital--PL5_1R0,bs2
'Digital Voltmeter (DVM) . D/A Converter Added
'
[Declarations]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte
n VAR Nib
'
[ Initialization ]
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS
'Start display.
DO
FOR n = 7 TO 15
GOSUB Main
NEXT
FOR n = 14 TO 8
GOSUB Main
NEXT
LOOP
'
[ Main Routine ]
Main:
GOSUB DAC
GOSUB ADC_Data
'GOSUB Calc_Volts
GOSUB Display
RETURN
'
[ Subroutines ]
DAC:
DIRB = 15
OUTB = n
PAUSE 50
RETURN
ADC_Data:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8]
RETURN
Calc_Volts:
v = 5 * adcBits/ 255
r = 5 * adcBits // 255
v2 = 100 * R / 255
v3 = 100 * R // 255
v3 = 10 * v3 /255
IF (v3 >= 5) THEN v2 = v2 +1
IF (v2 >= 100) THEN
v = v + 1
v2 = 0
ENDIF
RETURN
Display:
DEBUG REP " "\adcBits/4,"*", CR
RETURN
A PDF of the V1.4 book can be downloaded free here: https://www.parallax.com/downloads/basic-analog-and-digital-text
'GOSUB Calc_Volts
It should have been this.
GOSUB CALC_Volts
A very tiny mistake that I and everyone else overlooked. I suppose this means I am learning something.
I am so green at coding I began to wonder if I would ever catch on. I still feel like I only know 1% of what I need to know to be able to code. Winners never quit and quitters never win. Boys---Chalk this one up to determination, I got it working.