Pages: 1 [2]   Go Down
Author Topic: ADC LTC2433-1 on Leonardo  (Read 1331 times)
0 Members and 1 Guest are viewing this topic.
Denmark
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
-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:
-20840
-18899
-11663
-13768
Logged

Denmark
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4671
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
    int16_t value = (byte1 & 0x20) ? -v : v;

make this line looking like this:

Code:
    int16_t value = v;

and you have positive values.
Logged

Denmark
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Denmark
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);

}
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4671
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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;
  }
}
Logged

Denmark
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
int32_t v = byte1;
  v <<= 11;
  v |= ((int) byte2) << 3;
  v |= byte3 >> 5;
 
Serial.println(v);
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4671
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Pages: 1 [2]   Go Up
Jump to: