ADS1256 reading negative values

Active 2 days ago
Viewed 44 times

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

 New contributor
  • 1
    No evidence that this question has anything to do with the Pi. – joan Feb 25 at 14:35
  • Ah, I guess you are using ADS1250. The offset setting is a bit tricky. You need to read the datasheet very carefully not to go wrong. References: (1) raspberrypi.stackexchange.com/questions/99353/separate-spi-data, (2) raspberrypi.stackexchange.com/questions/95843/…. – tlfong01 Feb 25 at 14:35    
  • 1
    i am using ADS1256. could you know how to get negative value. any sample program do you have in python or c – Amritpal singh sodhi Feb 25 at 15:31
  • Ref 1 describes ADS1256 board, wiring, python SPI set up functions. You can follow up and describe your spec, init, setup, config, convert, read, and print results functions. If you have a spec, perhaps somebody might help writing the complete program for you. If you has a program spec and your already written, documented, but buggy program listing, perhaps somebody can debug the program for you. PS – Ref 2 points out it is important to set the “Vrefp” and “Vrefn”, “PGA”. If you don’t set them correctly, you result won’t offset and scale correctly. – tlfong01 2 days ago   
  • 1
    Thanks for your help. please find attach link. I marked it in red where i did twos complement and reading data. penzu.com/p/f38ec540. – Amritpal singh sodhi 2 days ago


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:


simulate this circuit – Schematic created using CircuitLab

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.

  • I think your simple resistor voltage divider works. To overcome the low input impedance problem, we can use an OP Amp as a digital buffer. Or we can use a dual+-5V power supply op amp and shift up input signal by 2.5V. Just brainstorming. – tlfong01 yesterday    
  • 1
    Ok Thanks @Dmitry Grigoryev,tlfong01 : I am doing simple register voltage divider i got now posItive measured value but how i program the formula V_real = 2*V_meas – 5*K_1Volt, in python. I gave the link of ADS 1256 file could you let me know .its library where i did twos complement .it mark in red.penzu.com/p/f38ec540. – Amritpal singh sodhi yesterday
  • Oh my goodness. So you are not using #Dmitry’s classic two register voltage divider method. Instead, you are using a “two register” divider approach, which I found wierd. As I said earlier, my accelerometer output is 2’s complement covering postive and negative values. I am using 2’s compliment converting to signed decimal function I borrowed form StackOverflow or elsewhere I forgot. As almost always, I did verify if the convering function is working in ALL conditions, no matter the number of bytes of the original 2’s compliment string. / to continue, … – tlfong01 4 mins ago   Edit   
  • I input pos and neg values, middle and boundaries, one to three bytes long, compare the function output with an online 2C to decimal converter. I found everything OK, before I decided to use it. My penzu program listing contains my conversion function with sample output. So you can use python to input different values to my converter and print out the results to verify. I have not yet looked at your do analog to digital conversion and convert 2C to decimal funtion, because you combined two things in one function, and I don’t wish to spend time splitting it and separate test one of them. – tlfong01 3 mins ago   Edit   
  • Actually I did rerfresh my memory on 2’s compliment represention and did mental checking using my studpid brain, with questions like below, on 8 bits only. (1) How can 8 bits donote +3? OK, it 00000011, so my function should give “+” and 00000011. (2) How to denote -4 then? Well, I know the mechanical procedure is first find one’c complement, then add one. Of course I cheated and asked help on line (exploringbinary.com/twos-complement-converter). / to continue, … – tlfong01 2 mins ago   Edit   
  • Anyway I used the online converter to verify my python converter function. Now of course you can verify if my converter is correct, AND IF YOUR TWO REGISTER APPROACH IS ALSO CORRECT (I doubt it). Sorry for my blunt comments, but you are doing 24 bit high precision perhaps life critical medical or military applications, you need to verify every step of your design. I won’t be so strict/severe if you are doing Micky Mouse hobbyist projects using the amateurish MCP3008. – tlfong01 just now   Edit   

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: