# applying equations on ADC samples in mikroC

Status
Not open for further replies.

#### hafizimran18

##### Member level 4

i found this thing some helpfull ,, but still there is a problem,, when using simpe multiplications i.e p=v*i;
it gives exactly 25watt power with d.c source of 5V and 5A current,, but when same source is applied using these equations it do not give 25watt,, please help,, i am in trouble

Code:
unsigned int V, Itotal, Ifund;
unsigned long Swith_harmonic;
double Iharmonic, Qharmonic,a, distAngle, TrueActPwr ;

void main()
{
TRISA  = 0xFF;  // PORTA is input
TRISB  = 0x3F;  // Pins RB7, RB6 are outputs
TRISD  = 0;     // PORTD is output
do
{

V = ADC_Read(0); // channel_V is the analog channel where you give the V input;

V = (V%1024)*5;

Itotal = (Itotal%1024)*5;

Ifund = (Ifund%1024)*5;

Swith_harmonic = V * Itotal;

Iharmonic = sqrt((Itotal * Itotal) - (Ifund * Ifund)); // Select the C_Math library for using this function

Qharmonic = V * Iharmonic;

distAngle = asin(Qharmonic  / Swith_harmonic);

TrueActPwr = Swith_harmonic * cos(distAngle);

PORTD = TrueActPwr;

} while(1);
}

Why are you doing these?
V = (V%1024)*5;

Itotal = (Itotal%1024)*5;

Ifund = (Ifund%1024)*5;

It should be

V = V*5/1023;

Itotal = Itotal*5/1023;

Ifund = Ifund*5/1023;

Why are you doing these?
V = (V%1024)*5;

Itotal = (Itotal%1024)*5;

Ifund = (Ifund%1024)*5;

It should be

V = V*5/1023;

Itotal = Itotal*5/1023;

Ifund = Ifund*5/1023;

yes you are right,, its working but, now there is another problem,,, it is working for constant d.c of 5V, but showing zero output for pulsating d.c with Vmax=5V,, any idea about this thing?

yes you are right,, its working but, now there is another problem,,, it is working for constant d.c of 5V, but showing zero output for pulsating d.c with Vmax=5V,, any idea about this thing?

zip and post your project files including hex file and proteus file.

zip and post your project files including hex file and proteus file.

here it is, compiled in mikroC 8.0

#### Attachments

• aho.rar
99.2 KB · Views: 64

Status
Not open for further replies.