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 10 17:10:01 2019 +0000
Revision:
0:1ebe7d222470
Child:
1:b9d4b9b8884c
Checking in the project for safe keeping;

Who changed what in which revision?

UserRevisionLine numberNew 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 0:1ebe7d222470 27 #define PORCH_WIDTH 40 // In milliseconds
Damotclese 0:1ebe7d222470 28 #define RAMP_WIDTH 216 // In milliseconds
Damotclese 0:1ebe7d222470 29 #define SCAN_LENGTH (PORCH_WIDTH + RAMP_WIDTH) // In milliseconds
Damotclese 0:1ebe7d222470 30 #define STEP_HEIGHT 2.5f // 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 0:1ebe7d222470 39
Damotclese 0:1ebe7d222470 40 // We will be creating a thread
Damotclese 0:1ebe7d222470 41 static Thread st_testSignalOutThread;
Damotclese 0:1ebe7d222470 42
Damotclese 0:1ebe7d222470 43 // For diagnostic purposes to show that the test output is working
Damotclese 0:1ebe7d222470 44 static DigitalOut st_testSignalLED(LED1);
Damotclese 0:1ebe7d222470 45
Damotclese 0:1ebe7d222470 46 // To drive the porch
Damotclese 0:1ebe7d222470 47 static bool b_onPorch;
Damotclese 0:1ebe7d222470 48 static uint16_t u16_countRemaining;
Damotclese 0:1ebe7d222470 49
Damotclese 0:1ebe7d222470 50 // Across the ramp we increment the voltage starting from the
Damotclese 0:1ebe7d222470 51 // initial step up to 3.3 volts. Here we compute what the
Damotclese 0:1ebe7d222470 52 // incremental voltage should be so that when the ramp has
Damotclese 0:1ebe7d222470 53 // been completed, we end up at 3.3 volts, starting from the
Damotclese 0:1ebe7d222470 54 // initial step.
Damotclese 0:1ebe7d222470 55 static const float f_stepIncrement = ((3.3f - STEP_HEIGHT) / (float)RAMP_WIDTH);
Damotclese 0:1ebe7d222470 56
Damotclese 0:1ebe7d222470 57 // ----------------------------------------------------------------------
Damotclese 0:1ebe7d222470 58 // Data that we will export globally
Damotclese 0:1ebe7d222470 59 //
Damotclese 0:1ebe7d222470 60 // ----------------------------------------------------------------------
Damotclese 0:1ebe7d222470 61
Damotclese 0:1ebe7d222470 62 // This is the value we maintain for ramp, adding to it the
Damotclese 0:1ebe7d222470 63 // incremental value every millisecond. We make it global so
Damotclese 0:1ebe7d222470 64 // that we can use the value for software development
Damotclese 0:1ebe7d222470 65 float f_rampVoltage = 0.0f;
Damotclese 0:1ebe7d222470 66
Damotclese 0:1ebe7d222470 67 // ----------------------------------------------------------------------
Damotclese 0:1ebe7d222470 68 // TestOutputDriveWaveformAT1Millisecond()
Damotclese 0:1ebe7d222470 69 //
Damotclese 0:1ebe7d222470 70 // ----------------------------------------------------------------------
Damotclese 0:1ebe7d222470 71 static void TestOutputDriveWaveformAT1Millisecond(void)
Damotclese 0:1ebe7d222470 72 {
Damotclese 0:1ebe7d222470 73 static uint8_t u8_ledTimeoutTimer = 0;
Damotclese 0:1ebe7d222470 74
Damotclese 0:1ebe7d222470 75 // Do we need to turn the scan-completed LED off?
Damotclese 0:1ebe7d222470 76 if (u8_ledTimeoutTimer > 0)
Damotclese 0:1ebe7d222470 77 {
Damotclese 0:1ebe7d222470 78 // Count down the timer and see if it expired
Damotclese 0:1ebe7d222470 79 if (0 == --u8_ledTimeoutTimer)
Damotclese 0:1ebe7d222470 80 {
Damotclese 0:1ebe7d222470 81 // Turn the LED off now that 10 milliseconds has expired
Damotclese 0:1ebe7d222470 82 st_testSignalLED = 0;
Damotclese 0:1ebe7d222470 83 }
Damotclese 0:1ebe7d222470 84 }
Damotclese 0:1ebe7d222470 85
Damotclese 0:1ebe7d222470 86 // Are we stepping out the porch?
Damotclese 0:1ebe7d222470 87 if (true == b_onPorch)
Damotclese 0:1ebe7d222470 88 {
Damotclese 0:1ebe7d222470 89 // Yes, are we just now starting on the porch?
Damotclese 0:1ebe7d222470 90 if (PORCH_WIDTH == u16_countRemaining)
Damotclese 0:1ebe7d222470 91 {
Damotclese 0:1ebe7d222470 92 // Yes, so drive the voltage down to zero for porch
Damotclese 0:1ebe7d222470 93 st_testSignalOut.write(0.0);
Damotclese 0:1ebe7d222470 94 }
Damotclese 0:1ebe7d222470 95
Damotclese 0:1ebe7d222470 96 // Is the porch time remaining still have some time?
Damotclese 0:1ebe7d222470 97 if (u16_countRemaining > 0)
Damotclese 0:1ebe7d222470 98 {
Damotclese 0:1ebe7d222470 99 // Yes, so count it down 1 millisecond and see if it expired
Damotclese 0:1ebe7d222470 100 if (0 == --u16_countRemaining)
Damotclese 0:1ebe7d222470 101 {
Damotclese 0:1ebe7d222470 102 // The porch time has expired so now we're on ramp
Damotclese 0:1ebe7d222470 103 b_onPorch = false;
Damotclese 0:1ebe7d222470 104
Damotclese 0:1ebe7d222470 105 // Set the ramp duration
Damotclese 0:1ebe7d222470 106 u16_countRemaining = RAMP_WIDTH;
Damotclese 0:1ebe7d222470 107
Damotclese 0:1ebe7d222470 108 // Set the output voltage to the step height
Damotclese 0:1ebe7d222470 109 f_rampVoltage = STEP_HEIGHT;
Damotclese 0:1ebe7d222470 110
Damotclese 0:1ebe7d222470 111 // Set the initial step height
Damotclese 0:1ebe7d222470 112 st_testSignalOut.write(f_rampVoltage / 3.3f);
Damotclese 0:1ebe7d222470 113 }
Damotclese 0:1ebe7d222470 114 }
Damotclese 0:1ebe7d222470 115 }
Damotclese 0:1ebe7d222470 116 else
Damotclese 0:1ebe7d222470 117 {
Damotclese 0:1ebe7d222470 118 // We are stepping out the ramp. We go from the step height
Damotclese 0:1ebe7d222470 119 // all the way up to 3.3 volts, incrementally across the
Damotclese 0:1ebe7d222470 120 // entire length of the ramp.
Damotclese 0:1ebe7d222470 121 //
Damotclese 0:1ebe7d222470 122 // Add the incremental value to the ramp voltage going out
Damotclese 0:1ebe7d222470 123 f_rampVoltage += f_stepIncrement;
Damotclese 0:1ebe7d222470 124
Damotclese 0:1ebe7d222470 125 // Write that voltage out
Damotclese 0:1ebe7d222470 126 st_testSignalOut.write(f_rampVoltage / 3.3f);
Damotclese 0:1ebe7d222470 127
Damotclese 0:1ebe7d222470 128 // Is there any more ramp to go out?
Damotclese 0:1ebe7d222470 129 if (u16_countRemaining > 0)
Damotclese 0:1ebe7d222470 130 {
Damotclese 0:1ebe7d222470 131 // There is so count it down
Damotclese 0:1ebe7d222470 132 u16_countRemaining--;
Damotclese 0:1ebe7d222470 133 }
Damotclese 0:1ebe7d222470 134
Damotclese 0:1ebe7d222470 135 // Is there no more ramp left to step out?
Damotclese 0:1ebe7d222470 136 if (0 == u16_countRemaining)
Damotclese 0:1ebe7d222470 137 {
Damotclese 0:1ebe7d222470 138 // No more ramp so we're back to porch
Damotclese 0:1ebe7d222470 139 b_onPorch = true;
Damotclese 0:1ebe7d222470 140
Damotclese 0:1ebe7d222470 141 // 1 millisecond from now we start counting down porch again
Damotclese 0:1ebe7d222470 142 u16_countRemaining = PORCH_WIDTH;
Damotclese 0:1ebe7d222470 143
Damotclese 0:1ebe7d222470 144 // At the completion of a scan we drive the LED
Damotclese 0:1ebe7d222470 145 st_testSignalLED = 1;
Damotclese 0:1ebe7d222470 146
Damotclese 0:1ebe7d222470 147 // We flash the LED for 10 milliseconds
Damotclese 0:1ebe7d222470 148 u8_ledTimeoutTimer = 10;
Damotclese 0:1ebe7d222470 149 }
Damotclese 0:1ebe7d222470 150 }
Damotclese 0:1ebe7d222470 151 }
Damotclese 0:1ebe7d222470 152
Damotclese 0:1ebe7d222470 153 // ----------------------------------------------------------------------
Damotclese 0:1ebe7d222470 154 // TestOutputThread()
Damotclese 0:1ebe7d222470 155 //
Damotclese 0:1ebe7d222470 156 // This thread sleeps for 1 millisecond and then calls the function
Damotclese 0:1ebe7d222470 157 // that sends the wavefor out the analog output pin.
Damotclese 0:1ebe7d222470 158 //
Damotclese 0:1ebe7d222470 159 // ----------------------------------------------------------------------
Damotclese 0:1ebe7d222470 160 static void TestOutputThread(void)
Damotclese 0:1ebe7d222470 161 {
Damotclese 0:1ebe7d222470 162
Damotclese 0:1ebe7d222470 163 while(true)
Damotclese 0:1ebe7d222470 164 {
Damotclese 0:1ebe7d222470 165 // Wait for 1 millisecond
Damotclese 0:1ebe7d222470 166 accurate_wait_ms(1);
Damotclese 0:1ebe7d222470 167
Damotclese 0:1ebe7d222470 168 // Call the routine which drives the wave form output
Damotclese 0:1ebe7d222470 169 // one millisecond at a time.
Damotclese 0:1ebe7d222470 170 TestOutputDriveWaveformAT1Millisecond();
Damotclese 0:1ebe7d222470 171 }
Damotclese 0:1ebe7d222470 172 }
Damotclese 0:1ebe7d222470 173
Damotclese 0:1ebe7d222470 174 // ----------------------------------------------------------------------
Damotclese 0:1ebe7d222470 175 // TestOutputInit()
Damotclese 0:1ebe7d222470 176 //
Damotclese 0:1ebe7d222470 177 // This function initializes this module and then launches the thread
Damotclese 0:1ebe7d222470 178 //
Damotclese 0:1ebe7d222470 179 // ----------------------------------------------------------------------
Damotclese 0:1ebe7d222470 180 void TestOutputInit(void)
Damotclese 0:1ebe7d222470 181 {
Damotclese 0:1ebe7d222470 182 // Initialize this module
Damotclese 0:1ebe7d222470 183 b_onPorch = true;
Damotclese 0:1ebe7d222470 184 u16_countRemaining = PORCH_WIDTH;
Damotclese 0:1ebe7d222470 185
Damotclese 0:1ebe7d222470 186 // Start the test output thread
Damotclese 0:1ebe7d222470 187 st_testSignalOutThread.start(TestOutputThread);
Damotclese 0:1ebe7d222470 188 }
Damotclese 0:1ebe7d222470 189
Damotclese 0:1ebe7d222470 190 // End of file
Damotclese 0:1ebe7d222470 191