Pages

Wednesday, May 29, 2013

MCP3201 debugging notes

So I did the correction.

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

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


def TestMcp320104(): #v1.4 tlfong01 2013may29

    ftprint.PrintDoubleSpaceLine("*** Start TestMcp320104( ) ***")   

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

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

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

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

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

    # 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

    spiGuzuntyPi.close() 

    ftprint.PrintDoubleSpaceLine("*** Stop  TestMcp320104( ) ***") 


# *** Start Program - FongToy v1.26 tlfong01 2013may28 ***
# *** Start TestMcp320104( ) ***
# ADC output byte 1 =  00001100
# ADC output byte 2 =  11110101
# Analog voltage =  3.31923828125
# *** Stop  TestMcp320104( ) 

.END

No comments:

Post a Comment