Shop OBEX P1 Docs P2 Docs Learn Events
Max1272 in Bipolar mode — Parallax Forums

Max1272 in Bipolar mode

mike.blankenshipmike.blankenship Posts: 4
edited 2013-06-11 19:25 in BASIC Stamp
I am using the the MAX1272 (12 bit AD internal 4.096 ref) This part is able to run in both Uni-polar and Bi-polar mode, however I am having issues in Bi-polar mode.
I can read the data with no problem with the device set to unipolar mode (Thanks to some code from Tracy Allen I found on this site)

The command byte is as follows for Bi-polar mode :

BIT7 BIT6 BIT5 BIT4 BIT3 BIT2 BIT1 BIT0
START RNG BIP PD MODE1 MODE0 RESERVED REF
1 0 1 1 1 1 0 1

BIT7 = 1 START Bit
BIT6 = 0 These next 2 bits sets the device in bi-polar mode Neg FUll scale -Vrf 1.2207 FUll scale Vref 1.2207
BIT5 = 1
BIT4 = 1 These next 3 bits set for normal operation no power down mode
BIT3 = 1
BIT2 = 1
BIT1 = 0 Spec says to write a logic 0
BIT0 = 1 Sets internal 4.096 reference

With the following commands even though Im setup in Bi-polar mode I am still able to get FUll scale resolution from 0 to 5 volts
However in this same mode I am not able to get the converted 2's compliment result (even after converting it back to unsigned decimal)

SHIFTOUT Serdata_out, Sclk, MSBFIRST, [111101] ' Set for BI-POLAR, Internal ref
SHIFTIN Serdata_in,SCLK,MSBPOST,[ADC_RESULT\12]

sign = ADC_RESULT.BIT11 ' Look at the signed bit to see if negative voltage was applied

IF (sign = 1) THEN VALUE = (~ADC_RESULT + 1) ' Ok this is 2's complement now convert back to a value I can read for the negative rail
IF (sign = 1) THEN VALUE = (VALUE ** 14464) * 2 ' Tracy Allens code (I added the * 2 because it made my value come out +- 2 mv from what my scope was saying)

IF (sign = 0) THEN VALUE = (ADC_RESULT + (ADC_RESULT ** 14464)) * 2

DEBUG "ADC Vout ... SBIN = ", BIN VALUE , 13
DEBUG "ADC Vout ... SDEC = ", DEC value , 13

Even though I have the part selected for Bi-polar mode and apply a positive signal I am able to measure all the
way from 0V to 5V. The Bi-polar transfer function shows Full scale between -2.048 and +2.048. so Im thinking in Bi-polar
mode I should only be able to measure up to 2048 steps

When I do place a negative voltage on the input my full scale is ~ 2048 but the volatges I read are way off but the range is ~ 2048.

If anyone has had experience with A/D in bi-polar mode I would appreciate some help.

Thanks

mike

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2013-06-11 12:44
    Hi Mike, welcome to the forums!

    It can help us look at the code blocks if you can attach the program, or follow the advice...
    attachment.php?attachmentid=78421&d=1297987572


    A couple of things look strange in this section:
    [FONT=courier new][SIZE=1]IF (sign = 1) THEN VALUE =  (~ADC_RESULT + 1)  ' Ok this is 2's  complement now convert back to a value I can read for the negative rail
    IF (sign = 1) THEN VALUE =  (VALUE ** 14464) * 2  ' Tracy Allens code (I  added the * 2 because it made my value come out +- 2 mv from what my  scope was saying)[/SIZE][/FONT]
    

    The value returned is already twos complement, and it only needs to have the sign extended from the 12th bit out to all bits to the left, namely nibD.
    [FONT=courier new][SIZE=1]ADC_result.nibD = -ADC_result.bit11[/SIZE][/FONT]
    

    The ** operator doesn't work properly on negative numbers (sign=1), so you have to extract the absolute value, then apply the ** scaling operator, then restore the sign. My memory of that chip is hazy, but the scaling operator does depend on the range selection by a factor of 2.
  • mike.blankenshipmike.blankenship Posts: 4
    edited 2013-06-11 19:25
    Tracy,

    Thanks for your help, it worked like a charm. I am ~ +- 5mv from rail to rail +5 to -5. This will be more then enough resolution
    for my project.

    If anyone will be using this ADC make sure to put a 1uf cap on pin6 reference,

    Here is the code :
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    ' ADC CONSTANTS
    ' MAX1272 - BIPOLAR
    ' Forum thread http://forums.parallax.com/showthread.php/148478-Max1272-in-Bipolar-mode
    
    SCLK             PIN  15      'serial clock pin
    CS               PIN  14      'chip select pin
    serData_in       PIN  13      'serial data into the Stamp
    serData_out      PIN  12
    
    ADC_RESULT       VAR   Word
    VALUE            VAR   Word
    sign             VAR   Bit
    
    main:
    
    Convert:
    PAUSE 250
    VALUE = 0
    
    LOW CS '  Enable ADC
      SHIFTOUT Serdata_out, Sclk, MSBFIRST, [%00000000]
      SHIFTOUT Serdata_out, Sclk, MSBFIRST, [%00000000]
      SHIFTOUT Serdata_out, Sclk, MSBFIRST, [%10111101] ' Set for BI-POLAR
      SHIFTIN Serdata_in,SCLK,MSBPOST,[ADC_RESULT\12]
    HIGH CS ' DISABLE ADC
    
    sign = ADC_RESULT.BIT11
    
    IF (sign = 1) THEN DEBUG  "SIGN = 1",13
    IF (sign = 1) THEN GOTO NEGATIVE
    IF (sign = 0) THEN DEBUG  "SIGN = 0",13
    IF (sign = 0) THEN GOTO POSATIVE
    
    NEGATIVE:
     ADC_RESULT.NIB3 = -ADC_result.BIT11
     ADC_RESULT = ABS ADC_RESULT
     VALUE = (ADC_RESULT + (ADC_RESULT ** 14464)) * 2
     DEBUG "ADC Vout ...  SDEC = ",SDEC -VALUE , 13
     ADC_RESULT = %0000000000000000
     VALUE = %0000000000000000
    GOTO convert
    
    POSATIVE:
     VALUE =  (ADC_RESULT + (ADC_RESULT ** 14464)) * 2
     DEBUG "ADC Vout ...  SDEC = ",SDEC VALUE , 13
     ADC_RESULT = %0000000000000000
     VALUE = %0000000000000000
    GOTO convert
    
    GOTO MAIN
    
    
Sign In or Register to comment.