I am trying to get negative ADC value by giving -2.5 v to AD/DA high precision expansion board with Raspberry Pi 4. I am using python programming with twos complement of buffer size 200, unfortunately, I am not getting negative ADC value properly. as per condition if I had applied -2.5v I will get values @ -2.53456 form but I am getting around -0.5465 which is not correct.
Anybody help me to find a negative value. if someone did work on the negative value before or now doing.
Thanks in advance
Let us first check out the ADS1256′ “Read 2’s compliment results and convert to signed decimal” function.
Appendix A – ADS1256 Read three byte long 2’s compliment results and convert to signed decimal
Appendix B – ADXL345 Read three two-byte-long 2’s compliment results and convert them to signed decimal
Troubleshooting Tips – Insert break points, fake values, and debugging print statements statements in the pink and green sections.
Appendix C – ADS1256 Class
Note: Your class summarized below seems not flexible, therefore not easily to test. It would be nice to include a sample instantiation and which methods are then used to change the parameters such as gain, data rate (or one shot) with sample outputs, to clarified how a couple of tests have been made.
I think the easiest way is to put the signal through a resistor divider attached to 5V (or whatever your ADC reference is): a 2x divider will let you measure voltages from +5V to -5V:
The conversion to real voltage is linear: 0V measured by the ADC corresponds to -5V on the signal wire, 5V measurement corresponds to 5V signal value and 2.5V measurement corresponds to 0V signal value. In terms of software, that’s
V_real = 2*V_meas - 5*K_1Volt, where
K_1Volt is the numeric value corresponding to 1V.
Obviously, your measurement resolution w.r.t the real signal value will be twice as bad, and your signal source should support a 20kOhm load for this to work properly.