MAX1270 12-bit A/D Converter
RClemons
Posts: 3
I'm using the MAX1270 to read voltage data ranging from 0-3V on the first 3 channels (0-2), and using a BS2p40 as my stamp. When I DEBUG the converted data, I'm getting completely erroneous numbers. I've double and triple checked my wiring on the BS2, as well as monitored the output on my voltage inputs to verify what I should be getting. I believe the problem is in the SHIFTIN portion of my code, as well as how I'm displaying it using the DEBUG command. I've tried a different way to SHIFTIN the data on each channel, hoping that at least one of them is correct, but have still not received the correct numbers.
If anyone has used the MAX1270 and can post code that worked for them, it would be much appreciated. Or, if you have experience using the SHIFTIN/SHIFTOUT commands, or combining the HIGHBYTE and LOWBYTE of a variable, you might be able to assist in helping me solve this problem.
The code "TC_read_parallax.bsp" is attached.
Thank you.
Richard Clemons
HRL Laboratories
If anyone has used the MAX1270 and can post code that worked for them, it would be much appreciated. Or, if you have experience using the SHIFTIN/SHIFTOUT commands, or combining the HIGHBYTE and LOWBYTE of a variable, you might be able to assist in helping me solve this problem.
The code "TC_read_parallax.bsp" is attached.
Thank you.
Richard Clemons
HRL Laboratories
Comments
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM1}
'*******************************************************************************************
'A/D Config words
'*******************************************************************************************
'control byte format
'*******************************************************************************************
'Bit 7 (MSB) must be HIGH
'Bits 6(MSB),5 and 4(LSB) are the channel select
'bits 3 and 2 are the Range and BIPolar bits we'll set both to 0 for 0-5 V,unipolar
'bits 1 and 0 are the Power Down bits and we'll set them to 0 and 0 respectively,
'for normal operation with an internal clock.
'A/D Control words are CHRead(0-7)
'*******************************************************************************************
'*******************************************************************************************
'Variable declarations
'*********************************************************************************************
··· CfgByte······ VAR······ Word··········· 'A/D configuration word
··· AnaDat······· VAR······ Word(8)········ 'array for data read from the A/D
··· counter······ VAR······ Word
··· x············ VAR······ Byte··········· 'Loop counter
··· EEAddr······· VAR······ Word
'Syntax : read location, Variable
'Syntax : READ Location, {Word} Variable {, {Word} Variable, ...}
'*******************************************************************************************
'Declare Constants
'*******************************************************************************************
··· SSTROB··· CON······ 0················· 'Var· con PIN#
··· SerDat··· CON······ 2
··· Clock···· CON······ 3
··· SelAD···· CON······ 4
'**********************************************************************************************
Main:··· GOSUB GetDat
········ GOSUB ShowDat
GetDat:
············ x=-1
·········· FOR CfgByte=$80 TO $F0 STEP $10
·················· x=x+1
·················· LOW Clock······································ 'Control Byte is Clocked in on rising edge of clockincrements the array index
·················· LOW SelAD
·················· SHIFTOUT SerDat,Clock,MSBFIRST,[noparse][[/noparse]CfgByte\8]····· 'this tells the A/D what channel to read
·················· LOW Clock······································· 'Data sheet says to keep clock low
··································································· 'Note that A/D is selected from config byte
··································································· 'until after data is read. Clock is held low
··································································· 'after the data is read from A/D
··································································· 'See Data Sheet page 12 of 20 in Adobe format
··································································· ' Data sheet downloaded from Parallaxinc.com
·················· SHIFTIN· SerDat,Clock,MSBPRE,[noparse][[/noparse]AnaDat(x)\12]····· 'Store analog values in the AnaDat array
·················· HIGH SelAD
·················· DEBUG ? x
··········· NEXT
············ RETURN
ShowDat:
········ FOR X = 0 TO 7
············ DEBUG ? AnaDat(X)[noparse]:D[/noparse]EBUG "· ": DEBUG ?x,CR
········ NEXT
········ PAUSE 1000
········ DEBUG CLS
········ GOTO main
Post Edited (Philip Gamblin) : 2/11/2006 9:50:37 PM GMT