Example program using the MLX90620 and KL25Z. Best viewed with wide-screen VT-100 color terminal. Tested with Tera Term. Easy i2c pin name change for mbed1768.
Dependencies: MLX9062x PrintBuffer mbed
main.cpp
00001 #include "mbed.h" 00002 #include "PrintBuffer.h" 00003 #include "MLX90620.h" 00004 00005 int revision = 110; 00006 00007 #define BS 0x08 //ascii backspace 00008 #define CR 0x0d //ascii CR 00009 #define LF 0x0a //ascii LF 00010 #define SP 0x20 //ascii space 00011 #define ESC 0x1b //ascii escape 00012 #define DP 0x2e //ascii decimal point / period 00013 #define ticC 0x03 //ascii control C 00014 #define ticX 0x18 //ascii control X 00015 00016 #define DOBLACK "\033[0;30;2m" 00017 #define DORED "\033[0;31;2m" 00018 #define DOGREEN "\033[0;32;2m" 00019 #define DOYELLOW "\033[0;33;2m" 00020 #define DOBLUE "\033[0;34;2m" 00021 #define DOMAGENTA "\033[0;35;2m" 00022 #define DOCYAN "\033[0;36;2m" 00023 #define DOWHITE "\033[0;37;2m" 00024 #define DODEFAULT "\033[0;39;2m" 00025 #define DONONE "\033[0m" 00026 00027 char *doBLACK = DOBLACK; 00028 char *doRED = DORED; 00029 char *doGREEN = DOGREEN; 00030 char *doYELLOW = DOYELLOW; 00031 char *doBLUE = DOBLUE; 00032 char *doMAGENTA = DOMAGENTA; 00033 char *doCYAN = DOCYAN; 00034 char *doWHITE = DOWHITE; 00035 char *doDEFAULT = DODEFAULT; 00036 char *doNONE = DONONE; 00037 00038 00039 #if defined(TARGET_KL25Z) 00040 extern "C" void NVIC_SystemReset(); //for KL25Z 00041 #else 00042 #include "FATFileSystem.h" 00043 extern "C" void mbed_reset(); //for mbed1768 00044 #endif 00045 00046 int gDebug = 2; 00047 00048 Serial pc (USBTX, USBRX); 00049 00050 #if defined(TARGET_KL25Z) 00051 I2C i2c1(PTE0, PTE1); 00052 I2C i2c2(PTE25, PTE24); 00053 //MLX90620 mlx(PTE0, PTE1, "mlx"); //MLX90620 register access 00054 MLX9062x mlx(PTE0, PTE1, MLX9062x::mlx90621, "mlx"); //MLX90620 or MLX90621 IR array 00055 MLX9062x::mlx_struct mlxSTR = {}; //data structure for MLX90260 00056 #else 00057 LocalFileSystem local("local"); //for access of files on mbed itself 00058 I2C i2c1(p9, p10); 00059 MLX90620 mlx(p9, p10, "mlx"); 00060 #endif 00061 00062 PrintBuffer pb("pb"); //new for 132. Moved PrintBuffer off to .cpp and .h files 00063 00064 #if defined(TARGET_KL25Z) 00065 PwmOut rled(LED_RED); 00066 PwmOut gled(LED_GREEN); 00067 PwmOut bled(LED_BLUE); 00068 00069 int rLedDelay = 0; 00070 float rLedPwm = 0.01; //LED1 brightness 00071 bool rLedUp = true; //LED1 auto up-down 00072 int gLedDelay = 0; 00073 float gLedPwm = 0.01; //LED1 brightness 00074 bool gLedUp = true; //LED1 auto up-down 00075 int bLedDelay = 0; 00076 float bLedPwm = 0.01; //LED1 brightness 00077 bool bLedUp = true; //LED1 auto up-down 00078 #endif 00079 00080 //MLX90620 buffers used by MLX90620.cpp 00081 char* EEbuf = new char[256]; 00082 char* RamCmmd = new char[8]; //holds / sends MLX90620 RAM commands 00083 char* RamBuf = new char[128]; //0x3f words, values are 'unsigned short' 00084 int SaveEEP = 0; //***USED BY .INI FILE save EEPROM Contents to EEP.CSV 00085 00086 //For MLX90620 00087 unsigned short ConfigReg = 0; //MLX90620 configuration register 00088 float Ta = 0.0; 00089 double TempPxl = 0; 00090 00091 //Used for display of temperature and extreme values 00092 float HotPxl = -40.0; //hottest pixel in the array 00093 float ColdPxl = 200.0; //coldest pixel in the array 00094 unsigned short HotColor = 0xffff; //color of hottest pixel 00095 unsigned short ColdColor = 0xffff; //color of coldest pixel 00096 int AutoScale = 0; //***USED BY .INI FILE autoscale display 0 or 1 00097 bool ReFrame = false; //do a reframe if asked 00098 int HottestX = 0; //hottest pixel X 00099 int HottestY = 0; //hottest pixel Y 00100 int ColdestX = 0; //coldest pixel X 00101 int ColdestY = 0; //coldest pixel Y 00102 bool PickPix = false; //pick a pixel to dump all data on flag 00103 int pixX = 0; //display pixel X (0-15) 00104 int pixY = 0; //display pixel Y (0-3) 00105 00106 //Display Options 00107 int TempC = 'C'; //***USED BY .INI FILE display temperatures in degrees C or F 00108 int SensFacingAway = 0; //***USED BY .INI FILE sensor facing towards you or away from you 00109 int xHatch = 1; //***USED BY .INI FILE display hatch pattern between pixels or allow pixels to blend together 00110 float lowEnd = 20.0; //***USED BY .INI FILE low end of color temperature scale (blue end) 00111 float hiEnd = 100.0; //***USED BY .INI FILE top end of color temperature scale (red end) 00112 int PutOnPC = 1; //***USED BY .INI FILE display temperature array on PC 0 or 1. Requires VT100 terminal operation 00113 00114 //USB Serial Port Support 00115 const int PCRXBUFSIZE = 128; //pc RX buffer size 00116 char pcRxBuffer[PCRXBUFSIZE]; //RX data buffer 00117 volatile int pcRxQty = 0; //RX data counter/pointer 00118 volatile char inchar = 0; //RX input character 00119 volatile bool LocalEcho = false; //whether or not, to local echo input chars from pc 00120 volatile bool pcRxLine = false; //CR or LF detected in RX buffer 00121 volatile bool pcRxTicC = false; //^C detected in RX buffer 00122 volatile bool pcRxEOB = false; //RX buffer EOB (full) 00123 volatile bool pcRxIsNumb = false; //whether or not string is a valid number (including dp) 00124 volatile double pcRxNumb = 0.0; //RX buffer comversion 00125 int pcRxCharCnt = 0; //total number of pc RX characters received since boot 00126 int pcRxIRQCnt = 0; //total number of pc RX interrupts received since boot 00127 00128 //--------------------------------------------------------------------------------------------------------------------------------------// 00129 // Checks to see if a ^C happend. reboot if so... 00130 00131 void PcChekTicC() { 00132 if(pcRxTicC == true) { 00133 pc.printf("\n\n%s*** Control C detected, Resetting ***%s \n", doRED, doNONE); 00134 // i2c1.stop(); 00135 wait_ms(200); 00136 00137 #if defined(TARGET_KL25Z) 00138 NVIC_SystemReset(); 00139 #else 00140 mbed_reset(); 00141 #endif 00142 } 00143 } 00144 00145 //--------------------------------------------------------------------------------------------------------------------------------------// 00146 // This function is called when a character goes into the RX buffer. 00147 00148 int TicC2 = 0; 00149 00150 void PcRxChar() { 00151 pcRxCharCnt++; 00152 if(inchar == BS) { 00153 if(pcRxQty == 0) { 00154 pcRxBuffer[pcRxQty] = 0; 00155 } else { 00156 if(LocalEcho) pc.printf("%c %c", BS, BS); 00157 pcRxQty--; 00158 } 00159 } else if((inchar == CR) || (inchar == LF)) { 00160 pcRxLine = true; 00161 if(LocalEcho) pc.printf("\n"); 00162 } else if(inchar == ticC) { 00163 pcRxTicC = true; 00164 TicC2++; 00165 if(TicC2 > 2) { 00166 wait_ms(200); 00167 pc.printf("\n\n%s*** Control C detected, Resetting %sfrom IRQ!!!%s***%s \n", doRED, doGREEN, doRED, doNONE); 00168 wait_ms(200); 00169 i2c1.stop(); 00170 00171 #if defined(TARGET_KL25Z) 00172 NVIC_SystemReset(); 00173 #else 00174 mbed_reset(); 00175 #endif 00176 00177 } 00178 } else if((inchar == 'C') || (inchar == 'c')) { 00179 TempC = inchar; 00180 } else if((inchar == 'F') || (inchar == 'f')) { 00181 TempC = inchar; 00182 } else if((inchar == 'I') || (inchar == 'i')) { 00183 SensFacingAway = 0; 00184 } else if((inchar == 'O') || (inchar == 'o')) { 00185 SensFacingAway = 1; 00186 } else { 00187 if(pcRxQty < sizeof(pcRxBuffer)) { 00188 pcRxBuffer[pcRxQty] = inchar; 00189 // pcRxQty++; //NOTE: no buffer needed for this code, don't inc char pointer 00190 pcRxBuffer[pcRxQty] = 0; 00191 if(LocalEcho) pc.putc(inchar); 00192 } else { 00193 pc.printf ("\n*** pcRxBuffer is full!!\n"); 00194 pcRxEOB = true; 00195 pcRxQty = 0; 00196 pcRxBuffer[pcRxQty] = 0; 00197 } 00198 } 00199 00200 bool oneDot = false; 00201 pcRxIsNumb = true; 00202 for(int i = 0; i < pcRxQty; i++) { 00203 if(pcRxBuffer[i] == '.') { 00204 if(oneDot == true) { 00205 pcRxIsNumb = false; 00206 break; 00207 } else { 00208 oneDot = true; 00209 } 00210 } 00211 else if((pcRxBuffer[i] < '0') || (pcRxBuffer[i] > '9')) { 00212 if(!((i == 0) && (pcRxBuffer[i] == '-'))) { 00213 pcRxIsNumb = false; 00214 break; 00215 } 00216 } 00217 } 00218 } 00219 00220 //--------------------------------------------------------------------------------------------------------------------------------------// 00221 // Read received chars from USB UART 00222 00223 void PcRxIRQ(void){ 00224 pcRxIRQCnt++; 00225 #if defined(TARGET_KL25Z) 00226 NVIC_DisableIRQ(UART0_IRQn); // n=0, 1 or 2 Disable Rx interrupt on kl25z 00227 #else 00228 LPC_UART0->IER = 0; //Disable Rx interrupt on mbed1768 00229 #endif 00230 while (pc.readable()) { 00231 inchar = pc.getc(); //read data from USB 00232 PcRxChar(); //go process char 00233 } 00234 #if defined(TARGET_KL25Z) 00235 NVIC_EnableIRQ(UART0_IRQn); //re-enable Rx interrupt on kl25z 00236 #else 00237 LPC_UART0->IER = 1; //re-enable Rx interrupt on mbed1768 00238 #endif 00239 } 00240 00241 //--------------------------------------------------------------------------------------------------------------------------------------// 00242 //fixing a screwup on the eeprom from an accidental write 00243 00244 void FixEEP() { 00245 EEbuf[0] = 0x10; //starting address of EEP to write to, pages 0 - 31 * 8 00246 EEbuf[1] = 0xed; 00247 EEbuf[2] = 0xee; 00248 EEbuf[3] = 0xee; 00249 EEbuf[4] = 0xec; 00250 EEbuf[5] = 0xee; 00251 EEbuf[6] = 0xef; 00252 EEbuf[7] = 0xef; 00253 EEbuf[8] = 0xed; 00254 i2c1.write(0xa0, EEbuf, 9, false); 00255 wait_ms(6); //datasheet says 5mS max 00256 00257 } 00258 00259 //--------------------------------------------------------------------------------------------------------------------------------------// 00260 //Reload EEPROM image from file /local/EEP.CSV 00261 00262 #if defined(TARGET_KL25Z) 00263 #else 00264 char* FileBuf = new char[1024]; 00265 char tbuf[256]; 00266 00267 int ReloadEEP() { 00268 FILE *fps = fopen("/local/EEP.CSV", "r"); 00269 if (fps == NULL) { 00270 return(0); 00271 } else { 00272 for(int i = 0; i < 256; i++) { 00273 int x = -1; 00274 do{ 00275 x++; 00276 FileBuf[x] = fgetc(fps); 00277 if(FileBuf[x] == '\n') { 00278 x--; 00279 } 00280 } while((FileBuf[x] != ',')); 00281 x--; 00282 tbuf[i] = char(strtod(FileBuf, &FileBuf)); 00283 EEbuf[i] = tbuf[i]; 00284 } 00285 fclose(fps); 00286 return(1); 00287 } 00288 } 00289 00290 //--------------------------------------------------------------------------------------------------------------------------------------// 00291 //re-write all of the MLX EEPROM from file EEP.CSV. Returns 0, no write error. 1 - 32 for failed page 00292 //tbuf contains the source data. ReloadEEP() must be run first!!! 00293 00294 int FixAllEEP() { 00295 for(int i = 0; i < 32; i++) { //32, 8 byte pages 00296 EEbuf[0] = i * 8; //EEPROM page # 00297 EEbuf[1] = tbuf[i * 8]; 00298 EEbuf[2] = tbuf[i * 8 + 1]; 00299 EEbuf[3] = tbuf[i * 8 + 2]; 00300 EEbuf[4] = tbuf[i * 8 + 3]; 00301 EEbuf[5] = tbuf[i * 8 + 4]; 00302 EEbuf[6] = tbuf[i * 8 + 5]; 00303 EEbuf[7] = tbuf[i * 8 + 6]; 00304 EEbuf[8] = tbuf[i * 8 + 7]; 00305 if(!(i2c1.write(0xa0, EEbuf, 9, false))) { //store 8 byte page 00306 i2c1.stop(); 00307 } 00308 wait_ms(10); //datasheet says 5mS max 00309 } 00310 return(0); 00311 } 00312 #endif 00313 00314 //--------------------------------------------------------------------------------------------------------------------------------------// 00315 //Detect I2C device chain 00316 00317 int i2cQty = 16; //number of bytes to get 00318 char i2cData[32]; //i2c buffer data 00319 00320 void find_i2c1() { 00321 if(gDebug > 1) pc.printf("Searching for I2C devices on bus 1...\n"); 00322 00323 int count = 0; 00324 for (int address = 2; address < 256; address +=2) { 00325 if (!i2c1.write(address, NULL, 0)) { // 0 returned is ok 00326 wait_ms(5); 00327 if(gDebug > 1) pc.printf(" - I2C device found at address 0x%02X\n", address); 00328 for (int clrb = 0; clrb < i2cQty; clrb +=1) { //clear out i2c buffer before reading in data 00329 i2cData[clrb] = 0; 00330 } 00331 count++; 00332 } 00333 } 00334 if(gDebug > 1) pc.printf(" - I2seeU! %d devices found\n", count); 00335 } 00336 00337 //--------- 00338 #if defined(TARGET_KL25Z) 00339 void find_i2c2() { 00340 if(gDebug > 1) pc.printf("Searching for I2C devices on bus 2...\n"); 00341 00342 int count = 0; 00343 for (int address = 2; address < 256; address +=2) { 00344 if (!i2c2.write(address, NULL, 0)) { // 0 returned is ok 00345 wait_ms(5); 00346 if(gDebug > 1) pc.printf(" - I2C device found at address 0x%02X\n", address); 00347 for (int clrb = 0; clrb < i2cQty; clrb +=1) { //clear out i2c buffer before reading in data 00348 i2cData[clrb] = 0; 00349 } 00350 count++; 00351 } 00352 } 00353 if(gDebug > 1) pc.printf(" - I2seeU! %d devices found\n", count); 00354 } 00355 00356 //--------------------------------------------------------------------------------------------------------------------------------------// 00357 // moving RGB LED display. Hacked from: david dicarlo / FRDM_RGBLED 00358 00359 const float pi = 3.1415927; 00360 float iLeds = 0.0; 00361 00362 void sinLEDs() { 00363 iLeds += 0.02; // was 0.001 in original code 00364 if(iLeds > (60.0 * pi)) iLeds = 0.0; 00365 rLedPwm = (1 + sin(2 * iLeds)) / 2; // calculate values for RGB based on different 00366 gLedPwm = (1 + sin(3 * iLeds)) / 2; // frequency sin waves. This should give a nice 00367 bLedPwm = (1 + sin(5 * iLeds)) / 2; // smooth transistion between colors and a 00368 rled = rLedPwm; // send RGB values to LED PWMs 00369 gled = gLedPwm; 00370 bled = bLedPwm; 00371 } 00372 00373 #endif 00374 //--------------------------------------------------------------------------------------------------------------------------------------// 00375 // See if new temperature in array is higher then the current hottest or colder then the current coldest 00376 00377 void CheckNewExtreme() { 00378 if(TempPxl > HotPxl) { 00379 HotPxl = TempPxl; 00380 HottestX = pixX / 4; 00381 HottestY = pixY; 00382 } 00383 if(TempPxl < ColdPxl) { 00384 ColdPxl = TempPxl; 00385 ColdestX = pixX / 4; 00386 ColdestY = pixY; 00387 } 00388 } 00389 00390 //--------------------------------------------------------------------------------------------------------------------------------------// 00391 // Change color of extreme tempeature values on PC using VT100 escape sequences 00392 00393 bool PCdeftFlag = true; 00394 00395 void PCExtreme() { 00396 if((HottestX == (pixX / 4)) && (HottestY == pixY)) { 00397 PCdeftFlag = false; 00398 pc.printf("%c[8;31;2m", ESC); 00399 return; 00400 } else 00401 if((ColdestX == (pixX / 4)) && (ColdestY == pixY)) { 00402 PCdeftFlag = false; 00403 pc.printf("%c[8;34;2m", ESC); 00404 return; 00405 } else 00406 if(PCdeftFlag == false) { 00407 PCdeftFlag = true; 00408 pc.printf("%c[8;30m", ESC); 00409 } 00410 } 00411 00412 //--------------------------------------------------------------------------------------------------------------------------------------// 00413 // Pick a pixel to print out temperature. X = column 0 - 15, Y = row 0 - 3 00414 00415 void PickaPixel(int pX, int pY) { 00416 TempPxl = mlx.CalcPixel(mlxSTR, pX + pY); 00417 if ((TempC == 'c') || (TempC == 'C')) { 00418 pc.printf("Pixel X:%d Y:%d Temp: %.2f degC\n", pX / 4, pY, TempPxl); 00419 } else { 00420 pc.printf("Pixel X:%d Y:%d Temp: %.2f degF\n", pX / 4, pY, TempPxl * 9.0 / 5.0 + 32.0); 00421 } 00422 } 00423 00424 //--------------------------------------------------------------------------------------------------------------------------------------// 00425 // Display on PC using VT100 escape codes 00426 00427 const int TTX = 45; 00428 const int TTY = 120; 00429 int tX = TTX; 00430 int tY = TTY;; 00431 00432 int AllowVT100 = 0; 00433 00434 void ShowTempsVT100() { 00435 if(AllowVT100 <= 3) { //update PC display every 4th TFT pixel update 00436 return; 00437 } 00438 AllowVT100 = 0; 00439 double HoldTemp = TempPxl; 00440 if(SensFacingAway == 1) { 00441 pc.printf("%c[8;30m%c[6AArray Temperature deg%c \\\\ ^ // \n F E D C B A 9 8 7 6 5 4 3 2 1 0 \n", ESC, ESC, (TempC & 0x5f)); 00442 for(pixY = 0; pixY <= 3; pixY++) { 00443 for(pixX = 60; pixX >= 0; pixX = pixX - 4) { 00444 TempPxl = mlx.CalcPixel(mlxSTR, pixX + pixY); 00445 if ((TempC == 'c') || (TempC == 'C')) { 00446 HoldTemp = TempPxl; 00447 } else { 00448 HoldTemp = TempPxl * 9.0 / 5.0 + 32.0; 00449 } 00450 PCExtreme(); 00451 if(HoldTemp >= 100.0) { 00452 pc.printf(" %.1f ", HoldTemp); 00453 } else 00454 if((HoldTemp <= 10.0) && (HoldTemp >= 0.0)) { 00455 pc.printf(" %.2f ", HoldTemp); 00456 } else 00457 if((HoldTemp >= -10.0) && (HoldTemp < 0.0)) { 00458 pc.printf(" %.2f ", HoldTemp); 00459 } else 00460 if(HoldTemp < -10.0) { 00461 pc.printf("%.2f ", HoldTemp); 00462 } else { 00463 pc.printf(" %.2f ", HoldTemp); 00464 } 00465 } 00466 PCdeftFlag = true; 00467 pc.printf("%c[8;30m%2d \n", ESC, pixY); 00468 // pc.printf("%2d \n", pixY); 00469 } 00470 } else { 00471 pc.printf("%c[8;30m%c[6AArray Temperature deg%c // v \\\\ \n 0 1 2 3 4 5 6 7 8 9 A B C D E F \n", ESC, ESC, (TempC & 0x5f)); 00472 for(pixY = 0; pixY <= 3; pixY++) { 00473 for(pixX = 0; pixX < 64; pixX = pixX + 4) { 00474 TempPxl = mlx.CalcPixel(mlxSTR, pixX + pixY); 00475 if ((TempC == 'c') || (TempC == 'C')) { 00476 HoldTemp = TempPxl; 00477 } else { 00478 HoldTemp = TempPxl * 9.0 / 5.0 + 32.0; 00479 } 00480 PCExtreme(); 00481 if(HoldTemp >= 100.0) { 00482 pc.printf(" %.1f ", HoldTemp); 00483 } else 00484 if((HoldTemp <= 10.0) && (HoldTemp >= 0.0)) { 00485 pc.printf(" %.2f ", HoldTemp); 00486 } else 00487 if((HoldTemp >= -10.0) && (HoldTemp < 0.0)) { 00488 pc.printf(" %.2f ", HoldTemp); 00489 } else 00490 if(HoldTemp < -10.0) { 00491 pc.printf("%.2f ", HoldTemp); 00492 } else { 00493 pc.printf(" %.2f ", HoldTemp); 00494 } 00495 } 00496 pc.printf("%c[8;30m%2d \n", ESC, pixY); 00497 } 00498 } 00499 } 00500 00501 //--------------------------------------------------------------------------------------------------------------------------------------// 00502 // Display Pixels in color 00503 00504 int loop = 0; 00505 bool GotAmbient = false; 00506 bool FirstRamDump = true; 00507 00508 int ShowTempsColor() { 00509 // ConfigReg = mlx.GetConfigReg(); 00510 00511 //because of change to normal mode... 00512 ConfigReg = 0; 00513 wait_ms(185); //balance out to display is about once per second 00514 //end of because of change 00515 00516 /* 00517 #ifdef MLX_KL25Z 00518 NVIC_DisableIRQ(UART0_IRQn); // n=0, 1 or 2 Disable Rx interrupt on kl25z 00519 #else 00520 LPC_UART0->IER = 0; //Disable Rx interrupt on mbed1768 00521 #endif 00522 */ 00523 if(GotAmbient == false) { 00524 if((ConfigReg & MLX_TAMEASFLAG) == 0) { 00525 mlx.CalcTa_To(mlxSTR); 00526 Ta = mlx.GetDieTemp(mlxSTR); 00527 // pc.printf("Ta = %f\n\n\n\n\n\n\n", Ta); 00528 GotAmbient = true; 00529 } else { 00530 return(ConfigReg & MLX_TAMEASFLAG); 00531 } 00532 } 00533 if((ConfigReg & MLX_IRMEASFLAG) == 0) { 00534 loop++; 00535 GotAmbient = false; 00536 if(ReFrame == true) { 00537 if(gDebug > 2) pc.printf("AutoScale Update, lowEnd: %4.0fC hiEnd: %4.0fC\n", lowEnd, hiEnd); 00538 ReFrame = false; 00539 } 00540 AllowVT100++; 00541 HotPxl = -40.0; 00542 ColdPxl = 200.0; 00543 mlx.LoadMLXRam(mlxSTR); 00544 if((gDebug > 1) && (FirstRamDump == true)) { 00545 FirstRamDump = false; 00546 pc.printf("First RAM dump"); 00547 pb.dump("Ram Buffer:", 8, 0, RamBuf); 00548 if(PutOnPC == 1) { 00549 //pc.printf("\n\n\n\n\n\n\n"); 00550 } 00551 } else 00552 if((PutOnPC == 1) && (FirstRamDump == true)) { 00553 FirstRamDump = false; 00554 pc.printf("\n\n\n\n\n\n\n"); 00555 } 00556 00557 tX = TTX; 00558 tY = TTY; 00559 mlx.StartMeasurement(mlxSTR); 00560 /* 00561 #ifdef MLX_KL25Z 00562 NVIC_EnableIRQ(UART0_IRQn); //re-enable Rx interrupt on kl25z 00563 #else 00564 LPC_UART0->IER = 1; //re-enable Rx interrupt on mbed1768 00565 #endif 00566 */ 00567 if(gDebug > 3) pc.printf("Array Temperature degC\n 3 2 1 0\n"); 00568 if(SensFacingAway == 1) { 00569 for(pixX = 60; pixX >= 0; pixX = pixX - 4) { 00570 for(pixY = 3; pixY >= 0; pixY--) { 00571 if((pixX == 16 * 4) && (pixY == 2)) { 00572 PickaPixel(pixX, pixY); 00573 PickPix = true; 00574 } else { 00575 PickPix = false; 00576 } 00577 TempPxl = mlx.CalcPixel(mlxSTR, pixX + pixY); 00578 CheckNewExtreme(); 00579 if(gDebug > 3) pc.printf("%4.2f ", TempPxl); 00580 } 00581 if(gDebug > 3) pc.printf("%2d\n", (pixX / 4)); 00582 } 00583 } else { 00584 for(pixX = 0; pixX < 64; pixX = pixX + 4) { 00585 for(pixY = 3; pixY >= 0; pixY--) { 00586 if((pixX == 16 * 4) && (pixY == 1)) { //0-15 and 0-3 00587 PickaPixel(pixX, pixY); 00588 PickPix = true; 00589 } else { 00590 PickPix = false; 00591 } 00592 TempPxl = mlx.CalcPixel(mlxSTR, pixX + pixY); 00593 CheckNewExtreme(); 00594 if(gDebug > 3) pc.printf("%4.2f ", TempPxl); 00595 } 00596 if(gDebug > 3) pc.printf("%2d\n", (pixX / 4)); 00597 } 00598 } 00599 if(gDebug > 3) pc.printf("\nloop: %d\n", loop); 00600 } 00601 return(0); 00602 } 00603 00604 //--------------------------------------------------------------------------------------------------------------------------------------// 00605 //--------------------------------------------------------------------------------------------------------------------------------------// 00606 00607 int main(void) { 00608 GotAmbient = false; 00609 i2c1.frequency(400000); //set up i2c speed 00610 i2c1.stop(); 00611 00612 #if defined(TARGET_KL25Z) 00613 i2c2.frequency(400000); //set up i2c speed 00614 i2c2.stop(); 00615 rled.period_us(1000); 00616 gled.period_us(1000); 00617 bled.period_us(1000); 00618 gLedUp = false; 00619 rLedPwm = 0.001; 00620 gLedPwm = 0.700; 00621 bLedPwm = 0.300; 00622 rled = 1.0 - rLedPwm; 00623 gled = 1.0 - gLedPwm; 00624 bled = 1.0 - bLedPwm; 00625 pc.baud(115200); 00626 #else 00627 pc.baud(921600); 00628 #endif 00629 00630 pc.printf("\n\n--------------------------------------------\n"); 00631 pc.printf("mbed1768 / FRDM-KL25Z MLX90620 Tests %sv%d%s\n", doBLUE, revision, doNONE); 00632 00633 //initialize the USB serial port interrupt 00634 pc.printf("Initializing Serial Port Rx Interrupt... \n"); 00635 pc.attach(&PcRxIRQ, pc.RxIrq); 00636 00637 //look for devices on i2c buses 00638 find_i2c1(); 00639 00640 #if defined(TARGET_KL25Z) 00641 find_i2c2(); 00642 #else 00643 //mbed1768 only, see if MLX90620 eeprom contents file saved. If so, dump on display 00644 if (ReloadEEP()) { 00645 if(gDebug > 1) { 00646 pb.dump("\nEEP.CVS file dump", 16, 0,tbuf); 00647 } 00648 } else { 00649 pc.printf("*** file /local/EEP.CSV does not exist\n"); 00650 } 00651 #endif 00652 00653 //DANGEROUS!!! FixEEP is for fixing small portions of the EEPROM on the MLX90620. 00654 //Fixes 8 bytes in EEPROM at a time. This is a manual operation, requiring a recompile each 00655 //time. You have to set up the starting EEP address and 8 bytes of data to be written 00656 //in routine FixEEP 00657 00658 //FixEEP(); 00659 00660 int initFail = 0; 00661 //load up eeprom into buffer 00662 if((mlx.LoadEEPROM(mlxSTR))) { 00663 pc.printf("*** MLX90620 dump failed!!!\n"); 00664 initFail++; 00665 } else { 00666 if(gDebug > 1) { 00667 //pc.printf("\nEEPROM array"); 00668 pb.dump("EEPROM Array:", 16, 0, EEbuf); 00669 } 00670 } 00671 00672 //Init MLX90620 00673 unsigned short x = 0; 00674 if((mlx.SetOscTrimReg(mlxSTR))) { 00675 pc.printf("*** set osc trim failed!!!\n"); 00676 initFail++; 00677 } else { 00678 x = mlx.GetOscTrimReg(mlxSTR); 00679 pc.printf("Osc Trim Value: 0x%04x\n", x); 00680 } 00681 00682 if((mlx.SetConfigReg(mlxSTR))) { 00683 pc.printf("*** set MLX config failed!!!\n"); 00684 initFail++; 00685 } else { 00686 x = mlx.GetConfigReg(mlxSTR); 00687 pc.printf("Config Register: 0x%04x\n", x); 00688 x = mlx.GetPTATReg(mlxSTR); 00689 pc.printf("PTAT Register: 0x%04x\n", x); 00690 } 00691 00692 if((mlx.StartMeasurement(mlxSTR))) { 00693 pc.printf("*** Start Measurement failed!!!\n"); 00694 initFail++; 00695 } 00696 wait_ms(300); 00697 00698 if(initFail == 0) { 00699 pc.printf("Calculating Ta...\n"); 00700 mlx.CalcTa_To(mlxSTR); 00701 pc.printf("Getting die temperature...\n"); 00702 Ta = mlx.GetDieTemp(mlxSTR); 00703 pc.printf("Ta = %f\n\n", Ta); 00704 } else { 00705 pc.printf("*** MLX90620 non operational!!!\n"); 00706 } 00707 ShowTempsColor(); 00708 00709 pc.printf("At any time, type:\n %sO%s = Pointing Outward\n %sI%s = Pointing Inward\n %sC%s = Temp Degrees C\n %sF%s = Temp Degrees F\n%s^C%s = reboot\n\n", 00710 doGREEN, doNONE, doGREEN, doNONE, doGREEN, doNONE, doGREEN, doNONE, doRED, doNONE); 00711 pc.printf("Ready...\n"); 00712 pc.printf("\n\n\n\n\n\n\n"); 00713 00714 while (true) { 00715 PcChekTicC(); 00716 int lc = 0; 00717 if(!(ShowTempsColor())) { 00718 do { 00719 lc++; 00720 //pc.printf("waiting... %d\n", lc); 00721 wait_ms(1); 00722 } while(ShowTempsColor() != 0); 00723 00724 #if defined(TARGET_KL25Z) 00725 sinLEDs(); 00726 #endif 00727 00728 } 00729 if(PutOnPC == 1) { 00730 ShowTempsVT100(); 00731 } 00732 } 00733 } 00734 00735
Generated on Fri Jul 22 2022 13:51:42 by 1.7.2