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.

Interfacing ADS1230 with Arduino

Other Parts Discussed in Thread: ADS1230, ADS1298

Greetings all,

 

I am new in using ADS chip series and I would like to interface with arduino.. I only have one problem .. using the SCLK pin.. I am not sure how to write the code for this pin in C .. So pleas can any one give me some hints of how to program it?

I am using a 300kg load cell .. with 2mV/V output..and 5V reference..

 

thanks all

Musab

  • Hi Musab,

    Welcome to the forum!  No one on our team has written code for the Arduino processor so we won't have anything specifically tailored to the ADS1230.  We did have another forum member share his code for an Arduino while running an ADS1298 though.  That device also has an SPI interface so the code should help you get your processors peripheral setup correctly.  Please take a look at this post:

    http://e2e.ti.com/support/data_converters/precision_data_converters/f/73/p/43772/218128.aspx#218128

     

  • Thanks Tom..

    Cheers,
    Musab

  •  Dear Mr. Tom,

    I wrote the code in C for the arduino .. I seemed to be working .. but I keep getting a constant value without applying compression or tension on the load cell,

    and when i apply a little compression force I get the maximum value!!!..

    here is the code with comments...

    void loop() {
      double values[24],force(0);
      int cal(0);
     
      delay(801.03); // for offset callibration
     
      if (digitalRead(4) == 0)// checking the output pin from the ADS1230
      {
        for (int i(0) ; i<24 ; i++) // applying the serial clock (SCLK)
        {
         
         
          digitalWrite(5,HIGH); // the rising edge of the serial clock
          values[i] = digitalRead(4);// reading from  the output pin
          delayMicroseconds(0.001); 
          digitalWrite(5,LOW);  //falling edge of SCLK
          delayMicroseconds(0.001);
        
        }
        for (cal ; cal<2; cal++) // applying additional 2 clocks
        {
          digitalWrite(5,HIGH); // the rising edge of the serial clock
          delayMicroseconds(0.001); 
          digitalWrite(5,LOW);  //falling edge of SCLK
          delayMicroseconds(0.001);
        }
       
       
       
       
        for (int j(0); j<24; j++)// converting the array values to decimal.
        {
          force = force + (values[j]*pow(2,j));
             
        }
       
         Serial.println(force); // print value..
        
        
       
       
       
     
     
    } // end While statement
    } // end loop

     

    Please tell me if providing the serial clocks is right.  provided that the gain is 64 ..

  • Hi Musab,

    Can you provide a screen capture of your SPI clock and data lines?

  • Musab,

    As Tom mentioned, we really need to see a scope shot of your transfer to verify clock edges with the data.  It would also be helpful to know what value you think (according to the software) is being returned for the same data shown on the scope shot.

    Regarding the code, remember that the code value returned is binary two's complement.  So when making into an integer remember it is signed.  The other thing to remember is the return value for the ADS1230 is 20 bit and not 24 bit for the result.  So when converting to an integer make sure you are using the correct bits in the correct bit order and the sign bit is extended properly.

    Best regards,

    Bob B

  • Greeting Bob and Tom,

     

    Sorry for the late response.. I was working on it every single day till it was finally giving nice output ( I think) ... Regarding the 24 bit .. I just followed the datasheet and applied the other four clocks to force the output pin of the ADS1230 to be high and that what I am getting .. but I only convert 20 bits of it...

     

    At first .. it was giving random values with out even putting load on the load cell ... I figured that that was because I did not excite the load cell with 10V instad with 5V..

    but another thing appeared.. I am not getting a good resolution... I noticed that it can only read  when the load is above 5Kg ....

     

    I did not really understand Tom's question.. I am just connecting the SCLK pin to an output pin (pin 5) in the arduino ... and giving it the following code:

    for (int i(0) ; i<24 ; i++)    // applying the serial clocks (SCLK)
            {
             
              digitalWrite(5,HIGH);   // the rising edge of the serial clock

               delayMicroseconds(1);


              values[i] = digitalRead(4);// reading from  the output pin


             delayMicroseconds(1);
              
              digitalWrite(5,LOW);//falling edge of SCLK


              delayMicroseconds(2);
              
                         
            }

    and the maximum values it reads is this count : 524288... does it ring any bells??

  • Musab,

    Tom was asking for a 'picture' or oscilloscope screen shot of the communication between the Arduino and the ADS1230.

    524288 is full-scale (2^19 or positive full-scale), so yes that rings a bell.  First of all we have a problem with the input voltage.  You said earlier that you are using a 2mV/V load cell.  Without a weight and if the bridge is balanced you should be 1/2 of the excitation voltage.  If you excite the bridge with 10V, 1/2 would be 5V.  The inputs of the device can only except voltages between AVDD-1.5V and AVSS+1.5V, so the inputs can not except 5V.  This means you can not use the 10V excitation.

    The second problem is gain.  You should be using a PGA setting of 128.  At 2mV/V and 5V excitation, the maximum deflection will be 10mV when the full weight is placed on the load cell (300kg).  5kg is 1/60th of the full range or in other words will cause a total deflection of 167uV.  The LSB size is about 37nVfor a gain of 128.  The resultant code for a 5kg weight should be about 4490 codes at the 20-bit level.  However, you will see a lot of noise (about 2-1/2 bits absolute best case.)  So even withno weight applied you will see fluctuating codes at least 5 to 6 codes.  If you actually end up with about 16 bits of usable data you will be doing pretty well.  If I did the math correctly that will give a resolution of about 10 grams for a 300kg max weight.  This can be improved if you have a very clean board layout and power supplies.  Averaging or processing the data digitally may also help.

    So what you need to do first is get accurate data.  To do this you need to have a very clean layout for your board.  You need to minimize as much as possible any noise sources that affect the result.  To find the noise on your system, create a voltage divider so that 1/2 of your supply voltage can be applied to the inputs (the inputs should be shorted and connected to 2.5V if the supply is 5V.)  You should only see about 2 to 3 codes of variation.  If it is worse than that you will need to fix the noise sources that are creating poor results.  Once you have a fairly stable system, disconnected the short from the input (including the bias of 2.5V) and connect your load cell.  Get the code value for an unloaded load cell, then add the 5kg weight and you should see about 4490 codes of increase above the unloaded code.

    Best regards,

    Bob B

  •  

    Dear BOb,

     

    Thank you for the great feedback .. I did what you said regarding the power supply ..

    Regarding the noise , I did what you suggested about shorting the inputs of the device to 2.5V and I got  3 codes namely : 262143 , 196607 , 131071 .. So, That  was good news or is it?? .. but then again when I connectd the load cell .. I keep getting this ( which I dont really consider good based on what you said ) :

    (in Arduino software(namely C) there is a serial monitor that I display the data on)

     

    Reading Data

    000000000000000000001111     0.00

    Reading Data

    000000000000000000001111     0.00

    Reading Data

    000000000000000000001111     0.00

    ....

    .....

     

     

    where the four onse are the other 4 clockes to force the output high.. the number on the right is the converted 20 bits..

    I checked the inputs of the device and they were excatly the same (2.52V).... Could be possibly that there no noise at all ... and onother thing : it is not responding to any loads at all ...

     

    So , I figured that the problem could be the power supply : the device and the load cell have the same power supply (5V) ... but for the arduino it is from the PC but  I shared grounds together.. I wonder if thats OK?

    any suggestions??

    thank u in advace Bob..

  • yes , there is one confusing thing in the data sheet , In the example of the weigh scale .. they said that they used the gain of 128 but the pin was  tied to the ground which then the gain will be 64 according to the pin configuration section in the sama data sheet?

  • Musab,

    The answer to the easy question first.  The PGA of 128 is with the GAIN pin high.  The drawing in the example does not match the text.

    I think I didn't explain very well what I wanted you to do with the shorted input test.  The '3' codes means three LSB maximum difference from all the data results collected (which could be hundreds of measurement results.)  The shorted inputs show you have a serious problem because the resultant code should be 0 +/- 3 (which assumes you did the self offset calibration.)  If you didn't do the self calibration the value should still be some value say 1959 +/- 3 ( I just picked a number, it could be any number.)  So if you took three results you might have one that is 1959, another 1960 and a third that is 1958.  The point I'm trying to make is that with the input shorted, you have a zero difference voltage, and outside of noise (and offset if you didn't do the offset calibration) affecting the result, you should see results that represent the 0V difference at the input.

    Is it possible to send me your schematic of how you hooked things up?  You said you connected the 5V supply to AVDD, this should also be connected to the reference input.  What are you using for DVDD?  Does the Arduino use 5V, or is the same digital voltage connected to both DVDD and the Arduino?  Do you have an oscilloscope (or logic analyzer?)  You really need to verify that the data results you see in software are the same as you see on the o-scope or logic analyzer.

    How do you have things hooked up?  Have you actually made a PC board?  Is it on a breadboard?  Can you send me a picture of your setup?

    Best regards,

    Bob B  

  • Bob,

    Alright, As a start, the Arduino is a ready soldered bored that has a USB serial port that can be connected to the PC directly and it can be powered from the PC as well..

    I really do understand the concept of shorting the inputs together and I did it as you suggested ..

    I will send the full schematic as well as a scope photo later on .. but I will explain the power distribution ... I have a  5V power supply connected to the ADS1230 for AVDD,DVDD and the reference .. and connected the SCLK , GIAN, /DRDY/DOUT , /PDOWN pins to an output pins of the arduino ... keeping in mind that PDOWN should be powered after the ADS1230 is powered .. GAIN to 1... but now there is a ground problem ,,, I connected the ground of the Arduino to the ground of the power supply.. when I do that it gives the maximum value directly ... don't really know why?

    keeping in mind that I powered the Arduino from the PC..  

    Regarding the offset calibration .. I did it only once when the software will start .. by applying 26 clocks as well as applying t(cal) for the calibration to take place.. then waited for the data output pin to go low to start reading from it..

     

  • Greetings bob,

    I think this is good news... but I would like to hear your opinion.. Well, I have connected the load cell ... and when it is unloaded it gives these values : ( I will list 5 of them) : 87961 , 88122 , 89781 , 90950 , 95021 ... it is fluctuating within these values .. when I compress it, it decreases and vise versa.. is this normal??

     

    Another question.. the update time (t_update) is it preferable to be near the minimum, because it is affecting the results a little bit?

     

    thank you Bob.. your feedback is well appreciated

  • Musab,

    Sounds like your getting something, but there is a lot of noise.  From the numbers you gave there is a 7060 code spread, which comes out to be about 13 bits of noise.  Also, if you depress on the load cell and the numbers go down, you will need to swap the connections at the analog input (you may want to reverify all of the load cell connections.)  You also have a very large offset.  Have you tried to measure this at the analog inputs with a meter?  According to the results there is an offset of about 3.5mV.

    Were you ever able to get the shorted inputs to show near zero volts?  We need a good baseline measurement to start from.  If you are still getting a full-scale measurement, then I would guess that the reference voltage is not present.  You need to make sure that the 5V is also getting to the reference.

    You don't want to retrieve data close to the tupdate time as that may cause the data results to be corrupted.  You do want to try and retrieve data as soon as possible after DRDY/DOUT goes low (or as soon as possible after tupdate has completed.)

    Best regards,

    Bob B