Constructing a Pushbutton Interface for the DS1845/DS1855 Digital Potentiometers
IntroductionThis application note illustrates a method of implementing a pushbutton interface to the DS1845 or DS1855 nonvolatile digital potentiometers using a Microchip® PIC12F509 microcontroller.
Hardware SetupThe schematic in Figure 1 illustrates how to interface the pushbuttons to the microcontroller. It also shows how the I²C interface is implemented.
Three of the switches are momentary pushbutton type and are used to increment (UP), decrement (DWN), and program a middle pot value (MID). When depressed, these switches force a low on three of the microcontroller's general purpose I/Os (GP0, GP1, and GP3). These I/Os were explicitly chosen because they have internal (optional) pullup resistors and can generate a wake-up interrupt if the low-current SLEEP mode is enabled. The other input switch is a DPDT toggle assigned to GP2. This switch can be used to select either POT0 or POT1 for programming.
Output signals on SDA, SCL, and the LED are assigned to GP5, GP4, and GP0. SDA and SCL have 4.7kΩ pullup resistors and connect directly to the communication pins of the digital pots. The LED and the MID momentary switches both use the GP0 pin as a resource. The GP0 pin functions as an input most of the time, polling for a LOW caused by the MID pushbutton. However, if one or both of the other momentary pushbuttons are depressed, then the PIC® outputs a LOW, causing the LED to be driven. In this way the LED is driven whenever the MID button is pressed and by the PIC whenever another pushbutton switch is depressed. R1, R2, and R3 are optional pullup resistors that do not need to be populated when using the PIC12F509.
Figure 2 illustrates the DS1845/DS1855 specific connections for evaluation. Jumpers are provided for selecting address pins, separating the shared VCC (VDD), as well as isolating SDA and SCL.
Figure 1. PIC12F509 interface circuitry.
Figure 2. DS1845/DS1855 digital pot connected to PIC controller.
Firmware DescriptionFirmware for this project was written in assembly language compiled in MPLAB IDE (version 7.31). This tool is currently available from Microchip at no cost. The entire program consists of fewer than 512 instructions in program space (flash) and 14 locations in data space (RAM).
The instructions are divided among five blocks: Initialize, Read, UP, DWN, and MID. The firmware simply runs in a loop continuously polling the input pins. Switch debouching is automatically incorporated in software due to the intrinsic delays and logical flow of the program.
The Initialize block runs once at PIC power-up or after waking-up (if SLEEP is enabled). After the instructions in the Initialize block have run, the operating registers, flags, and variables are loaded to known states. When these instructions have been executed, the remaining blocks serially form an infinite loop to poll the switches, read, or write new pot values through I²C.
An I²C READ of the pot values only occurs when the RD_FLAG is set. This flag is set once during initialization, then whenever a pushbutton calls for a pot register to be written to a new value. By performing an I²C READ only during a pot value change and at startup, there are no superfluous communication bursts occurring on the bus when the UP, DWN, or MID buttons have not been depressed. For example, if the pot is already in service controlling a power-supply trim parameter, then the pushbutton controller is connected to perform in-circuit programming. The current pot value will be read before an I²C WRITE of the pot value is performed. Once the I²C WRITE has completed, the RD_FLAG is set again to generate one final I²C READ of the new pot value.
The UP, DWN, and MID blocks run sequentially after the Read block. In each of these blocks the respective pins are polled for a LOW state. If a HIGH state is found, then the program exits the block quickly, without causing any I²C communication to occur. If a LOW is detected, then the program flows as described in the logical block diagram.
The source code (.asm file) can be downloaded from Maxim's FTP site.
Description of FunctionalityThis project's firmware and hardware allow several different operations to be carried out while programming the pot values on the DS1845/DS1855. The switch and LED functions are:
|POT0/1 (selection toggle switch)||This switch chooses which pot (if necessary) will be controlled in the next loop iteration. A change of state on this switch selects POT0 or POT1, causes an I²C read, and has no effect on the LED.|
|Tap the MID, UP, or DWN button
||By tapping one of these switches, the selected pot will either increment (UP), decrement (DWN), or be loaded with the middle position directly (MID). The LED will illuminate briefly while the I²C write is carried out; an I²C read will occur in the next loop iteration.|
|Press and hold UP or DWN button
||By pressing and holding the UP or DWN button, the selected pot will enter a fast increment or decrement mode. Now the pot value will continue to change until the button is either released or the max/min position is reached. The LED will illuminate as I²C writes are carried out; it will remain illuminated until the button is released. After button release, an I²C read will occur in the next loop iteration.|
|Press and hold UP, then tap DWN button||By pressing and holding the UP button, the selected pot will begin incrementing. Then while the UP button is still depressed, the DWN button is tapped causing the selected pot to directly be loaded with the maximum position. The LED will illuminate until the switches are released. After the buttons are released, an I²C read will occur in the next loop iteration.|
|Press and hold DWN, then tap UP button||By pressing and holding the DWN button, the selected pot will begin decrementing. Then while the DWN button is still depressed, the UP button is tapped causing the selected pot to directly be loaded with the minimum position of 0x00. The LED will illuminate until the switches are released. After the buttons are released, an I²C read will occur in the next loop iteration.|
|LED blinks three times||The LED will blink three times whenever the PIC is initialized during power up or whenever the watchdog timer causes a system reset (if enabled).|
|LED continuously blinks quickly||The LED will continually blink quickly whenever an I²C error occurs. Once the error is corrected, the LED will resume normal functionality. Troubleshoot by checking that the device address is correct and that the I²C bus is connected.|
ConclusionThis application note describes how to use and construct a simple and cost-effective controller for the DS1845/DS1855 nonvolatile digital potentiometers. Pushbutton inputs are converted to I²C commands to increment, decrement, or set a middle position without the need for a host computer.
Questions/comments/suggestions concerning this application note can be sent to: .