Help with A/D converter

Hi folks. I started to use a mcp3208 A/D converter, I'm using this code: http://arduino.cc/playground/Code/MCP3208, it works but with a big oscillation in the result. I'm using it to read 0-5 volts from a load cell converter, is normal this variation or have someway to improve it?

Did you look at the load cell converter output with an oscilloscope to see if the output is clean?

Oh, that is too much. Take a nice SPI capable part and then bit-bang the interface?

I'll post some code from home where I used SPI to read all 8 ports and output them. You can reduce it to be just 1 channel if you want.

No I didn't checked the signal from converter yet, but I believe that is not a problem, I used a potentiometer direct on the bread board using the same arduino power source and the variation remained.

About spi I don't know if can I use, because I'm using Ethernet shield, and this use spi communication. Can I use both together?

Yes, you can use both together - each gets their own slave select pin. Assign a free pin to for the ADC.

Very good, if I use spi communication do you believe it will solve my problem?

This code checks to see if 5mS passed, samples one of the ADCs, sends it out via serial with bytes 0x33 for syncing and byte 0x00 thru 0x07 to indicate which channel it was. The actual transfer is a 3-byte transaction: first byte out tells the ADC to capture a specific channel, 2nd byte captures part of the ADC info, 3rd byte captures the rest of ADC info.

// in declarations section
int ADCaddress;
// ADC address is manioulated & added to baseADCaddress to tell the ADC which channel to perform on
 // Result is  600, 640, 680, 6C0, 700, 740, 780, 7C0
int baseADCaddress = 0x0600;    

// add other variables called below, SPI.begin() in void setup (no SPI modifiers needed), pinModes, etc.

Rest of this goes in void loop

// Elapsed time check for ADC and Switch reading
  if ( (millis()-previousMillis) >=5){

    previousMillis = previousMillis + 5; // set for next 5 mS interval

    // read ADC with 3 byte transfer
    PORTB = PORTB & B11111011;  // ADC_SS, LOW  >> Can do this with digitalWrite(ADC_SS, LOW); also
    // ADCaddress = 0x0600, 640, 680, 6C0, 700, 740, 780, 7C0
    dummyADC = SPI.transfer (highByte(ADCaddress));  // 0x06, 0x07 out, read in dummy data
    highADC = SPI.transfer (lowByte(ADCaddress));    // 0x00, 0x40, 0x80, 0xC0, read in upper 4 bits
    lowADC = SPI.transfer (0);              // dummy 0 byte out , read in lower 8 bits
    PORTB = PORTB | B00000100; // ADC_SS, HIGH  >> Can do this with digitalWrite(ADC_SS, HIGH); also

    // send the data out

    Serial.write (ADCsyncbyte);      // syncbyte = B00110011, 0x33
    Serial.write (address_count);    // find way to put this in top nibble of next command?
    Serial.write (highADC & 0x0F);   // send it out
    Serial.write (lowADC);           // send it out
    
    // prep address_count for next pass. Used to create ADC select, DAC select
    address_count = address_count +1;  // 0 to 7, pass to Rx for DAC sync
    if (address_count == 8){ 
      address_count = 0;
    }  // reset if hit all 8

    ADCaddress = baseADCaddress + (address_count * 0x40); // update for next ADC pass

  } // end 5mS test

" Very good, if I use spi communication do you believe it will solve my problem?" Can't hurt - gotta believe that SPI bit banging takes a lot of time vs the hardware doing it at 4 MHz or whatever the standard SPI rate is.

Ok, I will try to implement this code in my project, I'm not a expert in coding, but I will try.

Do you have a complete code to send me, it will help me a lot.

I'm beginning in arduino and programming.

I could, but I'll let you take a whack at it first. Great way to learn.

Ok, thanks for now.

Someone knows if this A/D converter http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010531
works like that http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en544175
I’m using a MPC3201 and I would like to change it for MCP3901 keeping same code, it will works?

The MCP3201 will be read similar to the MCP3208, except you don't have to supply it with any address data. Just SS Low, and do the 2 SPI.transfers as reads, and SS High.

    // read ADC with 3 byte transfer
  digitalWrite(ADC_SS, LOW); 
    highADC = SPI.transfer (0);    // dummy 0 byte out , read in upper bits - B11-B7
    lowADC = SPI.transfer (0);              // dummy 0 byte out , read in lower  bits, B6-B0 + B1
    digitalWrite(ADC_SS, HIGH); 
// do some manipulating to mask off unwanted bits, etc & put together as one int. See Figure 6-1 of MCP3201 data sheet.

The MCP3901 will take more programming & setup to get data from it.

Ok, I wanna improve the read data resolution, I found this mcp3304 13bits it works same way mcp320x, but the resolution isn't enough. I need about 16bits. Do you know any converter that works like a mcp320X, I intend to use the same code.

I think this one would http://www.analog.com/static/imported-files/data_sheets/AD7988-1_7988-5.pdf You'd need a simple inverter from SS for MCP3201 to CONV input on the AD7988.