X9C103P Digital Pot As Voltage Divider Problem (SOLVED)

Discussion in 'Embedded Systems and Microcontrollers' started by iimagine, Nov 19, 2014.

  1. iimagine

    Thread Starter Active Member

    Dec 20, 2010
    129
    9
    This Pot is driving me nuts! I have no Idea why its not working as it should, I followed what the data sheet said: Set CS (Chip Select) LOW, Set UD (Up/Down) direction, Trigger INC LOW then HIGH. then set CS HIGH to write to EEPROM or set CS HIGH before setting INC HIGH to not write to EEPROM.
    This DOES work properly! However, only if I write to EEPROM right after by setting CS HIGH again.
    Since I dont want to write to EEPROM, I chose to leave CS LOW all the time, for now. It does work, using the osc-scope I can see the voltage varies UP/DOWN but not within the correct range, given an analog voltage of 1.5 and Wiper is set to 1, the analog output voltage is around 1V ?!.
    X9C103 connections:
    CS, U/D, INC to Arduino digital IO pins
    VH (High Terminal) to analog input
    VL (Low Terminal) to GND
    VW (Wiper) as output

    Any advice/help is much appreciated. Thanks in advance.

    Datasheet: http://pdf1.alldatasheet.com/datasheet-pdf/view/34250/XICOR/X9C103P.html
    Code (Text):
    1. //-----------------------------------------------------------------------
    2. // DPX9C Digital Pot
    3. //-----------------------------------------------------------------------
    4. // Arduino Uno pin 10 to X9Cxxx increment pin (INC) - 1
    5. // Arduino Uno pin 09 to X9Cxxx up/down pin (U/D) - 2
    6. // Arduino Uno pin 08 to X9Cxxx CS pin (CS) - 7
    7. // ---Constants---
    8. const byte DPX9C_INC = B00000100;
    9. const byte DPX9C_UD = B00000010;
    10. const byte DPX9C_CS = B00000001;
    11. const byte DPX9C_POWERUP_TIME = 50;
    12. const byte DPX9C_CS_TIME = 20;
    13. const byte DPX9C_INC_TIME = 1;
    14. // DPX9C Maximun number of steps
    15. const byte DPX9C_STEPS = 100;
    16. const byte DPX9C_LOWER_LIMIT = 1;
    17. const byte DPX9C_UPPER_LIMIT = DPX9C_STEPS - DPX9C_LOWER_LIMIT;
    18. byte volatile dpWiper;
    19.  
    20. static inline void dpDecrease()
    21. {
    22.   if (dpWiper > DPX9C_LOWER_LIMIT)
    23.   {
    24.     dpWiper--;
    25.     PORTB &= ~DPX9C_UD;
    26.     PORTB &= ~DPX9C_INC;
    27.     delayMicroseconds(DPX9C_INC_TIME);
    28.     PORTB |= DPX9C_INC;
    29.   }
    30. }
    31.  
    32. static inline void dpIncrease()
    33. {
    34.   if (dpWiper < DPX9C_UPPER_LIMIT)
    35.   {
    36.     dpWiper++;
    37.     PORTB |= DPX9C_UD;
    38.     PORTB &= ~DPX9C_INC;
    39.     delayMicroseconds(DPX9C_INC_TIME);
    40.     PORTB |= DPX9C_INC;
    41.   }
    42. }
    43.  
    44. void setupDP()
    45. {
    46.   // Wait for DPX9C to complete its powerup sequence
    47.   delay(DPX9C_POWERUP_TIME);
    48.   PORTB &= ~DPX9C_CS;
    49.   PORTB |= DPX9C_INC;
    50.   // Set the digital pot all the way down to zero;
    51.   dpWiper = DPX9C_STEPS << 1;
    52.   while (dpWiper > DPX9C_LOWER_LIMIT)
    53.     dpDecrease();
    54.   while (dpWiper < DPX9C_UPPER_LIMIT)
    55.     dpIncrease();
    56. }
    57.  
     
    Last edited: Nov 19, 2014
  2. JWHassler

    Member

    Sep 25, 2013
    201
    33
    A schematic might help. I can't quite picture where the pot's wiper-pin goes
     
  3. iimagine

    Thread Starter Active Member

    Dec 20, 2010
    129
    9
    The pot's wiper pin is connected to Cin, my ADC Preamp designl; V2, V3 and V4 are there for simulation purposes only. As you can see, I'm trying to control the input voltage. Thanks
     
  4. iimagine

    Thread Starter Active Member

    Dec 20, 2010
    129
    9
    JWHassler's got me into thinking that, somehow, somewhere between the wiper out and my ADC Preamp, something went wrong. So I connected VH to VCC (5V) and VL to GND, taking voltage measurement at VW; no connection to my ADC Preamp, and the Pot is now working properly; with the dpWiper set at 50, the output voltage is now at 2.5V. So now i'm stuck! Staring at my shematic and double check my wiring, wondering why its not working with AC input. Anyone have a thought?
     
  5. iimagine

    Thread Starter Active Member

    Dec 20, 2010
    129
    9
    Somehow, after reconnecting VH to AC input, VL to GND and VW (Wiper) to Cin of my ADC Preamp, its working!! Must have been a short somewhere that's been resolved by reconnecting everything. Thanks for reading my post
     
Loading...