Thursday, 4 July 2013

MCP3201 ADC / MCP4151 Digital Potentiometer old blog posts to refresh memory






MCP3201 ADC old blog posts to refresh memory



Wednesday, May 08, 2013 MCP3201 setup notes

http://tlfong01.blogspot.hk/2013/05/mcp3201-setup-notes.html

Now I have assembled a voltage divider to divided the input analogue voltage by half, so that input greater than the reference voltage 4.10V will not be over ranged.  So 5V will be divided to become 2.5V etc.

I need to double the calculated value in the final step, as listed below.

    spiGuzuntyPi = spidev.SpiDev()
    spiGuzuntyPi.open(0, 0)

    DummyDoubleByteList = [0x00, 0x00]
    adcOutputDoubleByteList = [0x55, 0x55]
    adcOutputDoubleByteList = spiGuzuntyPi.xfer2(DummyDoubleByteList)

    PrintEightBitPattern("ADC output byte 1 = ", adcOutputDoubleByteList[0])
    PrintEightBitPattern("ADC output byte 2 = ", adcOutputDoubleByteList[1])

    adcDecimalValue = (adcOutputDoubleByteList[1] >> 1) + (adcOutputDoubleByteList[0] * (2 ** 7))

    # adcAnalogVoltage = (float(adcDecimalValue) / 4096) * 4.10 # without half voltage divider
    adcAnalogVoltage = ((float(adcDecimalValue) / 4096) * 4.10) * 2 # with half voltage divider

    print "Analog voltage = ", adcAnalogVoltage

When the dual digital potentiometer arrives, I think I will try some auto ranging as well.


.END



Saturday, May 04, 2013  Guzunty Pi 4 digit LED to display MCP3201 ADC

http://tlfong01.blogspot.hk/2013/05/guzunty-pi-4-digit-led-to-display.html

Now I am thinking of playing with MCP3201 and display the results in Guzunty Pi LED.

.END




Sunday, May 05, 2013 MCP3201 ADC testing notes

http://tlfong01.blogspot.hk/2013/05/mcp3201-adc-testing-notes.html

Now I have inserted the MCP3201 ADC into the breadboard.  The interface to RPi is SPI channel 0. The power 3V3 is from the external power supply which also drives the Guzunty Pi.

Next step is to test the MCP3201.

.END




Sunday, May 05, 2013 MCP3201 learning notes

Now I am reading the MCP3201 datasheet.

MciroChip MCP3201 2.7V 12-Bit A/D Converter with SPI Serial Interface

Features

• 12-Bit Resolution

• ±1 LSB max DNL

• ±1 LSB max INL (MCP3201-B)

• ±2 LSB max INL (MCP3201-C)

• On-chip Sample and Hold

• SPI Serial Interface (modes 0,0 and 1,1)

• Single Supply Operation: 2.7V - 5.5V

• 100 ksps Maximum Sampling Rate at VDD = 5V

• 50 ksps Maximum Sampling Rate at VDD = 2.7V

..

Description

The Microchip Technology MCP3201 device is a successive approximation 12-bit Analog-to-Digital (A/D) Converter with on-board sample and hold circuitry. The device provides a single pseudo-differential input. Differential Nonlinearity (DNL) is specified at ±1 LSB, and Integral Nonlinearity (INL) is offered in ±1 LSB (MCP3201-B) and ±2 LSB (MCP3201-C) versions. Communication with the device is done using a simple serial interface compatible with the SPI protocol. The device is capable of sample rates of up to 100 ksps at a clock rate of 1.6 MHz. The MCP3201 device operates over a broad voltage range (2.7V-5.5V).

...

3.1 Positive Analog Input (IN+)

Positive analog input. This input can vary from IN- to VREF + IN-.

3.2 Negative Analog Input (IN-)

Negative analog input. This input can vary ±100 mV from VSS.

3.3 Chip Select/Shutdown (CS/SHDN)

The CS/SHDN pin is used to initiate communication with the device when pulled low and will end a conversion and put the device in low power standby when pulled high. The CS/SHDN pin must be pulled high between conversions.

3.4 Serial Clock (CLK)

The SPI clock pin is used to initiate a conversion and to clock out each bit of the conversion as it takes place.
...

3.5 Serial Data Output (DOUT)

The SPI serial data output pin is used to shift out the results of the A/D conversion. Data will always change on the falling edge of each clock as the conversion takes place.

4.0 DEVICE OPERATION

The MCP3201 A/D Converter employs a conventional SAR architecture. With this architecture, a sample is acquired on an internal sample/hold capacitor for 1.5 clock cycles starting on the first rising edge of the serial clock after CS has been pulled low. Following this sample time, the input switch of the converter opens and the device uses the collected charge on the internal sample and hold capacitor to produce a serial 12-bit digital output code. Conversion rates of 100 ksps are possible on the MCP3201 device.

...

5.0 SERIAL COMMUNICATIONS

Communication with the device is done using a standard SPI-compatible serial interface.

Initiating communication with the MCP3201 device begins with the CS going low. If the device was powered up with the CS pin low, it must be brought high and back low to initiate communication.

The device will begin to sample the analog input on the first rising edge after CS goes low. The sample period will end in the falling edge of the second clock, at which time the device will output a low null bit.

The next 12 clocks will output the result of the conversion with MSB first, as shown in Figure 5-1. Data is always output from the device on the falling edge of the clock.

If all 12 data bits have been transmitted and the device continues to receive clocks while the CS is held low, the device will output the conversion result LSB first, as shown in Figure 5-2. If more clocks are provided to the device while CS is still low (after the LSB first data has been transmitted), the device will clock out zeros indefinitely.

6.0 APPLICATIONS INFORMATION

6.1 Using the MCP3201 Device with Microcontroller SPI Ports

With most microcontroller SPI ports, it is required to clock out eight bits at a time. If this is the case, it will be necessary to provide more clocks than are required for the MCP3201.

