Pages

Tuesday, May 28, 2013

MCP3208 testing notes

Now I have added to Channel 7 a 10K + 10K voltage divider to divide by 2 input voltages higher than 5V.  So resultDecimal for Channel 7 will scale up by 2: 

        resultDecimal =  ((resultTripleByte[1] & 0x0f) * (2 ** 8)) + (resultTripleByte[2])
if (channelNumber == 7):
            resultDecimal *= ChannelScale7  

*** Start Program - FongToy v1.26 tlfong01 2013may28 ***


*** Start testing MCP3208 ADC ***

Analog voltage at channel number  0  =  2.499
Analog voltage at channel number  1  =  2.499
Analog voltage at channel number  2  =  2.499
Analog voltage at channel number  3  =  2.499
Analog voltage at channel number  4  =  2.499
Analog voltage at channel number  5  =  0.0
Analog voltage at channel number  6  =  3.303
Analog voltage at channel number  7  =  5.266 5V0 PSU actually is 5V266

*** Stop testing MCP3208 ***

*** Stop Program ***

def TestMcp3208v03(): # v1.5 tlfong01 2013may28

    ftprint.PrintDoubleSpaceLine("*** Start testing MCP3208 ADC ***")   

    spiChannel = spidev.SpiDev() 
    spiChannel.open(0, 1)  

    SingleEndMode = 0
    DifferentialMode = 1
    SingleEndModeFirstByte = 0x06
    DifferentialModeFirstByte = 0x04
    ChannelScale7 = 2

    controlTripleByte = [0x00, 0x00, 0x00]
    resultTripleByte = [0x00, 0x00, 0x00]

    for channelNumber in range(0, 8, 1):
        controlTripleByte[0] = SingleEndModeFirstByte | (channelNumber >> 2)
        controlTripleByte[1] = channelNumber << 6
        controlTripleByte[2] = 0x00 # don't care, actually
        resultTripleByte = spiChannel.xfer2(controlTripleByte) 

# ftprint.PrintEightBitPattern("ADC output byte 0 = ", resultTripleByte[0])
# ftprint.PrintEightBitPattern("ADC output byte 0 = ", resultTripleByte[1])
        # ftprint.PrintEightBitPattern("ADC output byte 0 = ", resultTripleByte[2])

        resultDecimal =  ((resultTripleByte[1] & 0x0f) * (2 ** 8)) + (resultTripleByte[2])
if (channelNumber == 7):
            resultDecimal *= ChannelScale7
# print "resultDecimal = ", resultDecimal

        resultVoltage = (float(resultDecimal) / 4096) * 4.096     
        print "Analog voltage at channel number ", channelNumber, " = ", resultVoltage

    spiChannel.close() 

    ftprint.PrintDoubleSpaceLine("*** Stop testing MCP3208 ***")

.END




No comments:

Post a Comment