Shop OBEX P1 Docs P2 Docs Learn Events
Question for MAX1270 A2D converter — Parallax Forums

Question for MAX1270 A2D converter

EdmondEdmond Posts: 7
edited 2007-11-30 17:22 in BASIC Stamp
Folks :

I am writing a cod for the BS2 to read the digital output from the MAX1270 A2D converter.
My sensor is a position transducer that varies from 0 to 5 (max) volts.

Here is my code :

=====================================
AdcDOUT···· CON 1
SSTRB······ CON 2
AdcDIN····· CON 4
AdcCS······ CON 5
clockpin··· CON 6
controlbyte CON %10000001
sensordata· VAR Word
sensordata = 0
DO
· GOSUB Read_ADC
· GOSUB Display
LOOP

Read_ADC :
· LOW AdcCS
· SHIFTOUT AdcDIN , clockpin, MSBFIRST, [noparse][[/noparse]controlbyte]
· SHIFTIN· AdcDOUT, clockpin, MSBPOST , [noparse][[/noparse]sensordata\12]
· HIGH AdcCS
RETURN
Display :
DEBUG HOME
DEBUG "12-bit binary value : ", BIN12 sensordata, CR
DEBUG "decmial value······ : ", DEC4· sensordata
RETURN
===================================================

For some reason, I don't know why that when my sensor reaches the maximum output (5 volt),
the digital output read only up to 246 (dec), not 4096 (2^16) which I expect to see as this is a 12 bit A2D converter.
I don't know what I did wrong in this.

If any of you have experience on this A2D converter, or this kind of problems, I will appreciate for your input. Thanks !

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-11-30 04:13
    Show us you circuit. I'll let someone else address the code as I'm not real good at that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-11-30 04:52
    The problem may be that the code you posted selects the external clocking mode. Try instead,
    controlbyte CON %10000000 ' internal clocking, 5 volt single ended on channel 0

    The problem with external clocking is twofold. It requires 4 additional conversion clock pulses not present in your code, after the control byte and before the data. Furthermore, the BS2 SHIFTOUT clock is not fast enough to do the external clocking, due to charge leakage from the 1270's internal sampling capacitor. With internal clocking, the '1270 supplies a fast internal clock to do the conversion itself, and your code only has to send the command and read out the data.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • EdmondEdmond Posts: 7
    edited 2007-11-30 05:06
    Hi Tracy :

    I did what you suggested and the mystery is solved !! You are awesome.

    Now the digital output (dec) read up to 3950 when the analog signal close to 5 v (max).
    So the actual voltage measurement is : 5*3950/4960 = 4.82 which is very close to what I measured from the multimeter.

    My question is that when I use internal clock mode, should I keep using the command "SHIFTOUT" & "SHIFTIN" as this command will
    generat the clock pulse and send it to the A2D converter.

    I am confused why my program works when I only change to internal clock mode (" %10000000 " ) while the "SHIFTOUT" and "SHIFTIN"
    command keep sending the clock pulse to the A2D converter?

    Anyway, great thanks for your help !
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-11-30 17:22
    I think your confusion comes from thinking that there is just one clock. There are actually two processes that require clocking, 1) the SHIFTIN and SHIFTOUT of data, and 2) the steps of the successive approximation analog to digital conversion. You will always use the Stamp clock pin for the former, but the MAX1270 gives you a choice of what to use for the conversion clock. When internal mode is selected, an oscillator inside the '1270 starts up right after it receives the command byte, and that internal oscillator drives the conversion and a few microseconds later the result is available for the SHIFTOUT using the normal Stamp clock. In external mode, the same external source drives both the data shifting and the conversion. Why would you want to use one instead of the other? Definitely use the internal mode with the Stamp, because the Stamp Shift clock is not fast enough to get the best accuracy. With a faster processor, the Propeller for example, you might want to use external mode in order to get the fastest possible conversion rate, or to better synchronize the conversion with some external event. All this is detailed in the MAX1270 data sheet.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.