# Calculating Max deviation in C

1. ## Calculating Max deviation in C

I am trying to implement above equation mentioned in link. I am using pic16F1938 for coding.

https://zenatix.com/current-and-volt...nter-measures/

Can someone help me or suggest me formula to calculate Max-deviation In c

All the variable declared as Unsigned int. In the mentioned example for unbalance current how to keep percentage limit.

•

2. ## Re: Calculating Max deviation in C

If it's just C coding, you could place each sample in an array and create a function using 'for-loop'.

[URL]https://www.programmingsimplified.com/c/source-code/c-program-find-maximum-element-in-array[\URL]

•

3. ## Re: Calculating Max deviation in C

I have implimented code considering the example. But in the example it not mentioned in which 2 phase unbalance has occurred.
can someone guide me here.

Code:
```unsigned int Max_Current=0;
unsigned int Min_Current=0;
unsigned int Unbalance_limit=10;
unsigned int Max_Deviation=0;
unsigned int Percentage_Unblance=0;

void Unbalance_Check()

{

Imean_Current=(Rph_Current+Yph_Current+Bph_Current)/3;

if((Rph_Current>Yph_Current)&&(Rph_Current>Bph_Current))
{
Max_Current=Rph_Current;

}else if((Yph_Current>Rph_Current)&&(Yph_Current>Bph_Current))
{
Max_Current=Yph_Current;

}else if((Bph_Current>Rph_Current)&&(Bph_Current>Yph_Current))
{
Max_Current=Bph_Current;

}else if((Yph_CurrentUnbalance_limit)
{
CRUnblance_Flag=1;
}else
{
CRUnblance_Flag=0;
}

}```
https://www.schneider-electric.co.in/en/faqs/FA300885/

--[[ ]]--