Here is my file. I'll spare you the huge lookup table. Please excuse the sloppiness for now. It's a first run. :)
#include // derivative information #include "pll.h" #include "adc.h" // ADC_Init, ADC_Read #include "lcd.h" // LCD Display #include "flow.h" // flow calculation fuction #include "stdio.h" // common functions #include "math.h" // math functions
unsigned int ms_ctr; unsigned int sec_ctr; unsigned int mins_ctr; unsigned int hrs_ctr; unsigned int days_ctr;
float Temp[446]; volatile float currentMCF; volatile float yesterdayMCF;
float SCFM;
void flowCalc() {
float ambPressure; float diffPressure; float ambTemperature; unsigned int Conv1; unsigned int Conv2; unsigned int Conv3; char ATDstring1[16]; char ATDstring2[16]; char ATDstring3[16]; char ATDstring4[16]; char ATDstring5[16]; char ATDstring6[16];
for(;;) { // reading ATD channel 13(Temperature) Conv1 = ADC_Read(0x85); ambTemperature = Temp[Conv1]; //sprintf(ATDstring1,"%f deg F ",ambTemperature); //writeLine(ATDstring1,1); // reading ATD channel 14(Ambient Pressure) Conv2 = ADC_Read(0x86); ambPressure = (float)(((Conv2-205.0)/819.0)*50.0); //sprintf(ATDstring2,"%f PSIA ",ambPressure); //writeLine(ATDstring2,0); // reading ATD channel 15(Differential Pressure) Conv3 = ADC_Read(0x87); diffPressure = (float)(((Conv3-205.0)/819.0)*138.40); //sprintf(ATDstring3,"%f in H2O ",diffPressure); //writeLine(ATDstring3,1); // calculating flow in SCFM SCFM=128.8*K*Di*Di*sqrt((ambPressure*diffPressure)/((ambTemperature+460.0)*Ss)); sprintf(ATDstring4,"%f SCFM ",SCFM); writeLine(ATDstring4,0); // displaying time // sprintf(ATDstring5,"%id%ih%im%is ",days_ctr,hrs_ctr,mins_ctr,sec_ctr); // writeLine(ATDstring5,1); // displaying yesterday MCF sprintf(ATDstring6,"%f MCF yesterday ",currentMCF); writeLine(ATDstring6,1); } }
__interrupt void RTI_ISR() { // clearing flag CRGFLG = 0x80; // update milliseconds ms_ctr = ms_ctr+1; // update seconds if(ms_ctr == 25) { ms_ctr = 0; sec_ctr = sec_ctr+1; } // update minutes if(sec_ctr == 60){ sec_ctr = 0; mins_ctr = mins_ctr+1; currentMCF = (currentMCF + SCFM); } // fudge correction if(mins_ctr == 30){ sec_ctr = sec_ctr+42; } // updates hours if(mins_ctr == 60){ // fudge correction sec_ctr = sec_ctr+42; mins_ctr = 0; hrs_ctr = hrs_ctr+1; } // updates days if(hrs_ctr == 24) { hrs_ctr = 0; days_ctr = days_ctr+1; yesterdayMCF = currentMCF; currentMCF = 0.00; } }
void RTI_Init() { SCFM = 0.00;
ms_ctr = 0; sec_ctr = 0; mins_ctr = 0; hrs_ctr = 0; days_ctr = 0; currentMCF = 0.00; yesterdayMCF = 0.00; // Enable interrupts asm cli // RTIE On CRGINT = 0x80; // RTI Freq Divide Rate 11x2^16 // Interrupts every 90.112 ms RTICTL = 0x74; }
void temperatureInit() { Temp[0]=-60.0000000000000; Temp[1]=-53.1734380020266; Temp[2]=-46.2560695623409;