Bus Pirate Edu Kit Exercise no.6

From DP

Revision as of 18:08, 26 May 2013 by Vipa (Talk | contribs)
Jump to: navigation , search

Contents

Overview

BP EK E6 overview.jpg

In this exercise we'll test out the MCP4131 digital potentiometer. Insted og having mechanical control, digital potentiometers are controlled through a digital protocol. In this case SPI.

To keep the exercise simple we'll concentrate only on adjusting the wiper position register (Volatile Wiper 0) at the address 0x00.

BP EK E6 protocol.jpg

The protocol is defined in such a way that each write to a register requires you to send 2 bytes. The first sent byte contains the registrar address(0x0), the write command (0x0), and the 2 MSB bits(D9 and D8 of the 10 bit data you want to write. The second byte contains the 8 LSB bits (D7, D6, D5, D4, D3, D2, D1, and D0) of the byte you want to write. Here is an example of how to set the wiper to the top most position.

  • 1st byte: 0b(0000-addr)(00-cmd)(11) = 0x03
  • 2nd byte: 0b(11111111) = 0xFF

The Circuit

BP EK E6 schematic.jpgBP EK E6 circuit.jpg

Breadboard legend

IC Location Breadboard wiring legend
IC PIN1 (+) PIN2 (-)
MCP4131 E14 E15
Signal name Contact1 Contact2
5V BP_5V BB_+_left
5V BB_+_left BB_+_right
5V BB_+_right J14
5V BB_+_right J15
GND BP_GND BB_-_left
GND BB_-_left BB_-_right
GND BB_-_left A17
GND BB_-_right J17
MOSI BB_MOSI A16
CLK BB_CLK A15
CS BB_CS A14
ADC BB_ADC H16
  • The (+) and (-) next to PIN1 and PIN2 are intended for devices such as LEDs, where PIN1 should be the anode and connected to a higher potential then PIN2.

Bus Pirate Terminal


HiZ>m<<<the mode command
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)

(1)>5<<<select the SPI mode<<<
Set speed:
1. 30KHz
2. 125KHz
3. 250KHz
4. 1MHz

(1)>3<<<set the SPI speed to 250 KHz<<<
Clock polarity:
1. Idle low *default
2. Idle high

(1)>1<<<set clock polarity to idle low
Output clock edge:
1. Idle to active
2. Active to idle *default

(2)>2<<<set output clock edge to active to idle
Input sample phase:
1. Middle *default
2. End

(1)>1<<<select the middle input sample phase
CS:
1. CS
2. /CS *default

(2)>2<<<select the inverted CS signal (active low)
Select output type:
1. Open drain (H=Hi-Z, L=GND)
2. Normal (H=3.3V, L=GND)

(1)>2<<<set the output type to normal
Ready
SPI>W<<<turn on the power supplies
POWER SUPPLIES ON

First we need to setup the SPI protocol as per MCP4131's datasheet. Once the protocol is setup we turn on the power supplies via the 'W' command.


SPI>[0x00 0x00]<<<move the potentiometer wiper to the 0 position
/CS ENABLED<<<the CS pin is brought LOW ('[' command)
WRITE: 0x00<<<registrar address and two MSB bits of data are sent
WRITE: 0x00<<<data to be written to the register is sent
/CS DISABLED<<<CS pin is brought HIGH (']' command)
SPI>d<<<read the voltage on the ADC pin
VOLTAGE PROBE: 0.00V

Here we write 0x000 to the volatile wiper 0 register. This moves the potentiometer wiper to the 0 position. Then we read out the voltage on the ADC pin, it should be around 0V.


SPI>[0x03 0xff]]<<<move the potentiometer wiper to the 1023 (0x3FF) position
/CS ENABLED
WRITE: 0x03
WRITE: 0xFF
/CS DISABLED
SPI>d<<<read the voltage on the ADC pin
VOLTAGE PROBE: 3.27V

Next we move the wiper to the highest most position. This is done by writing 0x3FF to the volatile wiper 0 register. Now ~3.3V should be read.


SPI>[0x00 0x40]]<<<move the potentiometer wiper to the 64 (0x040) position
/CS ENABLED
WRITE: 0x00
WRITE: 0xFF
/CS DISABLED
SPI>d<<<read the voltage on the ADC pin
VOLTAGE PROBE: 1.61V

Once you've tested out that the fist two positions are correct, you can move the digital potentiometer in any position you'd like.


SPI>m<<<the mode command
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)

(1)>1<<<select the HiZ mode
Ready
HiZ>

Once you're done with the exercise you can shutdown the Bus Pirate by selecting the HiZ mode, as shown above.

Not Working?

  • wiring
  • chip positioning (pin 1)
  • SPI setup

Taking it further

  • Try out using other commands
  • increment/decrement
  • attach/detach resister network pins..