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
No comments:
Post a Comment