As an example, Figure 6-1 and Figure 6-2 show how the MCP3201 device can be interfaced to a microcontroller with a standard SPI port.

Since the MCP3201 always clocks data out on the falling edge of clock, the MCU SPI port must be configured to match this operation. SPI Mode 0,0 (clock idles low) and SPI Mode 1,1 (clock idles high) are both compatible with the MCP3201. Figure 6-1 depicts the operation shown in SPI Mode 0,0, which requires that the CLK from the microcontroller idles in the ‘low’ state.

As shown in the diagram, the MSB is clocked out of the A/D Converter on the falling edge of the third clock pulse. After the first eight clocks have been sent to the device, the microcontroller’s receive buffer will contain two unknown bits (the output is at high-impedance for the first two clocks), the null bit and the highest order five bits of the conversion. After the second eight clocks have been sent to the device, the MCU receive register will contain the lowest-order seven bits and the B1 bit repeated as the A/D Converter has begun to shift out LSB first data with the extra clock. Typical procedure would then call for the lower-order byte of data to be shifted right by one bit to remove the extra B1 bit. The B7 bit is then transferred from the high-order byte to the lower-order byte, and then the higher-order byte is shifted one bit to the right as well. Easier manipulation of the converted data can be obtained by using this method.

Figure 6-2 shows the same thing in SPI Mode 1,1 which requires that the clock idles in the high state. As with mode 0,0, the A/D Converter outputs data on the falling edge of the clock and the MCU latches data from the A/D Converter in on the rising edge of the clock.



6.2 Maintaining Minimum Clock Speed

When the MCP3201 initiates the sample period, charge is stored on the sample capacitor. When the sample period is complete, the device converts one bit for each clock that is received. It is important for the user to note that a slow clock rate will allow charge to bleed off the sample cap while the conversion is taking place. At 85°C (worst-case condition), the part will maintain proper charge on the sample capacitor for at least 1.2 ms after the sample period has ended. This means that the time between the end of the sample period and the time that all 12 data bits have been clocked out must not exceed 1.2 ms (effective clock frequency of 10 kHz). Failure to meet this criteria may induce linearity errors into the conversion outside the rated specifications. It should be noted that during the entire conversion cycle, the A/D Converter does not require a constant clock speed or duty cycle, as long as all timing specifications are met.

.END



Sunday, May 05, 2013

MCP3201 timing notes





















5.0 SERIAL COMMUNICATIONS

Communication with the device is done using a standard SPI-compatible serial interface. Initiating communication with the MCP3201 device begins with the CS going low. If the device was powered up with the CS pin low, it must be brought high and back low to initiate communication. The device will begin to sample the analog input on the first rising edge [of the clock pules] after CS goes low.

The sample period will end in the falling  edge of the second clock, at which time the device will output a low null bit. The next 12 clocks will output the result of the conversion with MSB first, as shown in Figure 5-1.

Data is always output from the device on the falling edge of the clock. If all 12 data bits have been transmitted and the device continues to receive clocks while the CS is held low, the device will output the conversion result LSB first, as shown in Figure 5-2. If more clocks are provided to the device while CS is still low (after the LSB first data has been transmitted), the device will clock out zeros indefinitely.



4.2 Reference Input

The reference input (VREF) determines the analog input voltage range and the LSB size, as shown below.

EQUATION 4-1:

LSB Size =  VREF / 4096


As the reference input is reduced, the LSB size is reduced accordingly. The theoretical digital output code produced by the A/D Converter is a function of the analog input signal and the reference input as shown below.

Digital Output Code = (4096 * VIN) / VREF

Where:

VIN = Analog Input Voltage = V(IN+) - V(IN-)

VREF = Reference Voltage

When using an external voltage reference device, the system designer should always refer to the manufacturer’s recommendations for circuit layout.

Any instability in the operation of the reference device will have a direct effect on the operation of the A/D Converter.

.END



Sunday, May 05, 2013 MCP3201 Application Note useful

I read the MCP3201 datasheet and found it a bit confusing, perhaps I do not understand things like what is meant by SPI mode 0, 0, mode 1, 1.  I also don't know what to do with the null bit.  So I googled an application notes and found it useful.  I guess the time has come for me to write a function to do the AD conversion.

.END



Sunday, May 05, 2013 MCP3201 testing notes

So I drafted the function to do ADC by MCP3201.

def TestMcp3201():
    PrintDoubleSpaceLine("*** Start testing MCP3201 ADC ***")
    spiGuzuntyPi = spidev.SpiDev()
    spiGuzuntyPi.open(0, 0)
    DummyDoubleByteList = [0x00, 0x00]
    adcOutputDoubleByteList = [0x55, 0x55]
    adcOutputDoubleByteList = spiGuzuntyPi.xfer2(DummyDoubleByteList)
    PrintEightBitPattern("ADC output byte 1 = ", adcOutputDoubleByteList[0])
    PrintEightBitPattern("ADC output byte 2 = ", adcOutputDoubleByteList[1])
    spiGuzuntyPi.close()
    PrintDoubleSpaceLine("*** Stop testing MCP3201 ***")

I executed the function twice, the first time with analog input connected to 3V3, the second time connected to ground.

The first time output with analog input connected to 3v3 is:

ADC output byte 1 =  11011111
ADC output byte 2 =  11111000

The second time output with analog input connected to ground is:

ADC output byte 1 =  11000000
ADC output byte 2 =  00000000

So the function seems bug free and works right away.  I was surprised that everything sent so smoothly.  I thought it might take me at least half an hour to do software and hardware debugging.

One thing that might be wrong is that the output seems only 10 bits instead of 12 bits.  Next step is to look at this problem first.

Anyway, I call it a day.



Monday, May 06, 2013 MCP3201 ADC accuracy found about 0.4%

