00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "pic24_all.h"
00030 #include <stdio.h>
00031 #include "reflow_oven.h"
00032
00038 UFDATA fdata;
00039
00040 const PROFILE profiles[NUM_PROFILES] = {
00041 {100,100,150,100,230,90,20,90,60, 183},
00042 {150,100,200,100,250,90,30,90,60, 217}
00043 };
00044
00045 uint8 u8_currentProfile = 0;
00046
00047
00048 void doCommit(UFDATA* p_ufdata) {
00049 union32 u_memaddr;
00050 u_memaddr.u32 = DATA_FLASH_PAGE;
00051 doWritePageFlash(u_memaddr, (uint8 *) p_ufdata, FLASH_DATA_SIZE);
00052 }
00053
00054 void doRead(UFDATA* p_ufdata) {
00055 union32 u_memaddr;
00056 u_memaddr.u32 = DATA_FLASH_PAGE;
00057 doReadPageFlash(u_memaddr, (uint8 *) p_ufdata, FLASH_DATA_SIZE);
00058 }
00059
00060 char *getProfileDesc(uint8 u8_p) {
00061 if (u8_p == LEADTIN) return("Lead(40%)/Tin (60%) mix");
00062 else return("Lead-free");
00063 }
00064
00065
00066 void printProfile (uint8 u8_p) {
00067 float f_ramp;
00068
00069 if (u8_p == LEADTIN)
00070 printf("%s profile, Wet temp: %d C \n",
00071 getProfileDesc(u8_p),
00072 profiles[u8_p].i16_wetTemp);
00073 else printf("%s profile, Wet temp: %d C \n",
00074 getProfileDesc(u8_p),
00075 profiles[u8_p].i16_wetTemp);
00076 f_ramp = (float) (profiles[u8_p].i16_preheatTemp - 25.0)/(float)profiles[u8_p].u16_preheatTime;
00077 printf("Preheat Temp: %d C, Time: %d s, Ramp: %6.2f (C/s)\n",
00078 profiles[u8_p].i16_preheatTemp,
00079 profiles[u8_p].u16_preheatTime,
00080 (double) f_ramp);
00081 f_ramp = (profiles[u8_p].i16_soakTemp - profiles[u8_p].i16_preheatTemp)/(float)profiles[u8_p].u16_soakTime;
00082 printf("Soak Temp: %d C, Time: %d s, Ramp: %6.2f (C/s)\n",
00083 profiles[u8_p].i16_soakTemp,
00084 profiles[u8_p].u16_soakTime,
00085 (double) f_ramp);
00086 f_ramp = (float)(profiles[u8_p].i16_reflowTemp - profiles[u8_p].i16_soakTemp)/(float)profiles[u8_p].u16_reflowTime;
00087 printf("Reflow Temp: %d C, Time: %d s, Ramp: %6.2f (C/s), Hold time: %d\n",
00088 profiles[u8_p].i16_reflowTemp,
00089 profiles[u8_p].u16_reflowTime,
00090 (double) f_ramp,
00091 profiles[u8_p].u16_reflowHoldTime);
00092
00093 f_ramp = (float)(profiles[u8_p].i16_reflowTemp - profiles[u8_p].i16_coolTemp)/(float)profiles[u8_p].u16_coolTime;
00094 printf("Cool1 Temp: %d C, Time: %d s, Ramp: %6.2f (C/s)\n",
00095 profiles[u8_p].i16_coolTemp,
00096 profiles[u8_p].u16_coolTime,
00097 (double) f_ramp);
00098
00099
00100 }
00101
00102 #define SETTLE_TIME 15 //seconds
00103
00104 static inline void DELAY_SECONDS(uint8 u8_s) {
00105 while (u8_s) {
00106 DELAY_MS(1000);
00107 u8_s--;
00108 }
00109 }
00110
00111 void doTempCal(void) {
00112 uint8 u8_c, u8_i;
00113 uint16 tempC;
00114
00115 u8_currPowerSetting = 0;
00116 printf("Warning: Oven must be at room temperature and door closed to do calibration.\n");
00117 printf("Warning: This takes 30 minutes! Do you still want to continue? (y/n): ");
00118 u8_c = inCharEcho();
00119 if (u8_c != 'y') return;
00120 tempC = getCelsiusI16Temp();
00121 if ((tempC < 20) || (tempC > 40)) {
00122 printf("\nTemperature is %u; it is not between 20C and 40C, something is wrong, aborting...\n",
00123 tempC);
00124 return;
00125 }
00126 fdata.caldata.temp[0] = tempC;
00127 printf("\nRoom temperature is: %uC\n", tempC);
00128 printf("Beginning calibration...hit any key to exit.\n");
00129 for (u8_i = 1; u8_i <= 100; u8_i++) {
00130 u8_currPowerSetting++;
00131 DELAY_SECONDS(SETTLE_TIME);
00132 tempC = getCelsiusI16Temp();
00133 fdata.caldata.temp[u8_i] = tempC;
00134 printf("Power: %u, Temp: %u \n",u8_i, tempC);
00135 if (isCharReady()) break;
00136 if (tempC > MAX_TEMP) break;
00137 }
00138 u8_currPowerSetting = 0;
00139 if (isCharReady()) u8_c = inCharEcho();
00140 while (u8_i <= 100) {
00141 fdata.caldata.temp[u8_i] = tempC;
00142 u8_i++;
00143 }
00144 doCommit(&fdata);
00145 printf("Calibration data written.\n");
00146 }
00147
00148 void printTempCal(void) {
00149 uint8 u8_i;
00150 printf("\nPower Setting Temp (C)\n");
00151 for (u8_i=0; u8_i <= 100; u8_i++) {
00152 printf(" %d %u\n",
00153 u8_i, fdata.caldata.temp[u8_i]);
00154 }
00155 }
00156
00157 uint8 printProfileMenu(void) {
00158 printf("\n1 Print Tin/Lead mix profile\n");
00159 printf("2 Print Lead-free profile\n");
00160 printf("3 Print temperature calibration data\n");
00161 printf("4 Perform temperature calibration and commit to flash\n");
00162 printf("5 Toggle Profile\n");
00163 printf("6 Exit\n");
00164 printf(" Enter number (1-6): ");
00165 return inCharEcho();
00166 }
00167
00168
00169 void doProfileMenu(void) {
00170 uint8 u8_c;
00171
00172 do {
00173 u8_c = printProfileMenu();
00174 printf("\n");
00175 switch (u8_c) {
00176 case '1':
00177 printProfile(0);
00178 break;
00179 case '2':
00180 printProfile(1);
00181 break;
00182 case '3':
00183 printTempCal();
00184 break;
00185 case '4':
00186 doTempCal();
00187 break;
00188 case '5':
00189 u8_currentProfile =!u8_currentProfile;
00190 printf("Current profile: %s\n", getProfileDesc(u8_currentProfile));
00191 break;
00192 }
00193 } while (u8_c != '6');
00194 }
00195
00196