Sensing millivolts with MCP3551

I am currently in a project where i am building a universal calibrator with mV, mA and RTD sourcing and sinking. Everything is displayed on LCD. I successfully did it with MCP3421 but later i was not getting 0.01 Volts accuracy with it, so i decided to go for Mcp3551. Now i have interfaced it with 2.5V Vref. I used its library and while testing on serial, i am getting adc values. I actually want to convert these adc values to the respective mV. My total millivolt input range is 0 to 200 mV which i am feeding to ADC. I will upload my code soon. I need some suggestions getting value in millivolts.

My Code :

/*
This example demonstrate the usage of the A/D Converter with MCP3551 library.
*/
#include <MCP3551.h>
#include <SPI.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

const int MCPPin = 10;
double adc;
double vin = 0;
/*
Connect SCK to CLK                (pin 13 on Uno)
Connect SDO/!RDY to MOSI   (pin 12 on Uno)
Connect !CS to MCPPIN           (pin 10 on Uno)
*/

//Create an instance of MCP3551 connected to the MCPPIN
MCP3551 myADC(MCPPin);

void setup() {

  Serial.begin(9600);
  lcd.begin(16, 2); 
}

void loop() {
  lcd.print(" UniCal");
  
  if(myADC.getCode())
  {
         adc=myADC.byteCode;
         adc= adc*2;
         delay(1000);
  
         float vin = (adc*(5/419304)); 
         //vin= (4194304*adc)/5;
         Serial.println("ADC Value "); Serial.println(adc);
         //vin=vin*1000;
         Serial.print("Voltage "); Serial.println(vin);

          lcd.setCursor(0, 1);
          lcd.print("mV:");
          lcd.print(vin,3);
          lcd.print("      ");
          delay(500);
          }
}

Thank you.

hello sir,
i'm also using the same chip MCP3551.
Can u please share the MCP3551 arduino library for me.

thanq sir,
Sankar

Firstly you vary between 491304 and 4194304 freely. #define the constant at the top, then
you'll always get the same value. As it is a power of two, use hex, not decimal notation, and
as its a long value, use long constant:

#define MAXADC 0x400000L
         float vin = (adc*(5/419304));

In C/C++ integer constants use integer arithmetic, so 5/419304 = zero.
Also for the Arduino the max integer is 32767 anyway as its a 16 bit implementation.

Try:

         float vin = adc * 5.0 / MAXADC ;

The 5.0 forces floating point. You have a plague of unnecessary parentheses which I removed too.

You might want to build your constant from the bit count directly:

#define ADCBITS 22
#define ADCMAX (1L << ADCBITS)

Less chance of silly errors, easier to modify for a different ADC resolution.

MarkT:

I'm afraid OP has already given up waiting for an answer...