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-TestOutput.cpp@1:b9d4b9b8884c, 2019-06-14 (annotated)
- Committer:
- Damotclese
- Date:
- Fri Jun 14 21:11:31 2019 +0000
- Revision:
- 1:b9d4b9b8884c
- Parent:
- 0:1ebe7d222470
- Child:
- 2:cbcf2695a4a1
Threat timing is very bad, a thread will average waking up once a millisecond when asked but there is a lot of slop. Instead of launching threads I instead call the "threads" from main() now.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Damotclese | 0:1ebe7d222470 | 1 | |
Damotclese | 0:1ebe7d222470 | 2 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 3 | // LaserMon-TestOutput.cpp |
Damotclese | 0:1ebe7d222470 | 4 | // |
Damotclese | 0:1ebe7d222470 | 5 | // Fredric L. Rice, June 2019 |
Damotclese | 0:1ebe7d222470 | 6 | // |
Damotclese | 0:1ebe7d222470 | 7 | // For testing purposes only, this test output wave form can be |
Damotclese | 0:1ebe7d222470 | 8 | // jumpered in to the laser scan analog input signal so that the |
Damotclese | 0:1ebe7d222470 | 9 | // software can be developed without the need for an ISEM. |
Damotclese | 0:1ebe7d222470 | 10 | // |
Damotclese | 0:1ebe7d222470 | 11 | // This thread will set an analog output signal to contain a porch |
Damotclese | 0:1ebe7d222470 | 12 | // and then a ramp which increments from an initial step value up |
Damotclese | 0:1ebe7d222470 | 13 | // to 3.3 volts, with the step being at 0.0 volts. |
Damotclese | 0:1ebe7d222470 | 14 | // |
Damotclese | 0:1ebe7d222470 | 15 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 16 | |
Damotclese | 0:1ebe7d222470 | 17 | #include "mbed.h" // The mbed operating system |
Damotclese | 0:1ebe7d222470 | 18 | #include "LCD_DISCO_F429ZI.h" // For controlling the LCD |
Damotclese | 0:1ebe7d222470 | 19 | #include "TS_DISCO_F429ZI.h" // For controlling the touch screen |
Damotclese | 0:1ebe7d222470 | 20 | #include "LaserMon-Main.h" // For data exported to us |
Damotclese | 0:1ebe7d222470 | 21 | |
Damotclese | 0:1ebe7d222470 | 22 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 23 | // We describe the shape of the waveform |
Damotclese | 0:1ebe7d222470 | 24 | // |
Damotclese | 0:1ebe7d222470 | 25 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 26 | |
Damotclese | 1:b9d4b9b8884c | 27 | #define PORCH_WIDTH 10 // In milliseconds |
Damotclese | 1:b9d4b9b8884c | 28 | #define RAMP_WIDTH 250 // In milliseconds |
Damotclese | 0:1ebe7d222470 | 29 | #define SCAN_LENGTH (PORCH_WIDTH + RAMP_WIDTH) // In milliseconds |
Damotclese | 1:b9d4b9b8884c | 30 | #define STEP_HEIGHT 1.8f // In volts |
Damotclese | 0:1ebe7d222470 | 31 | |
Damotclese | 0:1ebe7d222470 | 32 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 33 | // Local data storage |
Damotclese | 0:1ebe7d222470 | 34 | // |
Damotclese | 0:1ebe7d222470 | 35 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 36 | |
Damotclese | 0:1ebe7d222470 | 37 | // We create an analog output |
Damotclese | 0:1ebe7d222470 | 38 | static AnalogOut st_testSignalOut(TEST_SIGNAL_OUT); |
Damotclese | 1:b9d4b9b8884c | 39 | |
Damotclese | 0:1ebe7d222470 | 40 | // For diagnostic purposes to show that the test output is working |
Damotclese | 0:1ebe7d222470 | 41 | static DigitalOut st_testSignalLED(LED1); |
Damotclese | 0:1ebe7d222470 | 42 | |
Damotclese | 0:1ebe7d222470 | 43 | // To drive the porch |
Damotclese | 0:1ebe7d222470 | 44 | static bool b_onPorch; |
Damotclese | 0:1ebe7d222470 | 45 | static uint16_t u16_countRemaining; |
Damotclese | 0:1ebe7d222470 | 46 | |
Damotclese | 0:1ebe7d222470 | 47 | // Across the ramp we increment the voltage starting from the |
Damotclese | 0:1ebe7d222470 | 48 | // initial step up to 3.3 volts. Here we compute what the |
Damotclese | 0:1ebe7d222470 | 49 | // incremental voltage should be so that when the ramp has |
Damotclese | 0:1ebe7d222470 | 50 | // been completed, we end up at 3.3 volts, starting from the |
Damotclese | 0:1ebe7d222470 | 51 | // initial step. |
Damotclese | 1:b9d4b9b8884c | 52 | static const float f_stepIncrement = ((3.3f - STEP_HEIGHT) / ((float)RAMP_WIDTH - 10.0f)); |
Damotclese | 0:1ebe7d222470 | 53 | |
Damotclese | 0:1ebe7d222470 | 54 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 55 | // Data that we will export globally |
Damotclese | 0:1ebe7d222470 | 56 | // |
Damotclese | 0:1ebe7d222470 | 57 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 58 | |
Damotclese | 0:1ebe7d222470 | 59 | // This is the value we maintain for ramp, adding to it the |
Damotclese | 0:1ebe7d222470 | 60 | // incremental value every millisecond. We make it global so |
Damotclese | 0:1ebe7d222470 | 61 | // that we can use the value for software development |
Damotclese | 0:1ebe7d222470 | 62 | float f_rampVoltage = 0.0f; |
Damotclese | 0:1ebe7d222470 | 63 | |
Damotclese | 0:1ebe7d222470 | 64 | // ---------------------------------------------------------------------- |
Damotclese | 1:b9d4b9b8884c | 65 | // TestOutputThread() |
Damotclese | 0:1ebe7d222470 | 66 | // |
Damotclese | 0:1ebe7d222470 | 67 | // ---------------------------------------------------------------------- |
Damotclese | 1:b9d4b9b8884c | 68 | void TestOutputThread(void) |
Damotclese | 0:1ebe7d222470 | 69 | { |
Damotclese | 0:1ebe7d222470 | 70 | static uint8_t u8_ledTimeoutTimer = 0; |
Damotclese | 0:1ebe7d222470 | 71 | |
Damotclese | 0:1ebe7d222470 | 72 | // Do we need to turn the scan-completed LED off? |
Damotclese | 0:1ebe7d222470 | 73 | if (u8_ledTimeoutTimer > 0) |
Damotclese | 0:1ebe7d222470 | 74 | { |
Damotclese | 0:1ebe7d222470 | 75 | // Count down the timer and see if it expired |
Damotclese | 0:1ebe7d222470 | 76 | if (0 == --u8_ledTimeoutTimer) |
Damotclese | 0:1ebe7d222470 | 77 | { |
Damotclese | 0:1ebe7d222470 | 78 | // Turn the LED off now that 10 milliseconds has expired |
Damotclese | 0:1ebe7d222470 | 79 | st_testSignalLED = 0; |
Damotclese | 0:1ebe7d222470 | 80 | } |
Damotclese | 0:1ebe7d222470 | 81 | } |
Damotclese | 0:1ebe7d222470 | 82 | |
Damotclese | 0:1ebe7d222470 | 83 | // Are we stepping out the porch? |
Damotclese | 0:1ebe7d222470 | 84 | if (true == b_onPorch) |
Damotclese | 0:1ebe7d222470 | 85 | { |
Damotclese | 1:b9d4b9b8884c | 86 | // Drive the voltage down to zero for porch |
Damotclese | 1:b9d4b9b8884c | 87 | st_testSignalOut.write(f_rampVoltage = 0.0f); |
Damotclese | 1:b9d4b9b8884c | 88 | |
Damotclese | 0:1ebe7d222470 | 89 | // Is the porch time remaining still have some time? |
Damotclese | 0:1ebe7d222470 | 90 | if (u16_countRemaining > 0) |
Damotclese | 0:1ebe7d222470 | 91 | { |
Damotclese | 0:1ebe7d222470 | 92 | // Yes, so count it down 1 millisecond and see if it expired |
Damotclese | 0:1ebe7d222470 | 93 | if (0 == --u16_countRemaining) |
Damotclese | 0:1ebe7d222470 | 94 | { |
Damotclese | 0:1ebe7d222470 | 95 | // The porch time has expired so now we're on ramp |
Damotclese | 0:1ebe7d222470 | 96 | b_onPorch = false; |
Damotclese | 0:1ebe7d222470 | 97 | |
Damotclese | 0:1ebe7d222470 | 98 | // Set the ramp duration |
Damotclese | 0:1ebe7d222470 | 99 | u16_countRemaining = RAMP_WIDTH; |
Damotclese | 0:1ebe7d222470 | 100 | |
Damotclese | 1:b9d4b9b8884c | 101 | // Set the next output voltage to the step height |
Damotclese | 1:b9d4b9b8884c | 102 | f_rampVoltage = (STEP_HEIGHT - f_stepIncrement); |
Damotclese | 0:1ebe7d222470 | 103 | } |
Damotclese | 0:1ebe7d222470 | 104 | } |
Damotclese | 0:1ebe7d222470 | 105 | } |
Damotclese | 0:1ebe7d222470 | 106 | else |
Damotclese | 0:1ebe7d222470 | 107 | { |
Damotclese | 0:1ebe7d222470 | 108 | // We are stepping out the ramp. We go from the step height |
Damotclese | 0:1ebe7d222470 | 109 | // all the way up to 3.3 volts, incrementally across the |
Damotclese | 0:1ebe7d222470 | 110 | // entire length of the ramp. |
Damotclese | 0:1ebe7d222470 | 111 | // |
Damotclese | 0:1ebe7d222470 | 112 | // Add the incremental value to the ramp voltage going out |
Damotclese | 0:1ebe7d222470 | 113 | f_rampVoltage += f_stepIncrement; |
Damotclese | 0:1ebe7d222470 | 114 | |
Damotclese | 0:1ebe7d222470 | 115 | // Write that voltage out |
Damotclese | 0:1ebe7d222470 | 116 | st_testSignalOut.write(f_rampVoltage / 3.3f); |
Damotclese | 0:1ebe7d222470 | 117 | |
Damotclese | 0:1ebe7d222470 | 118 | // Is there any more ramp to go out? |
Damotclese | 0:1ebe7d222470 | 119 | if (u16_countRemaining > 0) |
Damotclese | 0:1ebe7d222470 | 120 | { |
Damotclese | 0:1ebe7d222470 | 121 | // There is so count it down |
Damotclese | 0:1ebe7d222470 | 122 | u16_countRemaining--; |
Damotclese | 0:1ebe7d222470 | 123 | } |
Damotclese | 0:1ebe7d222470 | 124 | |
Damotclese | 0:1ebe7d222470 | 125 | // Is there no more ramp left to step out? |
Damotclese | 0:1ebe7d222470 | 126 | if (0 == u16_countRemaining) |
Damotclese | 0:1ebe7d222470 | 127 | { |
Damotclese | 0:1ebe7d222470 | 128 | // No more ramp so we're back to porch |
Damotclese | 0:1ebe7d222470 | 129 | b_onPorch = true; |
Damotclese | 0:1ebe7d222470 | 130 | |
Damotclese | 0:1ebe7d222470 | 131 | // 1 millisecond from now we start counting down porch again |
Damotclese | 0:1ebe7d222470 | 132 | u16_countRemaining = PORCH_WIDTH; |
Damotclese | 0:1ebe7d222470 | 133 | |
Damotclese | 0:1ebe7d222470 | 134 | // At the completion of a scan we drive the LED |
Damotclese | 0:1ebe7d222470 | 135 | st_testSignalLED = 1; |
Damotclese | 0:1ebe7d222470 | 136 | |
Damotclese | 0:1ebe7d222470 | 137 | // We flash the LED for 10 milliseconds |
Damotclese | 0:1ebe7d222470 | 138 | u8_ledTimeoutTimer = 10; |
Damotclese | 0:1ebe7d222470 | 139 | } |
Damotclese | 0:1ebe7d222470 | 140 | } |
Damotclese | 0:1ebe7d222470 | 141 | } |
Damotclese | 0:1ebe7d222470 | 142 | |
Damotclese | 0:1ebe7d222470 | 143 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 144 | // TestOutputInit() |
Damotclese | 0:1ebe7d222470 | 145 | // |
Damotclese | 0:1ebe7d222470 | 146 | // This function initializes this module and then launches the thread |
Damotclese | 0:1ebe7d222470 | 147 | // |
Damotclese | 0:1ebe7d222470 | 148 | // ---------------------------------------------------------------------- |
Damotclese | 0:1ebe7d222470 | 149 | void TestOutputInit(void) |
Damotclese | 0:1ebe7d222470 | 150 | { |
Damotclese | 0:1ebe7d222470 | 151 | // Initialize this module |
Damotclese | 0:1ebe7d222470 | 152 | b_onPorch = true; |
Damotclese | 0:1ebe7d222470 | 153 | u16_countRemaining = PORCH_WIDTH; |
Damotclese | 0:1ebe7d222470 | 154 | } |
Damotclese | 0:1ebe7d222470 | 155 | |
Damotclese | 0:1ebe7d222470 | 156 | // End of file |
Damotclese | 0:1ebe7d222470 | 157 |