MCP3201 Shiftin Issues

chopperwalker

New Member
I have a 20x2 that is interfaced by a 4D LCD through I2C. I also have a MCP3201 that I am trying to shiftin the 12 bit reading off a RTD. SPI would be simple enough if the I2C wasn't using up the lines. My real issue is that my 12 bit data is jumping around. It seems that on start up I am getting the correct value (through debug). I have watched the analog input sit steady. The 12 bit output will cycle about 3-4 random readings before coming around back to what again seems to be the correct reading. For instance, my ADC output should be 3152 at room temp, the analog signal (1.924V)/ref (2.5V)*4096. It will show this value then range from 2000 - 3800 while cycling. I have the same result between to different and new MCP3201 chips.

I have tried Shiftin and a bit-banged method posted here by Jeremy Leach which he adopted from Anderson's site. Both through C.3 since I am running C.0 firmware. I am assuming I have a timing issue. I have racked my brain, on top of it, I have a head cold and can't think anymore. I am hoping for some input here if anyone can spot what I am missing or how to tackle this. Yes, I have read the DS, but my brain is no longer reliable.

Here is my pertinent code:

Code:
#picaxe 20x2                    ' Pick the chip

'----------------------- Inputs
   Symbol HI = C.3

'----------------------- Outputs
   Symbol HCS = C.1
   Symbol Hclk = C.2

'----------------------- Initialize
init:
   let dirsB = %00000000
   let pinsB = %00000000
   let dirsC = %10100111
   let pinsC = %00000000
   let adcsetup = %0000000000000110
   
   setfreq m8    
   
   High HCS
   High Hclk

'----------------------- Main program cycle
main:  
	
	gosub HLT_Temp
	
	pause 1000

goto main


'----------------------- Get HLT Temperature and Store Function
HLT_Temp:

	HLT = 0
	
	Low Hclk
	Low HCS
	
	High Hclk
	Low Hclk
	   
	High Hclk 'Sample begins on first rising edge after /CS goes low
	Low Hclk
	
	High Hclk
	   
	SHIFTIN Hclk,HI,MSBPre_L,(b1/4,b0/8)
	
'	For Counter = 11 to 0 step -1
'		Low Hclk ' gets next data bit
'		High Hclk
'		HLT = HLT * 2 + HI
'	Next

	High HCS
	High Hclk

        debug 

	if HCD = 1 then
		HLT = HLT + H_Cal
	else
		HLT = HLT - H_Cal  	
	endif
	put 2, b0 
	put 3, b1 
	
return
Don't worry, I'm not a student. I'm an ME in need of some EE or CE help. Thank you in advance.
 

inglewoodpete

Senior Member
I would make up several LEDs+current limiting resistors and put one on each data line. Then modify the bit-bang code so that the SPI or i2c runs really slow. Eg 1 or 2 seconds per clock cycle. Then you can see what is working and what is not. ... and then you will know what you have to fix.

Edit: Hmm This chip has a minimum recommended clock speed (see below)! A bit restrictive when using a PICAXE!
 
Last edited:

westaust55

Moderator
The problem is that the particular ADC chip has a minimum clock rate (10 kHz) otherwise errors with data values may occur.

Noted also that after the 12-bit data is sent msb to lsb then if you keep clocking, the same value is then sent lsb to msb flowed by zeros. There is thus an opportunity to clock in the value a second time to see if the two values match.
 

chopperwalker

New Member
At work, but I will try the LED setup later to make sure everything is working right.

So at 8MHz, I should be getting ~2000 basic commands per second. With the High/Low commands triggering the clock, I am at back down to 1kHz speed. I will try to pulsout instead, but that still leaves me back at 2kHz, right?
 
Top