Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI mbed-os BSP_DISCO_F429ZI
LaserMon-TEC.cpp
00001 00002 // ---------------------------------------------------------------------- 00003 // LaserMon-TEC.cpp 00004 // 00005 // Fredric L. Rice, June 2019 00006 // 00007 // ---------------------------------------------------------------------- 00008 00009 #include "mbed.h" // The mbed operating system 00010 #include "LCD_DISCO_F429ZI.h" // For controlling the LCD 00011 #include "TS_DISCO_F429ZI.h" // For controlling the touch screen 00012 #include "LaserMon-Main.h" // For data exported to us 00013 #include "LaserMon-TEC.h" // Always include ourself 00014 00015 // ---------------------------------------------------------------------- 00016 // Local data storage 00017 // 00018 // ---------------------------------------------------------------------- 00019 00020 // We bring in the TEC voltage to scan what it is 00021 static AnalogIn st_TECInput(TEC_VOLTAGE_IN); 00022 00023 // We store the last ten TEC readings and keep a running average 00024 // of the last ten so that the main module may find out what the 00025 // average is and display it 00026 static uint16_t u16_TECHistory[TEC_HISTORY_COUNT_MAX]; 00027 static uint8_t u8_TECHistoryCount; 00028 static uint16_t u16_TECHistoryRunningAverage; 00029 00030 // ---------------------------------------------------------------------- 00031 // TECGetLastTenAverage() 00032 // 00033 // ---------------------------------------------------------------------- 00034 uint16_t TECGetLastTenAverage(void) 00035 { 00036 return u16_TECHistoryRunningAverage; 00037 } 00038 00039 // ---------------------------------------------------------------------- 00040 // 00041 // 00042 // ---------------------------------------------------------------------- 00043 void TECThread(void) 00044 { 00045 uint16_t u16_TECVoltage = 0; 00046 float f_rawTECVoltage = 0.0f; 00047 00048 // Get the current voltage 00049 f_rawTECVoltage = st_TECInput.read() * 3.3f; 00050 00051 // The TEC voltage is converted from a floating point in to 00052 // 16 bit value with the value after the decimal moved to 00053 // the right by two decimal place 00054 u16_TECVoltage = (uint16_t)(f_rawTECVoltage * 100.0f); 00055 00056 // Inform the main module what the TEC voltage is 00057 LaserMonMainInformTECVoltage(u16_TECVoltage); 00058 00059 // Do we have lessd than our TEC history values stored so far? 00060 if (u8_TECHistoryCount < TEC_HISTORY_COUNT_MAX) 00061 { 00062 // Since we have fewer than our maximum history, store it 00063 u16_TECHistory[u8_TECHistoryCount++] = u16_TECVoltage; 00064 } 00065 else 00066 { 00067 #if 1 00068 // Discard the oldest history value that we have 00069 for (uint8_t u8_thisValue = 1; u8_thisValue < TEC_HISTORY_COUNT_MAX; u8_thisValue++) 00070 { 00071 // Move the history value over to the left once 00072 u16_TECHistory[u8_thisValue] = u16_TECHistory[u8_thisValue - 1]; 00073 } 00074 00075 // Now store the latest value in to the history array 00076 u16_TECHistory[TEC_HISTORY_COUNT_MAX - 1] = u16_TECVoltage; 00077 #endif 00078 } 00079 00080 // Compute the average TEC value 00081 u16_TECHistoryRunningAverage = 0; 00082 00083 for (uint8_t u8_thisValue = 0; u8_thisValue < u8_TECHistoryCount; u8_thisValue++) 00084 { 00085 u16_TECHistoryRunningAverage += u16_TECHistory[u8_thisValue]; 00086 } 00087 00088 // Compute the average 00089 u16_TECHistoryRunningAverage /= u8_TECHistoryCount; 00090 } 00091 00092 // ---------------------------------------------------------------------- 00093 // 00094 // 00095 // ---------------------------------------------------------------------- 00096 void TECInit(void) 00097 { 00098 // Initialize locally-held data 00099 u8_TECHistoryCount = 0; 00100 u16_TECHistoryRunningAverage = 0; 00101 } 00102 00103 // End of file 00104
Generated on Thu Jul 14 2022 16:41:21 by
1.7.2