![](/media/cache/profiles/f.jpg.50x50_q85.jpg)
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
LaserMon-Main.cpp
- Committer:
- Damotclese
- Date:
- 2019-06-10
- Revision:
- 0:1ebe7d222470
- Child:
- 1:b9d4b9b8884c
File content as of revision 0:1ebe7d222470:
// ---------------------------------------------------------------------- // LaserMon-Main.cpp // // Fredric L. Rice, June 2019 // // ---------------------------------------------------------------------- #include "mbed.h" // The mbed operating system #include "LCD_DISCO_F429ZI.h" // For controlling the LCD #include "TS_DISCO_F429ZI.h" // For controlling the touch screen #include "LaserMon-TestOutput.h" // For generating test output signal #include "LaserMon-ScanInput.h" // For monitoring laser power pin #include "LaserMon-Main.h" // Always include ourself // ---------------------------------------------------------------------- // Local data storage // // ---------------------------------------------------------------------- const char * pch_firstMessage = "Test signal on PA_5"; const char * pch_secondMessage = "Laser Scan on PC_1"; // ---------------------------------------------------------------------- // Define global data storage which we will export // // ---------------------------------------------------------------------- // We will be using the LCD so instantiate an object locally LCD_DISCO_F429ZI st_lcd; // We will be using the touch screen so instantiate an object TS_DISCO_F429ZI st_touchScreen; // ---------------------------------------------------------------------- // MainInit() // // ---------------------------------------------------------------------- static void MainInit(void) { // Bring the LCD up st_lcd.Clear(LCD_COLOR_WHITE); // Set the default text color st_lcd.SetTextColor(LCD_COLOR_BLUE); // Set the background color st_lcd.SetBackColor(LCD_COLOR_WHITE); // Set the default font size BSP_LCD_SetFont(&Font16); } // ---------------------------------------------------------------------- // main() // // // ---------------------------------------------------------------------- int main(void) { // Perform local module initialization, if any MainInit(); // Start generating the putput test signal TestOutputInit(); // Start scanning the laser drive power ScanInputInit(); // Display information about what signal pigs have what st_lcd.DisplayStringAt(1, LINE(1), (uint8_t *)pch_firstMessage, LEFT_MODE); st_lcd.DisplayStringAt(1, LINE(2), (uint8_t *)pch_secondMessage, LEFT_MODE); // Go in to a forever loop for the main thread which does nothing while(true) { // Wait for 1 second and then wait again wait(1.0); } } // ---------------------------------------------------------------------- // accurate_wait_ms() // // Because the wait() and wait_ms() library calls for the board we are // using is not accurate, this function is provided which uses // microseconds to scale the requested wait offered in milliseconds. // // ---------------------------------------------------------------------- void accurate_wait_ms(uint16_t u16_thisManyMilliseconds) { // There are one million microseconds in a second // There are one thousand milliseconds in a second // Compute how many microseconds would normally be needed to // perform the reqested number of milliseconds to wait if the // system clock / crystal were accurate uint64_t u64_thisManyMicroseconds = (u16_thisManyMilliseconds * 100000); // Since the clock appears to run much faster than expected by // the mbed library, divide the number of microseconds by a // hard-coded scaling factor to attempt to yield a number that // is closer to what we actually get u64_thisManyMicroseconds /= 300ul; // Now wait that many microseconds asking the library to do it wait_us((int)u64_thisManyMicroseconds); } // End of file