Generates a test signal on an AnalogOut and monitors a signal on an AnalogIn, plotting the test signal or the actual signal depending on a conditional compile. The wait() and wait_ms() library calls for this board are highly inaccurate so a new function is provided to wait for X number of milliseconds -- which is not very accurate.

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI mbed-os BSP_DISCO_F429ZI

Committer:
Damotclese
Date:
Mon Jun 17 17:11:07 2019 +0000
Revision:
2:cbcf2695a4a1
Added average TEC history;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Damotclese 2:cbcf2695a4a1 1
Damotclese 2:cbcf2695a4a1 2 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 3 // LaserMon-TEC.cpp
Damotclese 2:cbcf2695a4a1 4 //
Damotclese 2:cbcf2695a4a1 5 // Fredric L. Rice, June 2019
Damotclese 2:cbcf2695a4a1 6 //
Damotclese 2:cbcf2695a4a1 7 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 8
Damotclese 2:cbcf2695a4a1 9 #include "mbed.h" // The mbed operating system
Damotclese 2:cbcf2695a4a1 10 #include "LCD_DISCO_F429ZI.h" // For controlling the LCD
Damotclese 2:cbcf2695a4a1 11 #include "TS_DISCO_F429ZI.h" // For controlling the touch screen
Damotclese 2:cbcf2695a4a1 12 #include "LaserMon-Main.h" // For data exported to us
Damotclese 2:cbcf2695a4a1 13 #include "LaserMon-TEC.h" // Always include ourself
Damotclese 2:cbcf2695a4a1 14
Damotclese 2:cbcf2695a4a1 15 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 16 // Local data storage
Damotclese 2:cbcf2695a4a1 17 //
Damotclese 2:cbcf2695a4a1 18 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 19
Damotclese 2:cbcf2695a4a1 20 // We bring in the TEC voltage to scan what it is
Damotclese 2:cbcf2695a4a1 21 static AnalogIn st_TECInput(TEC_VOLTAGE_IN);
Damotclese 2:cbcf2695a4a1 22
Damotclese 2:cbcf2695a4a1 23 // We store the last ten TEC readings and keep a running average
Damotclese 2:cbcf2695a4a1 24 // of the last ten so that the main module may find out what the
Damotclese 2:cbcf2695a4a1 25 // average is and display it
Damotclese 2:cbcf2695a4a1 26 static uint16_t u16_TECHistory[TEC_HISTORY_COUNT_MAX];
Damotclese 2:cbcf2695a4a1 27 static uint8_t u8_TECHistoryCount;
Damotclese 2:cbcf2695a4a1 28 static uint16_t u16_TECHistoryRunningAverage;
Damotclese 2:cbcf2695a4a1 29
Damotclese 2:cbcf2695a4a1 30 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 31 // TECGetLastTenAverage()
Damotclese 2:cbcf2695a4a1 32 //
Damotclese 2:cbcf2695a4a1 33 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 34 uint16_t TECGetLastTenAverage(void)
Damotclese 2:cbcf2695a4a1 35 {
Damotclese 2:cbcf2695a4a1 36 return u16_TECHistoryRunningAverage;
Damotclese 2:cbcf2695a4a1 37 }
Damotclese 2:cbcf2695a4a1 38
Damotclese 2:cbcf2695a4a1 39 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 40 //
Damotclese 2:cbcf2695a4a1 41 //
Damotclese 2:cbcf2695a4a1 42 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 43 void TECThread(void)
Damotclese 2:cbcf2695a4a1 44 {
Damotclese 2:cbcf2695a4a1 45 uint16_t u16_TECVoltage = 0;
Damotclese 2:cbcf2695a4a1 46 float f_rawTECVoltage = 0.0f;
Damotclese 2:cbcf2695a4a1 47
Damotclese 2:cbcf2695a4a1 48 // Get the current voltage
Damotclese 2:cbcf2695a4a1 49 f_rawTECVoltage = st_TECInput.read() * 3.3f;
Damotclese 2:cbcf2695a4a1 50
Damotclese 2:cbcf2695a4a1 51 // The TEC voltage is converted from a floating point in to
Damotclese 2:cbcf2695a4a1 52 // 16 bit value with the value after the decimal moved to
Damotclese 2:cbcf2695a4a1 53 // the right by two decimal place
Damotclese 2:cbcf2695a4a1 54 u16_TECVoltage = (uint16_t)(f_rawTECVoltage * 100.0f);
Damotclese 2:cbcf2695a4a1 55
Damotclese 2:cbcf2695a4a1 56 // Inform the main module what the TEC voltage is
Damotclese 2:cbcf2695a4a1 57 LaserMonMainInformTECVoltage(u16_TECVoltage);
Damotclese 2:cbcf2695a4a1 58
Damotclese 2:cbcf2695a4a1 59 // Do we have lessd than our TEC history values stored so far?
Damotclese 2:cbcf2695a4a1 60 if (u8_TECHistoryCount < TEC_HISTORY_COUNT_MAX)
Damotclese 2:cbcf2695a4a1 61 {
Damotclese 2:cbcf2695a4a1 62 // Since we have fewer than our maximum history, store it
Damotclese 2:cbcf2695a4a1 63 u16_TECHistory[u8_TECHistoryCount++] = u16_TECVoltage;
Damotclese 2:cbcf2695a4a1 64 }
Damotclese 2:cbcf2695a4a1 65 else
Damotclese 2:cbcf2695a4a1 66 {
Damotclese 2:cbcf2695a4a1 67 #if 1
Damotclese 2:cbcf2695a4a1 68 // Discard the oldest history value that we have
Damotclese 2:cbcf2695a4a1 69 for (uint8_t u8_thisValue = 1; u8_thisValue < TEC_HISTORY_COUNT_MAX; u8_thisValue++)
Damotclese 2:cbcf2695a4a1 70 {
Damotclese 2:cbcf2695a4a1 71 // Move the history value over to the left once
Damotclese 2:cbcf2695a4a1 72 u16_TECHistory[u8_thisValue] = u16_TECHistory[u8_thisValue - 1];
Damotclese 2:cbcf2695a4a1 73 }
Damotclese 2:cbcf2695a4a1 74
Damotclese 2:cbcf2695a4a1 75 // Now store the latest value in to the history array
Damotclese 2:cbcf2695a4a1 76 u16_TECHistory[TEC_HISTORY_COUNT_MAX - 1] = u16_TECVoltage;
Damotclese 2:cbcf2695a4a1 77 #endif
Damotclese 2:cbcf2695a4a1 78 }
Damotclese 2:cbcf2695a4a1 79
Damotclese 2:cbcf2695a4a1 80 // Compute the average TEC value
Damotclese 2:cbcf2695a4a1 81 u16_TECHistoryRunningAverage = 0;
Damotclese 2:cbcf2695a4a1 82
Damotclese 2:cbcf2695a4a1 83 for (uint8_t u8_thisValue = 0; u8_thisValue < u8_TECHistoryCount; u8_thisValue++)
Damotclese 2:cbcf2695a4a1 84 {
Damotclese 2:cbcf2695a4a1 85 u16_TECHistoryRunningAverage += u16_TECHistory[u8_thisValue];
Damotclese 2:cbcf2695a4a1 86 }
Damotclese 2:cbcf2695a4a1 87
Damotclese 2:cbcf2695a4a1 88 // Compute the average
Damotclese 2:cbcf2695a4a1 89 u16_TECHistoryRunningAverage /= u8_TECHistoryCount;
Damotclese 2:cbcf2695a4a1 90 }
Damotclese 2:cbcf2695a4a1 91
Damotclese 2:cbcf2695a4a1 92 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 93 //
Damotclese 2:cbcf2695a4a1 94 //
Damotclese 2:cbcf2695a4a1 95 // ----------------------------------------------------------------------
Damotclese 2:cbcf2695a4a1 96 void TECInit(void)
Damotclese 2:cbcf2695a4a1 97 {
Damotclese 2:cbcf2695a4a1 98 // Initialize locally-held data
Damotclese 2:cbcf2695a4a1 99 u8_TECHistoryCount = 0;
Damotclese 2:cbcf2695a4a1 100 u16_TECHistoryRunningAverage = 0;
Damotclese 2:cbcf2695a4a1 101 }
Damotclese 2:cbcf2695a4a1 102
Damotclese 2:cbcf2695a4a1 103 // End of file
Damotclese 2:cbcf2695a4a1 104