Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with ADC calculation and voltage conversion

Status
Not open for further replies.
Re: ADC calculation - help

Hi

I have tested your codes and I get different answer from your!

I reckon it must be do with Keil IDE but I am not 100 percent certain

MaverickMax
 

ADC calculation - help

Try changing this:
Temp = 680*((adc_result[6]-82)/(920-82));

To this:
Temp = 680L*(adc_result[6]-82)/(920-82);
or this:
Temp = (long)680*(adc_result[6]-82)/(920-82);

Notice that I removed the parens (as silvio explained), and I added "L" or "(long)" so the calculation uses long int instead of int (as artem explained). If your compiler conforms to the ANSI C standard, then long int is at least 32 bits, and that's plenty for this calculation.

If this stuff seems somewhat mysterious to you, try grabbing a good C programming book, and read the section on integer expression evaluation.
 

Re: ADC calculation - help

I have got it working now :)

MaverickMax
 

Re: ADC calculation - help

Hi

There is one more thing to do as I only require to get the Voltage peak to peak....

Let assume that 300V peak to peak (150V peak)

According to the max and min of ADC, it is 950 and 500. So 950 would be +150V and 500 represents -150V.

Therefore I need to determine the OV (Reference) which would be 725

(950-500=225, 225+500=725)

temp= 150*(adc_result[5]-725)/(950-500)

Is that right? (Im terrible in math! :cry:)

Please correct if my calculation is incorrect

MaverickMax
 

ADC calculation - help

temp= 150*(adc_result[5]-725)/(950-725)

but keep in mind that you will get negative value so temp must be "signed long" type .
 

ADC calculation - help

Yes and no. You need to put "L" or "(long)" into the equation so that the multiplication doesn't overflow. The "temp" variable can be 16-bit.

temp= 150L*(adc_result[5]-725)/(950-725);
temp= (long)150*(adc_result[5]-725)/(950-725);

Another way to avoid 16-bit overflow is to use smaller constants that have the same ratio. However, it becomes harder to modify the equation if your ADC calibration changes slightly:

temp= 2*(adc_result[5]-725)/3;
 

ADC calculation - help

Yes, i admitted same error as Maverickmax originally did .))
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top