This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1234: Scale application dealing with the 2's complement data with signed integer

Part Number: ADS1234

I know this sounds elementary but I am struggling with the math once the data is read from the ADS1234.  If the data is negative (data > 0x7FFFFF) I add (data + 0xFF000000) to fill out the integer and pass that along to the scale integration logic.  Which seems to work very nicely. EXCEPT when I hit the negative to positive threshold.  The system would prefer an always positive number going the same direction.  For example, 0 -> 0xFFFFFF.  I have tried a few methods and keep falling down (due to poor math skills).  I tried for the negative numbers removing the negative bit/compliment/+1 ~(data & 0x7FFFFF)+1 and placing the positive on to by adding 0x8000000 to the positive numbers. 

I tried a few other things but fell flat with no joy.  

Scott

  • Hi Scott,

    I'm not totally sure I follow what you are doing. Binary 2's complement will output a code from 0 to 0x7FFFFF (positive full-scale) in the positive direction and from 0xFFFFFF (-1) to 0x800000 (negative full-scale).  If you are storing the 24-bit conversion value to a signed integer, then all you need to do is check the MSB (bit 23) of the conversion result to see if it is '1'.  If it is a 1, then you need to sign-extend the value so that the result remains negative.  There are many ways that you can do the sign-extension.  One method is by adding the value 0xFF000000 to the conversion result as you have mentioned.  Another method is by using a left-shift by 8 (<<8) followed by a right-shift by 8 (>>8).  Or you could do the more math intensive approach of complement and add 1.

    long ADCresult; //32-bit signed integer
    
    /* capture conversion result and store to ADCresult as 24-bit value */
    
    if(ADCresult & 0x800000)  // check to see if MSB is set for binary 2's complement
    {
        /* first option */    
        ADCresult |= 0xFF000000;
    
        /* second option */
        ADCresult = ADCresult << 8; //shift result so that the MSB determines result is negative
        ADCresult = ADCresult >> 8; //shift negative value back to 24-bit result
    
    }

    There are also so other methods that can be used, but I won't go into them.  Doing an online search will provide some additional methods.

    Best regards,

    Bob B

  • I know this sounds nuts but I think I have covid brain so let me just lay this out.  As I add weight, ignore the amount ;

    0x00700000

    0x00780000

    0x007FFFFF

    0xFF800000

    0xFF880000

    0xFF900000

    There is actually a step in value in the way my math is using the integer and the value starts going down even though the weight is going up.

  • Hi Scott,

    In binary 2's complement 0xFF800000 for a 24-bit value is negative full-scale.  0x007FFFFF is positive full-scale.  So the jump between 0x007FFFFF to 0xFF800000 is from positive full-scale to negative full-scale.  

    You can't go beyond full-scale, so if you are at 0x007FFFFF and keep adding weight you will always see 0x007FFFFF as that is the maximum full-scale output of the ADC.

    Also, in you example you are actually decreasing the weight and not increasing once you are at negative full-scale. Note that with binary 2's complement 0xFFFFFFFF is actually one less (-1) than 0x00000000.

    Best regards,

    Bob B

  • Bob,

    As I add weight I seem to hit a discontinuity.  Does this look right?

    Grams ATD DATA
    000      0x898FE0
    100      0x8A3530
    200      0x8ADA70
    300      0x8B7FC0
    400      0x8C2410
    500      0x8CCA40
    600      0x8D6F80
    700      0x8E14C0
    800      0x8EBA00
    850      0x8F0C79
    870      0X8F2D85
    872      0x8F3092
    873      0x8F3238
    874      0x70CF48
    875      0x70D887
    880      0x70D8A0
    900      0x70FAC0
    1000     0x719FAC

  • Hi Scott,

    No, the data does not look correct.  For a load cell or strain element, you should see an output code near 0 for no load.  This could be like in the range of 0xFFFF00 to 0x0000FF give or take.  The value for 0 grams is a very negative number and for 1000 grams is a very positive number.  Interestingly the difference in many cases is about 42320 counts per 100 grams.

    The hex data you are showing, is it directly coming from the ADS1234?  Or are you making some kind of correction like converting a binary 2's complement value to unipolar value?

    Do you have any scope shots or logic analyzer shots of the communication that you can share for me to review?  Do you have a schematic for me to look at?  What are the voltages you are using for AVDD, DVDD and the reference?

    Best regards,

    Bob B

  • Hi Bob, 

    The HEX data is directly from the ADS1234.  I checked the scope wave form to a specific data read and it matched.

    I attached the schematic and no load scope trace.  

    I have not done a "OFFSET CALIBRATION".  Is this the problem?

    Scott

    scope trace.pdf

    Scale.pdf

  • Hi Scott,

    I didn't get the scope trace.  From the schematic I see lots of inductance on the analog supply.  This could be an issue on power up especially if the supply ramps slow or is not monotonic.  There are various internal nodes that require very short duration but large instantaneous currents that the inductance might choke.  Generally I don't like to see inductors on the supply, but sometimes they are required.  One possible alternative is to create a lowpass filter using an small value or resistance instead of the choke. 

    I would suggest that you hold PDWN low until the the AVDD and DVDD supplies have reached nominal operating voltage and then bring PDWN high.  After about 100ms following the setting of PDWN goes high, pulse the PDWN pin for at least 100us low time.  This should reset the ADS1234 to a good starting point.

    If the power up is causing an issue with the output code, then the PDWN pulse should straighten things out.

    Best regards,

    Bob B

  • Hi Bob,

    After full system power up I power down the  ADS1234 (bring low) for 2 seconds and then power up (bring high) for 2 seconds before reading.  Tried attaching the scope trace again.

    7506.scope trace.pdf

  • Bob,

    I just checked AVDD and it is solid as a rock.  The thing is my data is consistently wrong.  It really sounds like I am doing something wrong in the hardware.    

  • Hi Scott,

    The one other thing I should have suggested and that is after you issue the PDWN pin pulse, send 26 SCLKs to the ADS1234 to force a self-offset calibration.  The one thing that the PDWN pulse will not do is fix any corrupt data in the offset register.  I would try sending the 26 clocks after your first measurement to see if the data corrects itself following the self-offset calibration.  If the data still looks to be incorrect, then lets measure the analog voltage coming to the ADC inputs being converted and measure both the AINP input to AGND and AINN input to AGND and let me know these voltages.  Also tell me the pin voltages being used for the gain pins.

    Best regards,

    Bob B

  • Hi Bob,

    I have tried all 3 gain settings above 0 and the issue happens at the same value but different weight..

    I will give self-offset calibration a try now and get back to you with the results.

    Scott

  • Hi Scott,

    Did you happen to capture the hex values for the different gain settings for me to compare?  The self-offset calibration I think should make a significant difference, but I guess we will see.

    Best regards,

    Bob B

  • Hi Bob,

    I did not see a difference after the self-offset calibration.

    I only captured the HEX values with the gain setting 2 but there was a similar - to + inconsistency.   

    Scott  

  • Hi Scott,

    Have you made the voltage measurements I requested measuring from AINP to gnd and AINN to ground for the ADC inputs?  Can you give me more information regarding the sensors being used?

    Best regards,

    Bob B

  • AINP1 to ground - 2.454

    AINN1 to ground - 2.454

  • Hi Scott,

    I assume that you are using a hyphen and the voltage is not negative, correct?  I also assume that the voltage is at no load, is that also correct?  Can you repeat and give me the 100 gram weight results and the voltage at the inputs relative to ground?

    A couple of further questions, do you have all of your sensors connected currently or just one?  Any chance you can send me some pictures of your test setup?  If your device is showing the same voltage at each input relative to ground, and you have pulsed the PDWN pin after the supplies have reached nominal operating voltage, and you have issued the self-offset command then you should see near 0 code (+/- noise) as the conversion result.  It is confusing to me why you are seeing something much different unless the part has become damaged.

    Another check is to create a voltage divider using equal value resistors powered by the same excitation.  At the junction of the resistors connect both the AINP and AINN inputs together.  This will create an external short that will not include any potential sensor offset and we can perhaps get a little more clarity as to whether or not there is a hardware issue.

    Best regards,

    Bob B

  • I assume that you are using a hyphen and the voltage is not negative, correct? Yes, Sorry about that!!

     I also assume that the voltage is at no load, is that also correct? Correct

  • Hi Scott,

    I must admit that you have me stumped on this one.  I have used similar load cells in the past to what you are using and your setup is pretty straightforward.  Have you tried to unplug all but one of the load cells to see if there is any different behavior?  One possibility may be that your 5V supply may be drooping, but even then you should not see the odd behavior with the ADS1234 output for the conversion result.  Can you tell me more about the ADS1234 you are using as to package markings on top and how/where you received the ADS1234?

    Best regards,

    Bob B

  • I bought the parts from DIGIKEY and I expect it was fine when I bought it.  I think my lack of AGND hurt the part.  I pulled another board from the lot and I get;  No load sensor 0 = FF9945, Sensor 1 = FFF179, Sensor 2 = FFF0AA,  Sensor 3 = 0004FC9.  This seems way different and closer to what you were saying.

  • Hi Scott,

    This seems much more reasonable.  I would suggest that you still issue the self-offset calibration following power-up so that the only offset you see is relative to the load cell offset.  Also, for your system you should be using a gain of 128 (both gain pins set high) so make sure that the gain is set appropriately prior to issuing the self-offset calibration.

    Best regards,

    Bob B

  • Hi Bob,

    I changed the gain and calibration and all seems like it should be. The root cause was I destroyed 2 ADs when I was missing the ground. The third board / AD is working as it should.

     

    Thank you for the help!!!!!

    Scott