Now I have used Excel to calculate the series resistor for Zener voltage reference, and the expected binary value for analog input voltages 2.85V and 2.44V.

Then I used the test function to find the MCP3201 ADC results, as listed below.  I found the accuracy is roughly 8 bits, which is equivalent to 1/256 or 0.4%, which I think is very good.

*** MCP3201 ADC results - tlfong01 2013may06 ***

0V    000 0000 0000 0000 0
3V3   000 1111 1111 1100 0

2V85  000 1101 1110 1001 0
Excel     1101 1111 1101

2V44  000 1011 1111 0010 1
Excel     1011 1111 1010

0V

ADC output byte 1 =  00000000
ADC output byte 2 =  00000000

3V3

ADC output byte 1 =  00011111
ADC output byte 2 =  11111000

2V85

ADC output byte 1 =  11011011
ADC output byte 2 =  11100111

2V44

ADC output byte 1 =  00010111
ADC output byte 2 =  11100101

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py
fl2067.py:268: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  setupOutputPin = lambda oPin: GPIO.setup(oPin, GPIO.OUT) # set GPIO pin as output
fl2067.py:270: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  setupInputPinWithPullUp = lambda iPin: GPIO.setup(iPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # set GPIO pin as input, with pull up

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00000000
ADC output byte 2 =  00000000

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00011111
ADC output byte 2 =  11111000

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  11011011
ADC output byte 2 =  11100111

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00010111
ADC output byte 2 =  11100101

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ date
Mon May  6 02:58:34 UTC 2013
pi@raspberrypi ~/python_programs/test_guzuntypi $

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00011011
ADC output byte 2 =  11010010

*** Stop testing MCP3201 ***


*** Stop Program ***

.END



Monday, May 06, 2013 KA431 for MCP3201 project notes

I found the Zenor diodes not that flexible or adjustable to use.  So I am thinking of using the reference IC KA431.  I googled "tlfong01 KA431" images and found a couple of my old images in the cloud.  They are for 3V0 reference which I used for gyro projects.  I think I will need to use 5V0 references for my Guzunty Pi projects.

.END



Monday, May 06, 2013 MCP3201 assembly notes

Now I am shifting the MCP3201 circuit from bread board to protoboard, at the same time adding a level shifter to convert 3V3 SPI signals to 5V0.  MCP3201 only listens to Chip Select signal.  So there is no need for another input signal to it.  In other words, SPI only has 4 wires - Gnd, Clk, MISO, Chip Select.

.END



Monday, May 06, 2013 MCP3201 setup up notes

Now I have finished the point to point soldering of MCP3201 and HC03/CD4050 based 3v3 to 5V0 level converter.  I have also made sure the open short thing is OK.  Next step is doing the real thing, ADC.

.END



Monday, May 06, 2013 MCP3201 5V version accuracy seems to be 0.2%

So I did the test.  I thought it might take me 30 minutes to debug the hardware wrong connections.  But again, everything went smoothly.

Accuracy seems not too different from the 3V3 version.  But then I forgot to check the precise value of the reference voltage.  So I need to Excel again.
Using the rough value 5.00, accuracy is 6 digits out of 12.  If using the more accurate value of 4.96, accuracy becomes 3 digits.  So accuracy is 3 last digits.

I am not too sure if I can then say accuracy is 3 digits / 12 digits == 8 / 4096
= 0.19 = 0.2%.

If indeed it is 0.2%, then it is very good.

5V0
MCP3201 = 0001111111110010
Excel   =    111111111111

0V0
MCP3201 = 0000000000000010
Excel   =    000000000000

3V26
MCP3201 = 0001010011111101
Excel   =    101001101111

2V43
MCP3201 = 0000111110100111 test 1
          0000111110101010 test 2
Excel   =    011111000111 (using 5.00)
             011111010111 (using 4.96)


*** Results ***

*** Start testing MCP3201 ADC ***

5V0

ADC output byte 1 =  00011111
ADC output byte 2 =  11110010

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

0V

ADC output byte 1 =  00000000
ADC output byte 2 =  00000010

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

3.26V

ADC output byte 1 =  00010100
ADC output byte 2 =  11111101

*** Stop testing MCP3201 ***


*** Stop Program ***

*** Start testing MCP3201 ADC ***

2.43V

ADC output byte 1 =  00001111
ADC output byte 2 =  10100111

*** Stop testing MCP3201 ***


*** Stop Program ***



*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00001111
ADC output byte 2 =  10101010

*** Stop testing MCP3201 ***


*** Stop Program ***


.END



Tuesday, May 07, 2013 MCP3201 conversion accuracy confirmed 0.2%

Now I have tidied up the messy wiring of the MCP3201 board, and then tested again, with the following conditions.

Vcc = 4.95V
Vref = 4.95V
Vin- = 0V
Vin+ = 2.37V

I tested 5 times to check if the output is stable.


Test 01 00001111 01011010
Test 02 00001111 01011000
Test 03 00001111 01011000
Test 04 00001111 01011010
Test 05 00001111 01010111

I found the worst case accuracy is 4 bits / 12 bits or 16/4096 == 0.4%, average is 3 bits or 8/4096 = 0.2%

Then I compared the converted output with the Excel worksheet which is 0x7a9


Test 01 00001111 01011010
Test 02 00001111 01011000
Test 03 00001111 01011000
Test 04 00001111 01011010
Test 05 00001111 01010111
Excel      01111 0101001

Then I found that I made a mistake earlier, of miscounting the 12 digits to 13.  So the worst and average accuracy should be 3/4096 and 2/4096 == 0.2% and 0.04%.

And comparing to Excel, the accuracy is 3 bits, or 0.2%.

In other words, retesting confirms MCP3201 accuracy as 3 bits out of 12, or 0.2%.

****************************************************************

$ sudo python fl2067.py

fl2067.py:268: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  setupOutputPin = lambda oPin: GPIO.setup(oPin, GPIO.OUT) # set GPIO pin as output
fl2067.py:270: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  setupInputPinWithPullUp = lambda iPin: GPIO.setup(iPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # set GPIO pin as input, with pull up

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00001111
ADC output byte 2 =  01011010

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00001111
ADC output byte 2 =  01011000

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py/
python: can't open file 'fl2067.py/': [Errno 20] Not a directory
pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00001111
ADC output byte 2 =  01011000

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00001111
ADC output byte 2 =  01011010

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $ sudo python fl2067.py

*** Start Program - MCP3201 ADC 01   ***


*** Start testing MCP3201 ADC ***

ADC output byte 1 =  00001111
ADC output byte 2 =  01010111

*** Stop testing MCP3201 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_guzuntypi $

.END



Tuesday, May 07, 2013 MCP3201 worst case / average accuracy using Vref = 3.26V

I tested with Vref = 3.26V.

Vref = 3.26V

Test 01 = 0001010100011101
Test 02 = 0001010100011010
Test 03 = 0001010100001110
Test 04 = 0001010100011101
Test 05 = 0001010100011010
Excel   =    101010001010

Again the worst case / average is 4/3 bits over 12 bits, again under 0.2%.

.END



Tuesday, May 07, 2013 MCP3201 testing notes

Now I have assembled a KA431 based regulator as the reference voltage for the MCP3201.  The adjustable range is around 2.8V to 4.5V.  The KA431 seems to be saturated around 4.5V and could not be adjusted higher than 4.5V, unless I think the Vcc increased from 5V to 6V or 7V.

Next step is to change the program to print decimal values.

.END



Tuesday, May 07, 2013 MCP3201 ADC accuracy to 2 decimal places

I have added the weighted sum of the two bytes from MCP3201, proportion it to full range of 4.10V and print the results.

I then input the analog voltage 3.26V, 2.37V, and 4.10V to check if MCP3201 can do the ADC accurately.  Indeed it does.


Analog voltage =  3.26518554687

Analog voltage =  2.37431640625
Analog voltage =  4.09899902344

And the accuracy is to 2 decimal places.


def TestMcp3201():

    PrintDoubleSpaceLine("*** Start testing MCP3201 ADC ***")

    spiGuzuntyPi = spidev.SpiDev()
    spiGuzuntyPi.open(0, 0)

    DummyDoubleByteList = [0x00, 0x00]
    adcOutputDoubleByteList = [0x55, 0x55]
    adcOutputDoubleByteList = spiGuzuntyPi.xfer2(DummyDoubleByteList)

    PrintEightBitPattern("ADC output byte 1 = ", adcOutputDoubleByteList[0])
    PrintEightBitPattern("ADC output byte 2 = ", adcOutputDoubleByteList[1])

    adcDecimalValue = (adcOutputDoubleByteList[1] >> 1) + (adcOutputDoubleByteList[0] * (2 ** 7))

    adcAnalogVoltage = (float(adcDecimalValue) / 4096) * 4.10
 
    print "Analog voltage = ", adcAnalogVoltage

    spiGuzuntyPi.close()

    PrintDoubleSpaceLine("*** Stop testing MCP3201 ***")




Wednesday, May 08, 2013 MCP3201 setup notes

Now I have assembled a voltage divider to divided the input analogue voltage by half, so that input greater than the reference voltage 4.10V will not be over ranged.  So 5V will be divided to become 2.5V etc.

I need to double the calculated value in the final step, as listed below.



    spiGuzuntyPi = spidev.SpiDev()
    spiGuzuntyPi.open(0, 0)

    DummyDoubleByteList = [0x00, 0x00]
    adcOutputDoubleByteList = [0x55, 0x55]
    adcOutputDoubleByteList = spiGuzuntyPi.xfer2(DummyDoubleByteList)

    PrintEightBitPattern("ADC output byte 1 = ", adcOutputDoubleByteList[0])
    PrintEightBitPattern("ADC output byte 2 = ", adcOutputDoubleByteList[1])

    adcDecimalValue = (adcOutputDoubleByteList[1] >> 1) + (adcOutputDoubleByteList[0] * (2 ** 7))

    # adcAnalogVoltage = (float(adcDecimalValue) / 4096) * 4.10 # without half voltage divider
    adcAnalogVoltage = ((float(adcDecimalValue) / 4096) * 4.10) * 2 # with half voltage divider

    print "Analog voltage = ", adcAnalogVoltage

When the dual digital potentiometer arrives, I think I will try some auto ranging as well.


.END












*** Digital Potentiometer Notes ********************************************************

Monday, May 06, 2013 MICROCHIP MCP4151-503E/P Digital Potentiometer learning notes

Now I am thinking of playing with digital potentiometer, instead of using KA431.

MICROCHIP MCP4151-503E/P  (Element14 - HK$7.64)

MicroChip MCP413X/415X/423X/425X 7/8-Bit Single/Dual SPI Digital POT with Volatile Memory

Description

The MCP41XX and MCP42XX devices offer a wide range of product offerings using an SPI interface. This family of devices support 7-bit and 8-bit resistor networks, and Potentiometer and Rheostat pinouts.

Description: IC, DGTL POT, SNGL, 50K, SPI, 8DIP; End To End Resistance:50kohm; Track Taper:Linear; Resistance Tolerance:± 20%; Supply Voltage Min:1.8V; Supply Voltage Max:5.5V; Potentiometer IC Case Style:DIP; No. of Pins:8; No. of S

8.0 APPLICATIONS EXAMPLES

Digital potentiometers have a multitude of practical uses in modern electronic circuits. The most popular uses include precision calibration of set point thresholds, sensor trimming, LCD bias trimming, audio attenuation, adjustable power supplies, motor control overcurrent trip setting, adjustable gain amplifiers and offset trimming. The MCP413X/415X/423X/425X devices can be used to replace the common mechanical trim pot in applications where the operating and terminal voltages are within CMOS process limitations (VDD = 2.7V to 5.5V).

Title Literature

AN1080 Understanding Digital Potentiometers Resistor Variations DS01080

AN737 Using Digital Potentiometers to Design Low Pass Adjustable Filters DS00737

AN692 Using a Digital Potentiometer to Optimize a Precision Single Supply Photo Detect DS00692

AN691 Optimizing the Digital Potentiometer in Precision Circuits DS00691

AN219 Comparing Digital Potentiometers to Mechanical Potentiometers DS00219

— Digital Potentiometer Design Guide DS22017

— Signal Chain Design Guide DS21825

.END



Tuesday, May 07, 2013 Digital Potentiometer learning notes

AN219 Comparing Digital Potentiometers to Mechanical Potentiometers

http://ww1.microchip.com/downloads/en/AppNotes/00219.pdf

Author: Bonnie C. Baker, Microchip Technology Inc

INTRODUCTION

Resistor potentiometers can be found in electronic circuits across a wide spectrum of applications. Most typically, they function in a voltage divider configuration in order to execute various types of tasks, such as offset or gain adjust. The two types of potentiometers compared in this application note are the mechanical potentiometer (also called a trimmer potentiometer) and the digital potentiometer. The physical descriptions and circuit models of these two devices are shown in Figure 1.

Basics of Mechanical Potentiometers

The first type of potentiometer on the market was mechanical in nature. This type of potentiometer is still available and adjustments of the wiper are implemented by twisting a knob, moving a slider, or using a screw driver. Although this method seems awkward, given the advent of the digital potentiometer, mechanical potentiometers still find their way into various electronic circuits.

Earlier mechanical potentiometers were built by wrapping a resistive wire around a cylinder. With this construction, the wiper moves from one winding to the next. As the wiper is moved across the element, there are discrete steps in resistance. Following this style of fabrication, the mechanical potentiometer was built using a resistive thick film that was screened onto a ceramic substrate. With this construction, the change in resistance across the element is continuous.

There are a variety of resistive materials that are used by mechanical potentiometer manufacturers. They include molded conductive plastic, conductive plastic film, screened conductive plastic, and cermet. Each resistive material has its own set of performance characteristics. In this application note the digital potentiometer will only be compared to the more popular cermet potentiometer. Cermet is a thick film resistive material that is a mixture of fine particles of ceramic or glass and precision metals such as silver, platinum, rhodium, or gold.

The wiper of the mechanical potentiometer slides along the distance on the resistive material providing an analog resistive output that has an infinite number of positions across the span of the element.

The metal contacts of the mechanical potentiometer can affect the performance and reliability of the device.

Higher cost potentiometers use multi-fingers made from precious metals in order to promote longer life as well as improve electrical performance in all environments. These higher quality potentiometers are not included in the discussions in this application note.

Basics of Digital Potentiometers

Digital potentiometers (Figure 2) were introduced in the market after the mechanical potentiometer. The digital potentiometer is fabricated using the same silicon technology used in active analog and digital integrated circuits use. This device comprises a combination of segmented resistive elements and on-chip switches.

The resistive elements are manufactured using standard p-type silicon diffusions. Each resistive element can be switched from one side to the other side of the wiper using a serial digital command.

The digital potentiometer exhibits the same fundamental operation as the mechanical potentiometer with one primary exception. The wiper position is digitally programmed with a microcontroller. This style of adjustment allows the designer to adjust circuit performance dynamically using a digital controller. The additional programmability provides a solution where human intervention is not required. With this “hands-off” programmability, the digital potentiometer offers significant flexibility for a variety of applications.

Because this system is digital, the number of wiper positions is no longer infinite. For example, Microchip’s MCP41XXX and MCP42XXX family of potentiometers are all 8-bit and have 256 unique linear positions along the total resistive element.

Beyond the basic differences in fabrication and functionality of these two styles of potentiometers, there are several specifications that describe the difference and similarities of these devices further.

...

.END


Tuesday, May 07, 2013 MCP4151 learning notes

Now I have skimmed through the 4 or 5 application notes to get a rough idea of what is a digital potentiometer.  Actually what I wish to clarify is what is the difference between a potentiometer and a rheostat.  I remember I read the term rheostat in school physics but I don't know how to pronounce it.  So I might not have play with it in school or college.

Now I know that rheostat and voltage divider are two different uses or modes of a potentiometer.  I think voltage divider is almost always used, and rheostat very very seldom, so that is why I don't know what a rheostat is.

Anyway, now I also know the basic theory of digital potentiometer, and that MCP4151 should have two pots inside the chip.

.END



Tuesday, May 07, 2013 MCP4151 Datasheet reading notes

Microchip MCP413X/415X/423X/425X  7/8-Bit Single/Dual SPI Digital POT with Volatile Memory

Features

• Single or Dual Resistor Network options

• Potentiometer or Rheostat configuration options

• Resistor Network Resolution

- 7-bit: 128 Resistors (129 Steps)

- 8-bit: 256 Resistors (257 Steps)

• RAB Resistances options of:

- 5kΩ

- 10kΩ

- 50kΩ

- 100 kΩ

• Zero Scale to Full-Scale Wiper operation

• Low Wiper Resistance: 75Ω (typical)

• Low Tempco:

- Absolute (Rheostat): 50 ppm typical
(0°C to 70°C)

- Ratiometric (Potentiometer): 15 ppm typical

• SPI Serial Interface (10 MHz, modes 0,0 & 1,1)

- High-Speed Read/Writes to wiper registers

- SDI/SDO multiplexing (MCP41X1 only)

• Resistor Network Terminal Disconnect Feature

via:

- Shutdown pin (SHDN)

- Terminal Control (TCON) Register

• Brown-out reset protection (1.5V typical)

• Serial Interface Inactive current (2.5 uA typical)

• High-Voltage Tolerant Digital Inputs: Up to 12.5V

• Supports Split Rail Applications

• Internal weak pull-up on all digital inputs

• Wide Operating Voltage:

- 2.7V to 5.5V - Device Characteristics

Specified

- 1.8V to 5.5V - Device Operation

• Wide Bandwidth (-3 dB) Operation:

- 2 MHz (typical) for 5.0 kΩ device

• Extended temperature range (-40°C to +125°C)

Description

The MCP41XX and MCP42XX devices offer a wide range of product offerings using an SPI interface. This family of devices support 7-bit and 8-bit resistor
networks, and Potentiometer and Rheostat pinouts.


4.0 FUNCTIONAL OVERVIEW

This Data Sheet covers a family of thirty-two Digital Potentiometer and Rheostat devices that will be referred to as MCP4XXX. The MCP4XX1 devices are
the Potentiometer configuration, while the MCP4XX2 devices are the Rheostat configuration.

As the Device Block Diagram shows, there are four main functional blocks. These are:

• POR/BOR Operation

• Memory Map

• Resistor Network

• Serial Interface (SPI)

The POR/BOR operation and the Memory Map are discussed in this section and the Resistor Network and SPI operation are described in their own sections. The
Device Commands commands are discussed in Section 7.0.

5.2 Wiper

Each tap point (between the RS resistors) is a connection point for an analog switch. The opposite side of the analog switch is connected to a common
signal which is connected to the Terminal W (Wiper) pin.

A value in the volatile wiper register selects which analog switch to close, connecting the W terminal to the selected node of the resistor ladder.

The wiper can connect directly to Terminal B or to Terminal A. A zero-scale connections, connects the Terminal W (wiper) to Terminal B (wiper setting of
000h). A full-scale connections, connects the Terminal W (wiper) to Terminal A (wiper setting of 100h or 80h).

In these configurations the only resistance between the Terminal W and the other Terminal (A or B) is that of the analog switches.

A wiper setting value greater than full-scale (wiper setting of 100h for 8-bit device or 80h for 7-bit devices) will also be a Full-Scale setting (Terminal W (wiper) connected to Terminal A). Table 5-1 illustrates the full wiper setting map.

Equation 5-2 illustrates the calculation used to determine the resistance between the wiper and terminal B.


A POR/BOR event will load the Volatile Wiper register value with the default value. Table 5-2 shows the default values offered.



6.0 SERIAL INTERFACE (SPI)

The MCP4XXX devices support the SPI serial protocol. This SPI operates in the slave mode (does not generate the serial clock).

The SPI interface uses up to four pins. These are:

• CS - Chip Select

• SCK - Serial Clock

• SDI - Serial Data In

• SDO - Serial Data Out

Typical SPI Interfaces are shown in Figure 6-1. In the SPI interface, The Master’s Output pin is connected to the Slave’s Input pin and the Master’s Input pin is connected to the Slave’s Output pin.

The MCP4XXX SPI’s module supports two (of the four) standard SPI modes. These are Mode 0,0 and 1,1.

The SPI mode is determined by the state of the SCK pin (VIH or VIL) on the when the CS pin transitions from inactive (VIH) to active (VIL or VIHH).

All SPI interface signals are high-voltage tolerant.


6.1.3.1 SDI/SDO Operation

Figure 6-2 shows a block diagram of the SDI/SDO pin. The SDI signal has an internal “smart” pull-up. The value of this pull-up determines the frequency that data can be read from the device. An external pull-up can be added to the SDI/SDO pin to improve the rise time and therefore improve the frequency that data can be read.

Data written on the SDI/SDO pin can be at the maximum SPI frequency.

On the falling edge of the SCK pin during the C0 bit (see Figure 7-1), the SDI/SDO pin will start outputting the SDO value. The SDO signal overrides the control of the smart pull-up, such that whenever the SDI/SDO pin is outputting data, the smart pull-up is enabled.

The SDI/SDO pin will change from an input (SDI) to an output (SDO) after the state machine has received the Address and Command bits of the Command Byte. If
the command is a Read command, then the SDI/SDO pin will remain an output for the remainder of the command. For any other command, the SDI/SDO pin
returns to an input.

FIGURE 6-2: Serial I/O Mux Block Diagram.

Note: MCP41X1 Devices Only .

Note: To support the High voltage requirement of the SDI function, the SDO function is an open drain output.

Note: Care must be take to ensure that a Drive conflict does not exist between the Host Controllers SDO pin (or software SDI/SDO pin) and the MCP41x1 SDI/SDO pin (see Figure 6-1).


6.2 The SPI Modes

The SPI module supports two (of the four) standard SPI modes. These are Mode 0,0 and 1,1. The mode is determined by the state of the SDI pin on the rising
edge of the 1st clock bit (of the 8-bit byte).

6.2.1 MODE 0,0

In Mode 0,0: SCK idle state = low (VIL), data is clocked in on the SDI pin on the rising edge of SCK and clocked out on the SDO pin on the falling edge of SCK.

6.2.2 MODE 1,1

In Mode 1,1: SCK idle state = high (VIH), data is clocked in on the SDI pin on the rising edge of SCK and clocked out on the SDO pin on the falling edge of SCK.

6.3 SPI Waveforms

Figure 6-3 through Figure 6-8 show the different SPI command waveforms. Figure 6-3 and Figure 6-4 are read and write commands. Figure 6-5 and Figure 6-6
are read commands when the SDI and SDO pins are multiplexed on the same pin (SDI/SDO). Figure 6-7 and Figure 6-8 are increment and decrement commands.


7.0 DEVICE COMMANDS

The MCP4XXX’s SPI command format supports 16 memory address locations and four commands. Each command has two modes. These are:

• Normal Serial Commands

• High-Voltage Serial Commands

Normal serial commands are those where the CS pin is driven to VIL. High Voltage Serial Commands, CS pin is driven to VIHH, for compatibility with systems that also support the MCP414X/416X/424X/426X devices. High Voltage Serial Commands operate identically to their corresponding Normal Serial Command. In each
mode, there are four possible commands. These commands are shown in Table 7-1.

The 8-bit commands (Increment Wiper and Decrement Wiper commands) contain a Command Byte, see Figure 7-1, while 16-bit commands (Read Data and Write Data commands) contain a Command Byte and a Data Byte. The Command Byte contains two data bits, see Figure 7-1.

Table 7-2 shows the supported commands for each memory location and the corresponding values on the SDI and SDO pins.

Table 7-3 shows an overview of all the SPI commands and their interaction with other device features.


7.1 Command Byte

The Command Byte has three fields, the Address, the Command, and 2 Data bits, see Figure 7-1. Currently only one of the data bits is defined (D8). This is for the Write command.

The device memory is accessed when the master sends a proper Command Byte to select the desired operation. The memory location getting accessed is
contained in the Command Byte’s AD3:AD0 bits. The action desired is contained in the Command Byte’s C1:C0 bits, see Table 7-1. C1:C0 determines if the
desired memory location will be read, written, Incremented (wiper setting +1) or Decremented (wiper setting -1). The Increment and Decrement commands
are only valid on the volatile wiper registers.

As the Command Byte is being loaded into the device (on the SDI pin), the device’s SDO pin is driving. The SDO pin will output high bits for the first six bits of that command. On the 7th bit, the SDO pin will output the CMDERR bit state (see Section 7.3 “Error Condition”).

The 8th bit state depends on the the command selected.

TABLE 7-1: COMMAND BIT OVERVIEW

FIGURE 7-1: General SPI Command Formats.

C1:C0 Bit

States Command # of Bits

11 Read Data 16-Bits

00 Write Data 16-Bits

01 Increment 8-Bits

10 Decrement 8-Bits


7.2 Data Byte

Only the Read Command and the Write Command use the Data Byte, see Figure 7-1. These commands concatenate the 8-bits of the Data Byte with the one
data bit (D8) contained in the Command Byte to form 9-bits of data (D8:D0). The Command Byte format supports up to 9-bits of data so that the 8-bit resistor
network can be set to Full-Scale (100h or greater). This allows wiper connections to Terminal A and to Terminal B.

The D9 bit is currently unused, and corresponds to the position on the SDO data of the CMDERR bit.


7.4 Continuous Commands

The device supports the ability to execute commands continuously. While the CS pin is in the active state (VIL or VIHH). Any sequence of valid commands may be received.

The following example is a valid sequence of events:

1. CS pin driven active (VIL or VIHH).

2. Read Command.

3. Increment Command (Wiper 0).

4. Increment Command (Wiper 0).

5. Decrement Command (Wiper 1).

6. Write Command.

7. Write Command.

8. CS pin driven inactive (VIH).

TABLE 7-3: COMMANDS

Note

1: It is recommended that while the CS pin is active, only one type of command should be issued. When changing commands, it is recommended to take the CS pin inactive then force it back to the activestate.

2: It is also recommended that long command strings should be broken down into shorter command strings. This reduces the probability of noise on the
SCK pin corrupting the desired SPI command string.

Command Name # of Bits High Voltage (VIHH) on CS pin?
Write Data 16-Bits —
Read Data 16-Bits —
Increment Wiper 8-Bits —
Decrement Wiper 8-Bits —
High Voltage Write Data 16-Bits Yes
High Voltage Read Data 16-Bits Yes
High Voltage Increment Wiper 8-Bits Yes
High Voltage Decrement Wiper 8-Bits Yes


7.5 Write Data Normal and High Voltage

...


7.6 Read Data Normal and High Voltage

...


7.7 Increment Wiper Normal and High Voltage

...


7.7.2 CONTINUOUS INCREMENTS Continuous Increments are

...


7.8 Decrement Wiper Normal and High Voltage

...


7.8.2 CONTINUOUS DECREMENTS

Continuous Decrements are possible only when writing to the wiper registers. Figure 7-9 shows a continuous Decrement sequence for three continuous writes. The writes do not need to be to the same volatile memory address.

When executing an continuous Decrement commands, the selected wiper will be altered from n to n-1 for each Decrement command received. The wiper value will
decrement from the wipers Full-Scale value (100h on 8-bit devices and 80h on 7-bit devices). Above the wipers Full-Scale value (8-bit =101h to 1FFh,
7-bit = 81h to FFh), the decrement command is disabled. If the Wiper register has a Zero Scale value (000h), then the wiper value will not decrement. See
Table 7-4 for additional information on the Decrement Command vs. the current volatile wiper value.

Decrement commands can be sent repeatedly without raising CS until a desired condition is met. The value in the Volatile Wiper register can be read using a Read Command.

When executing a continuous command string, The Decrement command can be followed by any other valid command.

The wiper terminal will move after the command has been received (8th clock).

After the wiper is decremented to the desired position, the CS pin should be forced to VIH to ensure that “unexpected” transitions (on the SCK pin do not cause the wiper setting to change). Driving the CS pin to VIH should occur as soon as possible (within device specifications) after the last desired decrement occurs.


8.0 APPLICATIONS EXAMPLES

Digital potentiometers have a multitude of practical uses in modern electronic circuits. The most popular uses include precision calibration of set point thresholds, sensor trimming, LCD bias trimming, audio attenuation, adjustable power supplies, motor control overcurrent trip setting, adjustable gain amplifiers and offset trimming.

The MCP413X/415X/423X/425X devices can be used to replace the common mechanical trim pot in applications where the operating and terminal voltages are within CMOS process limitations (VDD = 2.7V to 5.5V).

8.2 Techniques to force the CS pin to VIHH

The circuit in Figure 8-3 shows a method using the TC1240A doubling charge pump. When the SHDN pin is high, the TC1240A is off, and the level on the CS pin
is controlled by the PIC® microcontrollers (MCUs) IO2 pin.

When the SHDN pin is low, the TC1240A is on and the VOUT voltage is 2 * VDD. The resistor R1 allows the CS pin to go higher than the voltage such that the PIC MCU’s IO2 pin “clamps” at approximately VDD.

...


8.4.1 POWER SUPPLY CONSIDERATIONS

The typical application will require a bypass capacitor in order to filter high-frequency noise, which can be induced onto the power supply's traces. The bypass capacitor helps to minimize the effect of these noise sources on signal integrity. Figure 8-6 illustrates an appropriate bypass strategy.
In this example, the recommended bypass capacitor value is 0.1 μF. This capacitor should be placed as close (within 4 mm) to the device power pin (VDD) as
possible.

The power source supplying these devices should be as clean as possible. If the application circuit has separate digital and analog power supplies, VDD and
VSS should reside on the analog plane.

TECHNICAL DOCUMENTATION
..
Application Note Number Title Literature #
AN1080 Understanding Digital Potentiometers Resistor Variations DS01080
AN737 Using Digital Potentiometers to Design Low Pass Adjustable Filters DS00737
AN692 Using a Digital Potentiometer to Optimize a Precision Single Supply Photo Detect DS00692
AN691 Optimizing the Digital Potentiometer in Precision Circuits DS00691
AN219 Comparing Digital Potentiometers to Mechanical Potentiometers DS00219
— Digital Potentiometer Design Guide DS22017
— Signal Chain Design Guide DS21825
MCP4151-503E/P MCP4151: Single Volatile 8-bit Potentiometer (HK$7.64, Element 14)

MCP4151-503E/XX: 50 kΩ, 8LD Device

IC, DGTL POT, SNGL, 50K, SPI, 8DIP; End To End Resistance:50kohm;
Track Taper:Linear; Resistance Tolerance:± 20%;
Supply Voltage Min:1.8V; Supply Voltage Max:5.5V;
Potentiometer IC Case Style:DIP; No. of Pins:8; No. of S

Device MCP4131: Single Volatile 7-bit Potentiometer
MCP4131T: Single Volatile 7-bit Potentiometer (Tape and Reel)
MCP4132: Single Volatile 7-bit Rheostat
MCP4132T: Single Volatile 7-bit Rheostat (Tape and Reel)
MCP4151: Single Volatile 8-bit Potentiometer
MCP4151T: Single Volatile 8-bit Potentiometer (Tape and Reel)
MCP4152: Single Volatile 8-bit Rheostat
MCP4152T: Single Volatile 8-bit Rheostat (Tape and Reel)
MCP4231: Dual Volatile 7-bit Potentiometer
MCP4231T: Dual Volatile 7-bit Potentiometer (Tape and Reel)
MCP4232: Dual Volatile 7-bit Rheostat
MCP4232T: Dual Volatile 7-bit Rheostat (Tape and Reel)
MCP4251: Dual Volatile 8-bit Potentiometer
MCP4251T: Dual Volatile 8-bit Potentiometer (Tape and Reel)
MCP4252: Dual Volatile 8-bit Rheostat
MCP4252T: Dual Volatile 8-bit

Resistance Version:
502 = 5 kΩ
103 = 10 kΩ
503 = 50 kΩ
104 = 100 kΩ

Temperature Range
I = -40°C to +85°C (Industrial)
E = -40°C to +125°C (Extended)

Package
MF = Plastic Dual Flat No-lead (3x3 DFN), 8/10-lead
ML = Plastic Quad Flat No-lead (QFN), 16-lead
MS = Plastic Micro Small Outline (MSOP), 8-lead
P = Plastic Dual In-line (PDIP) (300 mil), 8/14-lead
SN = Plastic Small Outline (SOIC), (150 mil), 8-lead
SL = Plastic Small Outline (SOIC), (150 mil), 14-lead
ST = Plastic Thin Shrink Small Outline (TSSOP), 14-lead
UN = Plastic Micro Small Outline (MSOP), 10-lead

8-Lead PDIP
XXXXXXXX
XXXXXNNN
YYWW

Legend: XX...X Customer-specific information
Y Year code (last digit of calendar year)
YY Year code (last 2 digits of calendar year)
WW Week code (week of January 1 is week ‘01’)
NNN Alphanumeric traceability code
...

.END



Wednesday, May 08, 2013 MCP4151's scary SDI/SDO multiplexing thing.

Yesterday when I read the MCP4151 datasheet, I found a strange thing called SDI/SDO multiplexing.


*** From MCP4151 datasheet ***

SDI/SDO multiplexing (MCP41X1 only)


3.3 Serial Data In / Serial Data Out (SDI/SDO)

On the MCP41X1 devices, pin-out limitations do not allow for individual SDI and SDO pins. On these devices, the SDI and SDO pins are multiplexed.

The MCP41X1 serial interface knows when the pin needs to change from being an input (SDI) to being an output (SDO). The Host Controller’s SDO pin must be properly protected from a drive conflict.

*** End MCP4151 datasheet ***

I think this is scary, because any careless mistake might cause white smoke rising at my RPi.  This is for sure not for SPI newbies.

So I decided not to touch this SDI/SDO multiplexing MCP4151.  I visited MCP and found they has MCP4251 which is not SDI/SDO multiplexed.  TaoBao sells for RMB10 each.  I think this is safer for newbies messing with.  So I bid a couple of them.

.END






































Now I have inserted the MCP3201 ADC into the breadboard.  The interface to RPi is SPI channel 0. The power 3V3 is from the external power supply which also drives the Guzunty Pi.

Next step is to test the MCP3201.

.END

No comments:

Post a Comment