Max1272 in Bipolar mode
mike.blankenship
Posts: 4
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
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
It can help us look at the code blocks if you can attach the program, or follow the advice...
A couple of things look strange in this section:
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.
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.
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 :