AnsweredAssumed Answered

ADC interpretation

Question asked by GMVS on Apr 27, 2013
Latest reply on Apr 30, 2013 by bigmac

please help

this shouldnt be a difficult question to answer and it gets freaking frustrating to have 40 views and no response of anykind

 

i'm trying to use the adc, lets forget about EMI and coupling for the time being

 

assume this

ADC 0 = 0V

ADC 255 = 650V

 

if i get a 237 from the ADC

the voltage should be 237*650/255=604

at least that's what i want...

 

but it doesn't works, i assume its due type

 

if i do this

 

unsigned char ADCmeasure;

unsigned int Voltage;

ADC1_Measure(1);

ADC1_GetValue8(ADCReadBuffer);

ADCm=ADCReadBuffer[0];

Voltage=(int)ADCm*650/255;

 

it compiles but is not correct

i think because ADCmeasure*650 might not fit on a int

 

 

if i do this

 

unsigned int ADCm;

long Voltage;

ADC1_Measure(1); //measure

ADC1_GetValue8(ADCReadBuffer); //record

ADCm=(int)ADCReadBuffer[0]; //get first number and cast it to int

Voltage=ADCm*2.54902; //interpret it

ADCm=Voltage; //truncate it

 

it breaks saying

_DMUL_RC, _DSTRUNC, _DUFLOAT are not defined

 

 

if i do this

 

unsigned int ADCm;

long Voltage;

ADC1_Measure(1); //measure

ADC1_GetValue8(ADCReadBuffer); //record

ADCm=(int)ADCReadBuffer[0]; //get first number and cast it to int

Voltage=ADCm*650/255; //interpret it

ADCm=Voltage; //truncate it

 

it compiles but still is not correct

i think because it is messing with the sign or something for supposedly negative stuff

 

 

 

so how do i do this?

do i rather make the table of what each adc step mean and just look out for it?

would that be faster than dividing and multiplying on a 8 bit mcu?

 

thanks

 

 

 

Outcomes