Voltage --> A2D --> Stamp --> Digital Pot
Keith Hilton
Posts: 150
·Working on feeding an analog voltage to AD converter, to BS-2, then to a digital potentiometer.
Working from Matt Gilliland's "The Microcontroller Application Cookbook #1"
Page 221 is my hookup and program for the analog voltage input.· Page· 188 is my hookup and program for my digital potentiometer.· I am trying to combine both these programs to eventually convert a analog voltage, 0 to 5 volts, into a resistance value coming out of the digital pot.· Would like resistance to change as quickly as the analog voltage changes. In my program, I have changed the numbers in the program on page 188.· Here are the changes: 3 changed to 13, 2 changed to 12, and 1 changed to 11.· I can get the program on page 221 to run great.· I can get the program on page 188 to run great.· I have not been able to combine them and get them to work together.
'{$STAMP BS2}
x VAR byte
y VAR byte
Incr VAR byte
here:
LOW 0 'enable the 0831 AD converter
PULSOUT 1,1 'send the first set up out clock pulse.
x=0 'set x to 0
FOR y= 1 to 8·· 'loop 8 times to get 8 data bits
PULSOUT1,1·· 'send a clock pulse
x=x*2·· 'shift the bits left
x=x+IN2·· 'add the value of x to the incoming bit
NEXT
HIGH 0·· 'disable the 0831 AD converter
DEBUG ?X· 'display the result.
'To this point everything is working great!
' This is where I screw up, getting the information to the 1804 POT.
LOW 13·· 'select DS 1804 Digital POT.
LOW 12· 'set direction to counter -clockwise
Incr=x· 'Read analog voltage number
FOR x=1 to 255
HIGH 11
LOW 11
NEXT
HIGH 12·· 'set direction to clockwise
Incr=x·· 'Read analog voltage number
FOR x= 1 to 255
PAUSE 1000·· 'View it on the ohm meter
HIGH 11
LOW 11
NEXT
GOTO here
I am brand new at programming.·Help--Teacher is in Florida at a Teacher's conference.
Post Edited By Moderator (Jon Williams) : 12/9/2004 4:13:56 AM GMT
Working from Matt Gilliland's "The Microcontroller Application Cookbook #1"
Page 221 is my hookup and program for the analog voltage input.· Page· 188 is my hookup and program for my digital potentiometer.· I am trying to combine both these programs to eventually convert a analog voltage, 0 to 5 volts, into a resistance value coming out of the digital pot.· Would like resistance to change as quickly as the analog voltage changes. In my program, I have changed the numbers in the program on page 188.· Here are the changes: 3 changed to 13, 2 changed to 12, and 1 changed to 11.· I can get the program on page 221 to run great.· I can get the program on page 188 to run great.· I have not been able to combine them and get them to work together.
'{$STAMP BS2}
x VAR byte
y VAR byte
Incr VAR byte
here:
LOW 0 'enable the 0831 AD converter
PULSOUT 1,1 'send the first set up out clock pulse.
x=0 'set x to 0
FOR y= 1 to 8·· 'loop 8 times to get 8 data bits
PULSOUT1,1·· 'send a clock pulse
x=x*2·· 'shift the bits left
x=x+IN2·· 'add the value of x to the incoming bit
NEXT
HIGH 0·· 'disable the 0831 AD converter
DEBUG ?X· 'display the result.
'To this point everything is working great!
' This is where I screw up, getting the information to the 1804 POT.
LOW 13·· 'select DS 1804 Digital POT.
LOW 12· 'set direction to counter -clockwise
Incr=x· 'Read analog voltage number
FOR x=1 to 255
HIGH 11
LOW 11
NEXT
HIGH 12·· 'set direction to clockwise
Incr=x·· 'Read analog voltage number
FOR x= 1 to 255
PAUSE 1000·· 'View it on the ohm meter
HIGH 11
LOW 11
NEXT
GOTO here
I am brand new at programming.·Help--Teacher is in Florida at a Teacher's conference.
Post Edited By Moderator (Jon Williams) : 12/9/2004 4:13:56 AM GMT
Comments
You're having trouble with your digital pot because you're destroying the·adc value (in x) with a FOR-NEXT loop.
Let me suggest that you also read the section of the Help file called "The Elements of PBASIC Style."· Using single-letter variables an pin numbers (instead of named pins) is an easy way to make a big mess and get lost.· PBASIC allows for very elegant coding that will save you from creating lots of bugs in the long run.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 12/9/2004 4:29:39 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Basic Analog and Digital - Chapter 3 has a similar BASIC Stamp 2, ADC0831, potentiometer/voltmeter application and lots of explanations.· There is also some warm-up material in the chapter before, and some simple applications in the chapters that follow.·
Understanding Signals - Chapter 5 takes a closer look at the synchronous serial communication between the BASIC Stamp 2 and the ADC0831.· With the aid of the Parallax Oscilloscope, the SHIFTIN command is examined along with the mechanics of making the ADC0831 transmit its digital value.
Industrial Control - Chapters 4 through 6 use the ADC0831 to measure a temperature probe in a closed loop temperature control system.
Post Edited (Andy Lindsay) : 12/9/2004 7:39:28 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office