Go Down

Topic: ADC LTC2433-1 on Leonardo (Read 1 time) previous topic - next topic

steen67

Yes you have been a great help.
I thought I could just connect the IC and so it worked. It did not :-(

Here is the output, it looks like the other times.
This means that there is a connection to the LTC2433?

Code: [Select]
-201
-22
-59
-22
-58
-75
-207
-96
-112
-80
-99


And a problem with the input to the LTC2433 ?

Perhaps I have found the error, there does not seem that there is a supplay for the 4 strain gauge.

If I put my fingers on the input I get the following
Code: [Select]

-20840
-18899
-11663
-13768

steen67

Now I've got it working :-)
There was no Vcc to the 4 strain gauge

0 kg is about -3295
5 kg is about -4477
Me on the top is about -18087
About 236 each kg

But why is the number negative ?

You must have many thanks for your help pylon.
It was never succeed without you.

pylon

Quote
But why is the number negative ?


Because the ADC can convert positive and negative voltages. You can change that either in the hardware or just remove the addition of the sign in the code, e.g. this line:

Code: [Select]
    int16_t value = (byte1 & 0x20) ? -v : v;


make this line looking like this:

Code: [Select]
    int16_t value = v;


and you have positive values.

steen67

Thank you once again, you've been a great help

steen67

I still have a problem
The result can not be greater than 32768

I have changed the code, but that has not solved the problem.
I think it has something to do with unsigned

Code: [Select]
void loop()
{
delay(2000);
digitalWrite(CSPin, LOW);
delay(1);

byte1 = SPI.transfer(0);
byte2 = SPI.transfer(0);
byte3 = SPI.transfer(0);
delay(1);
digitalWrite(CSPin, HIGH);

unsigned int v = byte1;
v <<= 11;
v |= ((unsigned int) byte2) << 3;
v |= byte3 >> 5;


//v = (v-1340)/59;

Serial.println(v);

}

pylon

If you want to have 16bits of integer information and the sign information you need to change to the 32bit variant:

Code: [Select]
void loop() {
  delay(2000);
  digitalWrite(CSPin, LOW);
  delay(1);

  byte1 = SPI.transfer(0);
  byte2 = SPI.transfer(0);
  byte3 = SPI.transfer(0);
  delay(1);
  digitalWrite(CSPin, HIGH);

  int32_t v = byte1;
  v <<= 11;
  v |= ((int) byte2) << 3;
  v |= byte3 >> 5;
  if (byte1 & 0x20) {
    v = -v;
  }
}

steen67

There's something I do not understand.
My ADC is 16 bit it should give 65535 in decimal.

If I use your old code I get an output from unloaded stain gauge: 1340

Code: [Select]
uint16_t v = byte1;
v <<= 11;
v |= ((uint16_t) byte2) << 3;
v |= byte3 >> 5;

Serial.println(v);


If I use your new code I get an output from unloaded stain gauge: 66862

Code: [Select]
int32_t v = byte1;
  v <<= 11;
  v |= ((int) byte2) << 3;
  v |= byte3 >> 5;
 
Serial.println(v);


pylon

We need to mask out the flag bits in the first byte:

Code: [Select]
int32_t v = byte1 & 0x1F;
  v <<= 11;
  v |= ((int) byte2) << 3;
  v |= byte3 >> 5;
 
Serial.println(v);

Go Up