Finding that the 10 bit ADCs in the AVRs are just not enough for most of my projects I have been looking for a while for an ADC that is similar to the AVRs but more bits (12 or better) I have tried over sampling but still it was not good enough the best I could get was 3 stable digits no good if I wanted to measure 12.45 Volts or worse still with an analog sensor with 2.453 Volts so recently I saw one at a low cost (on special) the MAX1238 this is a 12 bit, 12 Channel , single ended or differential, I2C buss device. First problem is that its a tiny QSOP package but I found Sparkfun has an adapter PCB ready to go to convert this to 16 pin dip just need a steady hand to solder it and some solder wick to clean up. Next I need to talk to it so read the data sheet, so I read it only to find it half of what I need ok just have to play with it to see what goes.
Step 1: connect it up to an AVR on the I2C buss with resistors fitted.
Step 2: scan the buss to see if it answers back and it did!
Note you can find this in the I2C samples in bascom
Step 3; work out the commands to send to it (read the data sheet again)
Here is some code that works with a lot of the commands to send to the ADC
[code:1:14acfdc00f]
'-----------MAX1238------------------------------------------------------------------------
'--MAX1238 slave address
'--MAX1238 is a 12 bit 12 channel I2C ADC
'--write
'Dim Max1239b As Word
'Dim Max1239lh(2) As Byte At Max1239b Overlay
'Dim Volt As Single
'Const Wrmax1238 = &H6A '&B01101010 write to MAX1238
'--read
'Const Rdmax1238 = &H6B '&B01101011 read from MAX1238
'--setup byte
'use internal reference, internal clock, unipolar mode
'Const Setmax1238 = &HD2 ' &B11010010
'--configuration bytes
'-scan all adc inputs 0 to 11 single ended
'Const Scanall = &H17 '&B00010111
'--convert one ADC channel single ended BINARY VALUE
'Const Scan0 = &H61 '&B01100001 scan adc 0
'Const Scan1 = &H63 '&B01100011 scan adc 1
'Const Scan2 = &H65 '&B01100101 scan adc 2
'Const Scan3 = &H67 '&B01100111 scan adc 3
'Const Scan4 = &H69 '&B01101001 scan adc 4
'Const Scan5 = &H68 '&B01101011 scan adc 5
'Const Scan6 = &H6D '&B01101101 scan adc 6
'Const Scan7 = &H6F '&B01101111 scan adc 7
'Const Scan8 = &H71 '&B01110001 scan adc 8
'Const Scan9 = &H73 '&B01110011 scan adc 9
'Const Scan10 = &H75 '&B01110101 scan adc 10
'Const Scan11 = &H77 '&B01110111 scan adc 11
'--HSmode
'Const Hsmax1238 = &H08 '&B00001000
'-------------------------------------------------------------------------------
'---------------------------------------
'--This sub sets up and reads the values from
'--the MAX1239 12 bit ADC
Sub Max1239_setup
'use internal reference, internal clock, unipolar mode
I2csend Wrmax1238 , Setmax1238
End Sub
Sub Max1239_read
'use internal reference, internal clock, unipolar mode
I2creceive Rdmax1238 , Max1239lh(1)
I2creceive Rdmax1238 , Max1239lh(2)
End Sub
Sub Max1239_write
I2csend Wrmax1238 , Scan0
End Sub
[/code:1:14acfdc00f]
I have it working but need to refine the code more and look into the other modes
Regards Paul
↧