Shop OBEX P1 Docs P2 Docs Learn Events
Voltage that controls resistance through BS-2 — Parallax Forums

Voltage that controls resistance through BS-2

Keith HiltonKeith Hilton Posts: 150
edited 2004-12-14 20:38 in BASIC Stamp
tongue.gif·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
Returnhop.gif
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.
roll.gif·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?smhair.gif· Wiper can be set counter-clockwise, or clockwise.· But how can it be set to automatically follow voltage counter-clockwise or clockwise?smhair.gif·· I don't have a clue, and I can't find any instructions or examples to read. Help.confused.gif· 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

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-12-11 17:36
    This is a classic negative feedback problem. Your main loop will do something like the following:
    actualPosition VAR Byte
    desiredPosition VAR Byte
    DO
      GOSUB   Read_0831
      desiredPosition = adc */100   ' convert 0-256 to 0-100 for the DS1804
      SELECT desiredPosition 
      CASE <actualPosition    ' also 0-100
        gosub counterclockwise 
      CASE >actualPosition
        gosub clockwise
      ENDSELECT
    LOOP
    



    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
  • Keith HiltonKeith Hilton Posts: 150
    edited 2004-12-14 02:55
    Tracy, thanks for the reply and help. I agree that my program has no feedback from the DS1804. The BS2 needs to know what is going on with the BS2. Tracy, where would the main loop ,you have written out, go in my program. I am not understanding exactly where to put it in the program I listed above? Thanks!
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-12-14 20:38
    You can use the main loop from your program that you posted, but right after reading the ADC and displaying the results, insert this snippet:

    ··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
Sign In or Register to comment.