Yes, they are ll Floating point types. does it take 8.3us for each FP (+,*)?. I have 48 of those plus 8 more total additions in addition to select GPIO for each LED and reading each sample (56 * 8.3us = 464.8 us, almost half of 1ms). if I comment this below code, I have print for half-second, I can see my print coming very faster, if I enable below code, print is very very slow. this is my separate task, the first flag (get_curr_read_flag = TRUE) set by PIT 1ms timer, here it loks for that flag TRUE, then it reset to FALSE, then read one set of ADC samples and do math and store them in accumulators, then I have local counter here for 500 for Half-sec (measure_power_factor), when this reaches 500 (SAMPLES/2), I reset this to zero and do power calculations. this is my code. I have print all the way below for half-sec, if I comment all these FP (+,*), I get that orint very quickly, if I enable these, it is very slow, I gets print for every 5 Seconds.
#define SAMPLES 1000
TK_ENTRY(tk_adc_readings)
{
int err;
int temp;
int i;
float curr_buf1 =0;
float curr_buf2 =0;
float curr_buf3 =0;
float curr_buf4 =0;
float curr_buf5 =0;
float curr_buf6 =0;
float curr_buf7 =0;
float curr_buf8 =0;
float curr_buf9 =0;
float curr_buf10 =0;
float curr_buf11 =0;
float curr_buf12 =0;
float curr_buf13 =0;
float curr_buf14 =0;
float curr_buf15 =0;
float curr_buf16 =0;
float curr_buf17 =0;
float curr_buf18 =0;
float curr_buf19 =0;
float curr_buf20 =0;
float curr_buf21 =0;
float curr_buf22 =0;
float curr_buf23 =0;
float curr_buf24 =0;
float Board_Total =0;
while (!iniche_net_ready)
TK_SLEEP(1);
err = eg_init();
if( err == SUCCESS )
{
exit_hook(eg_cleanup);
}
else
{
dtrap(); // eg_init() shouldn't ever fail
}
for (;
{
//this get_curr_read_flag seyt by PIT 1ms timer, reset here
if (get_curr_read_flag == TRUE) {
get_curr_read_flag = FALSE;
//comment this temporarily - added this function code below
//get_readings();
VOLT_READ1;
for(i=0; i < 0x22; i++)
volt_buf1 = (int)((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 407 ) / 2048;
volt1_accu += volt_buf1 * volt_buf1;
CURR_READ1;
for(i=0; i < 0x22; i++)
curr_buf1 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr1_accu += curr_buf1 * curr_buf1;
power1_accu += volt_buf1 * curr_buf1;
CURR_READ2;
for(i=0; i < 0x22; i++)
curr_buf2 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr2_accu += curr_buf2 * curr_buf2;
power2_accu += volt_buf1 * curr_buf2;
CURR_READ3;
for(i=0; i < 0x22; i++)
curr_buf3 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr3_accu += curr_buf3 * curr_buf3;
power3_accu += volt_buf1 * curr_buf3;
CURR_READ4;
for(i=0; i < 0x22; i++)
curr_buf4 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr4_accu += curr_buf4 * curr_buf4;
power4_accu += volt_buf1 * curr_buf4;
CURR_READ5;
for(i=0; i < 0x22; i++)
curr_buf5 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr5_accu += curr_buf5 * curr_buf5;
power5_accu += volt_buf1 * curr_buf5;
CURR_READ6;
for(i=0; i < 0x22; i++)
curr_buf6 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr6_accu += curr_buf6 * curr_buf6;
power6_accu += volt_buf1 * curr_buf6;
CURR_READ7;
for(i=0; i < 0x22; i++)
curr_buf7 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr7_accu += curr_buf7 * curr_buf7;
power7_accu += volt_buf1 * curr_buf7;
CURR_READ8;
for(i=0; i < 0x22; i++)
curr_buf8 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr8_accu += curr_buf8 * curr_buf8;
power8_accu += volt_buf1 * curr_buf8;
curr_18_BT = curr_buf1+curr_buf2 +curr_buf3+ curr_buf4 + curr_buf5 + curr_buf6 + curr_buf7 + curr_buf8;
curr_18_AT += curr_18_BT * curr_18_BT;
VOLT_READ2;
for(i=0; i < 0x22; i++)
volt_buf2 = (int)((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 407 ) / 2048;
volt2_accu += volt_buf2 * volt_buf2;
CURR_READ9;
for(i=0; i < 0x22; i++)
curr_buf9 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr9_accu += curr_buf9 * curr_buf9;
power9_accu += volt_buf2 * curr_buf9;
CURR_READ10;
for(i=0; i < 0x22; i++)
curr_buf10 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr10_accu += curr_buf10 * curr_buf10;
power10_accu += volt_buf2 * curr_buf10;
CURR_READ11;
for(i=0; i < 0x22; i++)
curr_buf11 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr11_accu += curr_buf11 * curr_buf11;
power11_accu += volt_buf2 * curr_buf11;
CURR_READ12;
for(i=0; i < 0x22; i++)
curr_buf12 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr12_accu += curr_buf12 * curr_buf12;
power12_accu += volt_buf2 * curr_buf12;
CURR_READ13;
for(i=0; i < 0x22; i++)
curr_buf13 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr13_accu += curr_buf13 * curr_buf13;
power13_accu += volt_buf2 * curr_buf13;
CURR_READ14;
for(i=0; i < 0x22; i++)
curr_buf14 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr14_accu += curr_buf14 * curr_buf14;
power14_accu += volt_buf2 * curr_buf14;
CURR_READ15;
for(i=0; i < 0x22; i++)
curr_buf15 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr15_accu += curr_buf15 * curr_buf15;
power15_accu += volt_buf2 * curr_buf15;
CURR_READ16;
for(i=0; i < 0x22; i++)
curr_buf16 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr16_accu += curr_buf16 * curr_buf16;
power16_accu += volt_buf2 * curr_buf16;
curr_9_16_BT = curr_buf9+curr_buf10 +curr_buf11+ curr_buf12 + curr_buf13 + curr_buf14 + curr_buf15 + curr_buf16;
curr_9_16_AT += curr_9_16_BT * curr_9_16_BT;
VOLT_READ3;
for(i=0; i < 0x22; i++)
volt_buf3 =(int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 407 ) / 2048;
volt3_accu += volt_buf3 * volt_buf3;
CURR_READ17;
for(i=0; i < 0x22; i++)
curr_buf17 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr17_accu += curr_buf17 * curr_buf17;
power17_accu += volt_buf3 * curr_buf17;
CURR_READ18;
for(i=0; i < 0x22; i++)
curr_buf18 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr18_accu += curr_buf18 * curr_buf18;
power18_accu += volt_buf3 * curr_buf18;
CURR_READ19;
for(i=0; i < 0x22; i++)
curr_buf19 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr19_accu += curr_buf19 * curr_buf19;
power19_accu += volt_buf3 * curr_buf19;
CURR_READ20;
for(i=0; i < 0x22; i++)
curr_buf20 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr20_accu += curr_buf20 * curr_buf20;
power20_accu += volt_buf3 * curr_buf20;
CURR_READ21;
for(i=0; i < 0x22; i++)
curr_buf21 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr21_accu += curr_buf21 * curr_buf21;
power21_accu += volt_buf3 * curr_buf21;
CURR_READ22;
for(i=0; i < 0x22; i++)
curr_buf22 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr22_accu += curr_buf22 * curr_buf22;
power22_accu += volt_buf3 * curr_buf22;
CURR_READ23;
for(i=0; i < 0x22; i++)
curr_buf23 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr23_accu += curr_buf23 * curr_buf23;
power23_accu += volt_buf3 * curr_buf23;
CURR_READ24;
for(i=0; i < 0x22; i++)
curr_buf24 = (int) ((((MCF_ADC_ADRSLT7&0x7FF8)>>3) - 2048) * 100) / 2048;
curr24_accu += curr_buf24 * curr_buf24;
power24_accu += volt_buf3 * curr_buf24;
curr_17_24_BT = curr_buf17+curr_buf18+curr_buf19+curr_buf20+curr_buf21+curr_buf22+curr_buf23+curr_buf24;
Board_Total = curr_18_BT + curr_9_16_BT + curr_17_24_BT;
Board_Total_AT += Board_Total * Board_Total;
curr_17_24_AT += curr_17_24_BT * curr_17_24_BT;
measure_power_factor ++;
}
//for every Half-second calculate powers and reset this flag
if (measure_power_factor == (SAMPLES/2)) {
//calculate RMS currents and voltages and powers
//calc_powers();
measure_power_factor = 0;
printf("********* Half-second-print ****************************\n");
}
//eg_loop(); // will block if anything needs to be done
tk_yield(); // give up CPU in case it didn't block
eg_wakes++;
if (net_system_exit)
break;
}
TK_RETURN_OK();
}