ADC Pi Plus channel switch timeout
The ADC Pi is an Analogue to Digital converter for the Raspberry Pi
02/02/2016
Posted by:
johnm
This is what I do (pseudo) :
write(1001 0000); //channel 1, continuous mode, PGA1, 12bit resolutionread(); //Reading 4 bytes, loop untill highest bit of 4th byte is '1', then use first 2 bytes as the 'value'write(1011 0000); //channel 2, continuous mode, PGA1, 12bit resolutionread(); //Reading 4 bytes, loop untill highest bit of 4th byte is '1'
=>last read would still return the value from channel 1 allthought we switched to channel 2
write(1001 0000); //channel 1, continuous mode, PGA1, 12bit resolutionread(); //Reading 4 bytes, loop untill highest bit of 4th byte is '1'write(1011 0000); //channel 2, continuous mode, PGA1, 12bit resolutionwait(100msec)read(); //Reading 4 bytes, loop untill highest bit of 4th byte is '1'
=>last read now returns value of channel2
So, am I doing something wrong or is there a way of reading the status after a channel switch to see when it is ready? Imho waiting an arbitrary amount of msecs feels a bit fishy, also in the original perl sample there seems to be no need for it.
Secondly, what is bit 7 doing in the config? In the perl script it seems to be initialized on '1' (the initial config is 0x9C) and stays on that value. Only when switching to single shot it is set to 1 (which has no use, since it is already 1?) but then after writing it is set to 0 again.
Thanks!
03/02/2016
Posted by:
andrew
Bit 7 of the config byte, which is the last byte returned, is the Ready Bit which the ADC uses to show when a sample is ready to be used. To initiate a new read on the ADC you have to set the Ready Bit to 1 in the config and write that to the ADC. You then have to keep reading from the ADC until the ready bit returns as 0. When it is 0 that means the last set of bytes you read from the ADC contains the new voltage value. Page 17 of the MCP3424 datasheet describes how the ready bit works in more detail.
If you look at the python library from lines 141 to 154 you can see that there is a while loop which reads the bytes from the ADC and then checks the status of bit 7 in the config byte. The while loop only breaks when bit 7 is returned as 0.
Hopefully, if you add this while loop into your java code it will return the correct values.
03/02/2016
Posted by:
johnm
Just for the record (I don't have the board here atm): is the laste byte returned a copy of the config byte ? So is this reflecting the config the ADC is actually using at that time?
03/02/2016
Posted by:
andrew
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.