Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Measurements of two analog signals - temperature T (degree C) and wind speed V (

ID: 3849152 • Letter: M

Question

Measurements of two analog signals - temperature T (degree C) and wind speed V (km/h), are to be taken once every second by a PlC18 based weather station. Noise in the measurements is to be reduced by averaging the measurements over one minute, (ie 60 measurements) The average values are then used to calculate the windchill value W (degree C) using the following equation: W = 33 - (2 times V + 15) times (33 - T) 32 Write a C 'main' program suitable for a PlC18 MCU to perform the measurement, averaging and calculation of W. In your program you must declare any variables you need, use a loop to sequence a 24 hour period of measurement, averaging and calculating, then stop (wait in an endless loop). You must write your program in a modular fashion providing suitable subroutines or functions for the key steps of measurement, averaging and calculation. You are to assume the following routines are provided: (you do not need to write these routines) A subroutine called setup initializes the adc A function called temp returns an integer value for T between 0 and -20 (degree C) A function called wind returns an unsigned integer value for V between 0 and 10 (in km/h) A subroutine called dly1s provides a delay of 1 second There is no requirement to write any other sections of the program or initialise the hardware. (ie. You do not need to initialise the adc or write an adc conversion program.)

Explanation / Answer

Code:-

int main(){
   setup();
   int T[60];
   double avg_T;
   unsigned int V[60];
   double avg_V;
   double wind_chill;
   int min_count;
   int period_count=0;
   while(period_count<3600){ //24 Hour period
       for(min_count=0;min_count<60;min_count++){
           T[min_count]=temp();
           V[min_count]=wind();
       }  
       avg_T=average_Temp(T);
       avg_V=average_Wind_Speed(V);
       wind_chill=calculate_Windchill(avg_T,avg_V);
       printf("windchill value after %d minute = %lf",period_ count++,wind_chill);
       dly1s();
   }
   stop_end();
}

void stop_end(){           //stop by endless loop
   while(1){

   }
}

double average_Temp(int arr[]){
   int i=0,sum=0;
   for(i=0;i<60;i++){
       sum+=arr[i];
   }
   return (double)sum/(60.0);
}

double average_Wind_Speed(unsigned int arr[]){
   unsigned int i=0,sum=0;
   for(i=0;i<60;i++){
       sum+=arr[i];
   }
   return (double)sum/(60.0);
}  

double calculate_Windchill(double temprature,double wind_speed){
   double temp_V=0;
   double temp_T=0;
   double wind_chill=33;
   temp_V=(2*wind_speed)+15;
   temp_T=(33-temperature)/32.0;
   wind_chill=wind_chill-(temp_V * temp_T);
   return wind_chill;
}