MCP3201 A to D converter - issues

Jeremy Leach

Senior Member
Hi

I'm using this one channel A2D chip to read 12bit readings of atmospheric pressure using an MPX4115 pressure sensor. I'm not feeling too confident of the digital readings though as I get some wierd results just by slight changes to the code. By changes I do't mean anything that changes the logic.

Basically I'd be interested if anyone else has used an MCP3201 and their code. Plus very grateful of any comments on below.

P Anderson has given an article at http://www.phanderson.com/picaxe/spi.html of how to interface this sensor to an 8 channel version of this chip.

The code I've got is as below. My one-channel version works slightly differently (simpler) as it doesn't receive any channel selecting data.

The code changes I've done are around the central for...next loop. There are different ways of acheiving the same theoretical result. e.g instead of WordValue = WordValue * 2 + MISO, can have a test for MISO and then WordValue = WordValue + 1 if MISO = 1 (as per the Shiftin programming examples in the manual). Also, can use Pulseout to generate clock signals. However ALL these varieties give slightly different results of digitised readings.

I'm guessing the differences are due somehow to changing the timing of the clock signals.
The chip spec says that it is important to maintain a minimum clock speed of 10KHz otherwise the sampled voltage will start decaying while the conversion is in progress.

Key questions I've got are:

1. Pulseout. Ok, this command gives a precise pulse in 10us units. However if two pulseout commands were following each other how long would the gap be between pulses?
2. High Sclk, Low Sclk. I've got these commands in rapid sequence. Could this be too rapid? I'd imagine the high and low commands are pretty much the most basic of the picaxe commands and are executed extremely quickly?
3. The pause statement is in milliseconds. Anyone got a reliable way of pausing for a a certain number of uS ? Has anyone done any tests on empty for...next loops? I was thinking of ensuring good/regular waveforms for Sclk by putting in appropriate ,very short pauses.

Actually I've already started experimenting with short pauses in the core loop below. It's strange but the longer the pause the higher the digitised result. I guess this is something to do with the Successive approximations.


GetPressure:
----'Reads the pressure reading from the MCP3201 12 bit A2D converter.

----Symbol BitNumber = b0
----Symbol MISO = Input0

----'Initialise
----Low Sclk
----Low CS 'Enable MCP3201
----WordValue = 0

----'Take a sample
----High Sclk 'Sample begins on first rising edge after /CS goes low
----Low Sclk
----High Sclk
----Low Sclk 'Sample ends on falling edge. Outputs a null bit.
----High Sclk

----'The next 12 clocks will output the result of the conversion with MSB first. Data
----'is always output on the falling edge of the clock.

----For BitNumber = 11 to 0 step -1
--------Low Sclk ' gets next data bit
--------High Sclk
--------WordValue = WordValue * 2 + MISO
----Next

----High CS 'Disable MCP3201

----'Save the result to RAM
----Poke ByteAddress,SV_Pressure
----Gosub PokeWord
Return
 

Jeremy Leach

Senior Member
Hi, just for the records, in case anyone is using an MCP3201 in future.

Now solved the issue. I hadn't read the datasheet properly. I thought the IN- and IN+ were true differential inputs where the IN- could be any voltage. Not so, IN- limited to +/- 100mv of ground. I've now tied IN- to ground, VRef to +5V and it seems to work ok.

Moral of the story (for me at least) - read the datasheets carefully !

Edited by - Jeremy Leach on 4/25/2005 6:21:16 PM
 
Top