Hello,
I have a problem with wrong representation of voltage processed by ADC. I tried every mode (differential and sigle-ended inputs), tried to find error in my code on microcontroller side and PC's side, but cannot find the reason.
The problem is that processed voltage's bit representation seems to be wrong at 9th bit. I get something like this for voltages that was smoothly changed on the precise voltage divider from value higher to lower. I tried also photodetector as signal source. The height between those two levels is about 256 so i thought that the problem can be related with data casting from one variable type to another but cannot find it.
It is visualized data taken from ADC. It looks like 9th bit is inversed.
Here is source code of my application on microcontroller:
Code to read data from ADC (I use C language HiTech PICC on PIC16F877A):
unsigned int dataOut = 0;
// Transmission start
// Set Pointer Register on Conversion register
SSPIF = 0;
ACKSTAT = 1;
SEN = 1;
while(SEN);
SSPIF = 0;
// Address
SSPBUF = 0b10010000;
while(!SSPIF);
while(ACKSTAT);
SSPIF = 0;
ACKSTAT = 1;
// Pointer Register
SSPBUF = 0b00000000;
while(!SSPIF);
while(ACKSTAT);
SSPIF = 0;
ACKSTAT = 1;
PEN = 1;
while(PEN);
// Read Data from ADC
ACKSTAT = 1;
SEN = 1;
while(SEN);
SSPIF = 0;
// Address
SSPBUF = 0b10010001;
while(!SSPIF);
SSPIF = 0;
// Read MSB
RCEN = 1;
while(!BF);
while(!SSPIF);
SSPIF = 0;
ACKEN = 1;
while(!SSPIF);
SSPIF = 0;
dataOut |= (SSPBUF << 8);
// Read LSB
RCEN = 1;
while(!BF);
while(!SSPIF);
SSPIF = 0;
ACKEN = 1;
while(!SSPIF);
SSPIF = 0;
dataOut |= SSPBUF;
// Transmission End PEN = 1;
while(PEN);
return dataOut;
then i send this data through RS-232 to PC
// Divide 2 byte variable on two bytes
unsigned char byte0 = dataOut;
unsigned char byte1 = (dataOut >> 8);
// Send byte throught RS-232
putch(byte0);
putch(byte1);
then on PC side i join two bytes into one 16bits variable
unsigned short detector1 = (unsigned short)byte0 + ((unsigned short)byte1 << 8);
And then send it into chart.
Please help me, I can add more informations if you need them.
ADC is set on continuous conversation, i can change sampling rate from 8 to 860 sps in program, can freely change adc's inner voltage reference gain, it doesn't affect on that problem behavior.
Before reading data I always wait period of time equal to two cycles of sampling rate but even in one shot mode behavior is the same.
Data shown on chart was obtain when ADC was in differential mode with +-2.048V voltage reference, 128 sps, second differential channel was short to ground.
Here is picture of basic, testing circuit: