|
Hi to everyone! I would use some help about one assigment, and I'll be grateful if you could help me. The assigment is on two input signal, I need to calculate the efective value and I need to let the signal who has bigger effective value on the gate. My solution on this problem is the following:
I squere and add every sample and I do that for some particular number of sample, in my case that number is 65535. After that the sum which is equal to the sum of the sgures I devide it with 65535, and then I find a root on that rusult. In that way I get the effective value. After that i compere the two effective value and I let to the gate the bigger one.
my code is:
#include <device.h>
#include <math.h>
double result = 0;
double konecen = 0;
double konecen1 = 0;
int32 suma1=0;
int32 suma2=0;
double result1 = 0;
int32 br1=0;
int32 br2=0;
void main()
{
ADC_DelSig_1_Start(); /* Initialize ADC */
for(;;)
{
AMux_1_Start( ); /* Reset all channels */
AMux_1_Select(0); /* Connect channel 1 */
ADC_DelSig_1_StartConvert();
ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT);
ADC_DelSig_1_StopConvert();
suma1+=ADC_DelSig_1_GetResult16() * ADC_DelSig_1_GetResult16();
br1+=1;
if (br1==65535)
{
result = suma1/65535 ;
konecen = sqrt(result);
}
AMux_1_Select(1); /* Connect channel 2 */
ADC_DelSig_1_StartConvert();
ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT);
suma2+=ADC_DelSig_1_GetResult16() * ADC_DelSig_1_GetResult16();
br2+=1;
if (br2==65535)
{
result1 = suma2/65535 ;
konecen1 = sqrt(result1);
}
if( br1==65535 && br2==65535)
{
br1=0;
br2=0;
suma1=0;
suma2=0;
if(konecen > konecen1)
{
AMux_2_Start( );
AMux_2_Select(0);
}
else
{
AMux_2_Select(1);
}
break;
}
}
}
Do you think this will work? Has anyone have a sugestion how I can advance the code? Then how can I make a conversion from a binary record on finaly and finaly1 into decimal becouse I will need to show it on the screen so I need the easiest way to do that? That should look like this:
Input signal1 effective value=number
Input signal2 effective value=number
output=signal1 or signal 2 it depends how is bigger
Is it better if I calculate the sum of the root with the interapt routine form adc?
Do you have any other ideas about how I can solve this problem? Thanks to everybody !!
|