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.

problem reading conversion and calculating power

Status
Not open for further replies.

ghattas.akkad

Member level 1
Member level 1
Joined
Apr 30, 2013
Messages
39
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,555
hello i am trying to build a wattmeter using mplab
following the documents instructions in this pdf but im not getting correct results and cant figure out why
i think the problem is with the A/D reading but couldnt figure out how to fix it
it would be great if someone can take a look at it
thank you
 

Attachments

  • power meter! (3).zip
    80.3 KB · Views: 66
  • WattMeter.pdf
    1.3 MB · Views: 97

hello i am trying to build a wattmeter using mplab
following the documents instructions in this pdf but im not getting correct results and cant figure out why
i think the problem is with the A/D reading but couldnt figure out how to fix it
it would be great if someone can take a look at it
thank you


what microcontroller and compiler are you using?

if you vary the load does the ADC reading change?
 

Hi,

sorry, i didn´t read through the zip file...

"not correct results" what results do you get, and what do you expect?

Maybe step by step:
(use known voltages, known resistive loads, use a voltmeter and an amperemeter to compare values)
* just make sure that the adc is working
* then only make voltage readings and display it. Are they correct?
* then do the current readings an display it...
* then do the power calculations.

Then tell us what you see, and we can better assist you...

hope this helps
Klaus
 

what microcontroller and compiler are you using?

if you vary the load does the ADC reading change?
i am using pic18f4520 on mplab and C18 compiler yes it changes value when the load varies
i think the problem is with the A/D conversion formula i am using i managed to read the inputted values correctly now i just have to rescale them back
to the original voltage and current scales the problem some calculation problem where the result seems to vary whenever i change the values from 2 to 2.0
when i multiply by 10 it gives a result and when i multiply by 10.0 it gives another i dont understand this

- - - Updated - - -

Hi,

sorry, i didn´t read through the zip file...

"not correct results" what results do you get, and what do you expect?

Maybe step by step:
(use known voltages, known resistive loads, use a voltmeter and an amperemeter to compare values)
* just make sure that the adc is working
* then only make voltage readings and display it. Are they correct?
* then do the current readings an display it...
* then do the power calculations.

Then tell us what you see, and we can better assist you...

hope this helps
Klaus

thank you that was helpful i followed the steps and fixed the reading i still have to rescale the values to the original input voltage and current
so i can calculate the power on the ranges 0-230V and 0-5A the problem is some calculation errors that are a bit confusing and im getting some unexpected results
 

The "AC Watt Meter" project paper is assuming that you know how to read 10 Bit ADC values and thus doesn't discuss the details. But it's not done correctly in your code. I'm not using C18 and don't know how ADRES is generated. Presuming it is a correctly right adjusted 10-Bit values, it surely can't be stored in a char array.

Verify that you get plausible raw values and then trace the calculation step by step.
 

The "AC Watt Meter" project paper is assuming that you know how to read 10 Bit ADC values and thus doesn't discuss the details. But it's not done correctly in your code. I'm not using C18 and don't know how ADRES is generated. Presuming it is a correctly right adjusted 10-Bit values, it surely can't be stored in a char array.

Verify that you get plausible raw values and then trace the calculation step by step.
an int array wont compile stating that there is not enough place and i have a question regarding mikroC compiler when u use ADC_Read the returned value for example is between 0-255 and i have to rescale it by multiplying it by vdd/1024 right ?

- - - Updated - - -

Refer this project **broken link removed**

thank youu

- - - Updated - - -

MPLINK 4.40, Linker
Device Database Version 1.3
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - section '.udata_PowerM.o' can not fit the section. Section '.udata_PowerM.o' length=0x00000135
Errors : 1

this is the linker error

- - - Updated - - -

ok i fixed the linker error with his code
Code:
	#pragma udata udata1
	unsigned int ResultV[100];

	#pragma udata udata2
	unsigned int ResultI[100];

but the A/D conversion following the papers formula is still not working for me

Code:
Am = (5.0/1024.0)*(5.4054);
Vm = (5.0/1024.0)*(230.0);

ADCON0 = 0b11000001; 										//  A/D on, RC clock, select RA0
ADCON0bits.GO = 1;											//  start A/D conversion
while (ADCON0bits.NOT_DONE);								//  wait until A/D conversion is complete
ResultV[i] = ADRES;

ADCON0 = 0b11000101; 										//  A/D on, RC clock, select RA1
ADCON0bits.GO = 1;											//  start A/D conversion
while (ADCON0bits.NOT_DONE);								//  wait until A/D conversion is complete
ResultI[i] = ADRES;

tempV=Vm*((ResultV[i]/10)-2.5);		
tempI=Am*((ResultI[i]/10)-2.5);

RMSV = RMSV + (tempV)*(tempV);
RMSA = RMSA + (tempI)*(tempI);
Pin += (tempV)*(tempI);

i guess ill change the paper formulas... ill read A/D data scale it to 0-5V range than rescale them back to the original inputs
with some reversed calculations based on the implemented circuits
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top