Voltage that controls resistance through BS-2
Keith Hilton
Posts: 150
·I started this topic a couple of days ago, and was so far off I thought it would be best to start it all over again. Here are the parts involved: 100K pot feeding a variable,·0 to 5 volts, to a AD0831 to a BS-2.· Then,BS-2 feeding a DS1804. There should be two basic parts to a program, the input to the BS-S, and the output.·· The input first: I had a program that worked out of Matt Gilliland's Applications Cookbook #1, page 87.· Problem was I couldn't get it to work with the digital pot. Jon Williams then helped me with the following program that did wonders with the AD0831.
'{$STAMP BS2}
'{$PBASIC 2.5}
CS PIN 15
Clk PIN 14
Dio PIN 13
Raw2mV CON $139B
adc VAR Byte
mVolts VAR Word
Reset:
HIGH CS
DEBUG CLS,
········· "ADC0831",CR,CR,
········· "··· Counts:",CR,
········· " Volts: "
Main:
DO
GOSUB Read_0831
mVolts =adc*/Raw2mV
DEBUG CRSRXY, 10,2,
········· DEC3 adc,
········· CRSRXY, 10 3,
········· DEC mVolts DIG 3, ".", DEC3 mVolts
LOOP
END
Read_0831:
LOW CS
SHIFTIN Dio, Clk, MSBPOST, [noparse][[/noparse]adc\9]
HIGH CS
Return
The above program read out
,"count and voltage", on the DEBUG Screen and moved values· as I moved the pot controlling voltage to the 0831.
·Now, how to write the program, and where to insert it, so·it will control the resistance of the DS1804?·The special problem here is the resistance must follow the voltage.·The DS1804 must·quickly follow what the 0831 is doing. ·I can write a program that will increment the ohm value up or down in the DS1804, that is not problem.·But, I don't know how to use the information coming from the 0831 chip to increment the DS1804.·The "BIG" question in my mind is how I set the clock direction so it follows voltage?· Wiper can be set counter-clockwise, or clockwise.· But how can it be set to automatically follow voltage counter-clockwise or clockwise?·· I don't have a clue, and I can't find any instructions or examples to read. Help.· Thus far I have used up pins 15,14,and 13 on the stamp with the 0831, so the DS1804 needs to use different pin numbers.
'{$STAMP BS2}
'{$PBASIC 2.5}
CS PIN 15
Clk PIN 14
Dio PIN 13
Raw2mV CON $139B
adc VAR Byte
mVolts VAR Word
Reset:
HIGH CS
DEBUG CLS,
········· "ADC0831",CR,CR,
········· "··· Counts:",CR,
········· " Volts: "
Main:
DO
GOSUB Read_0831
mVolts =adc*/Raw2mV
DEBUG CRSRXY, 10,2,
········· DEC3 adc,
········· CRSRXY, 10 3,
········· DEC mVolts DIG 3, ".", DEC3 mVolts
LOOP
END
Read_0831:
LOW CS
SHIFTIN Dio, Clk, MSBPOST, [noparse][[/noparse]adc\9]
HIGH CS
Return
The above program read out
,"count and voltage", on the DEBUG Screen and moved values· as I moved the pot controlling voltage to the 0831.
·Now, how to write the program, and where to insert it, so·it will control the resistance of the DS1804?·The special problem here is the resistance must follow the voltage.·The DS1804 must·quickly follow what the 0831 is doing. ·I can write a program that will increment the ohm value up or down in the DS1804, that is not problem.·But, I don't know how to use the information coming from the 0831 chip to increment the DS1804.·The "BIG" question in my mind is how I set the clock direction so it follows voltage?· Wiper can be set counter-clockwise, or clockwise.· But how can it be set to automatically follow voltage counter-clockwise or clockwise?·· I don't have a clue, and I can't find any instructions or examples to read. Help.· Thus far I have used up pins 15,14,and 13 on the stamp with the 0831, so the DS1804 needs to use different pin numbers.
Comments
The thing is, I don't see that you have any feedback from the DS1804 back to your program. That part is open loop. Your program has to keep an internal state variable, which I called actualposition. The routines that send an UP or a DOWN pulse to the DS1804 also have to increment or decrement actualposition, so that the Stamp itself keeps track of the potentiometer position. (It would be easier if you had a chip that simply let you send the desired wiper setting via SPI or I2C, instead of simple up and down).
The feedback loop itself should be clear. Move the wiper toward the position that makes it match the desired setting.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
··desiredPosition·=·adc·*/100···'·convert·0-256·to·0-100·for·the·DS1804
··SELECT·desiredPosition
··CASE·<actualPosition
····gosub·counterclockwise
actualPosition=actualPosition-1
··CASE·>actualPosition
····gosub·clockwise
actualPosition=actualPosition+1
··ENDSELECT
You will need to add two subroutines, one to move the DS1804 one step "clockwise", and one to move it one step "counterclockwise". Follow Matt's example, but instead of moving 100 steps, just move one step and RETURN. The feedback will execute time and time again until actualPosition=desiredPosition.
You will still need an initialization step, to bring the DS1304 to its home position and to set variable actualPosition=0. Since this is an open loop system, with no direct feedback from the DS1804, there is a possibility that the settings will slip witn time, so it will need to be reinitialized. For closed loop feedback, put the DS1304 output into another ADC channel.
I hope that helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com