Fredric Rice / Mbed 2 deprecated NextGen-LaserMonitor

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI mbed-os BSP_DISCO_F429ZI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LaserMon-TestOutput.cpp Source File

LaserMon-TestOutput.cpp

00001 
00002 // ----------------------------------------------------------------------
00003 // LaserMon-TestOutput.cpp
00004 //
00005 // Fredric L. Rice, June 2019
00006 //
00007 // For testing purposes only, this test output wave form can be
00008 // jumpered in to the laser scan analog input signal so that the
00009 // software can be developed without the need for an ISEM.
00010 //
00011 // This thread will set an analog output signal to contain a porch
00012 // and then a ramp which increments from an initial step value up 
00013 // to 3.3 volts, with the step being at 0.0 volts.
00014 //
00015 // ----------------------------------------------------------------------
00016 
00017 #include "mbed.h"                   // The mbed operating system
00018 #include "LCD_DISCO_F429ZI.h"       // For controlling the LCD
00019 #include "TS_DISCO_F429ZI.h"        // For controlling the touch screen
00020 #include "LaserMon-Main.h"          // For data exported to us
00021 
00022 // ----------------------------------------------------------------------
00023 // We describe the shape of the waveform
00024 //
00025 // ----------------------------------------------------------------------
00026 
00027 #define PORCH_WIDTH     10                          // In milliseconds
00028 #define RAMP_WIDTH      250                         // In milliseconds
00029 #define SCAN_LENGTH     (PORCH_WIDTH + RAMP_WIDTH)  // In milliseconds
00030 #define STEP_HEIGHT     1.8f                        // In volts
00031 
00032 // ----------------------------------------------------------------------
00033 // Local data storage
00034 //
00035 // ----------------------------------------------------------------------
00036 
00037     // We create an analog output
00038     static AnalogOut st_testSignalOut(TEST_SIGNAL_OUT);
00039     
00040     // For diagnostic purposes to show that the test output is working
00041     static DigitalOut st_testSignalLED(LED1);
00042     
00043     // To drive the porch
00044     static bool     b_onPorch;
00045     static uint16_t u16_countRemaining;
00046     
00047     // Across the ramp we increment the voltage starting from the
00048     // initial step up to 3.3 volts. Here we compute what the
00049     // incremental voltage should be so that when the ramp has
00050     // been completed, we end up at 3.3 volts, starting from the
00051     // initial step.
00052     static const float f_stepIncrement = ((3.3f - STEP_HEIGHT) / ((float)RAMP_WIDTH - 10.0f));
00053     
00054 // ----------------------------------------------------------------------
00055 // Data that we will export globally
00056 //
00057 // ----------------------------------------------------------------------
00058 
00059     // This is the value we maintain for ramp, adding to it the
00060     // incremental value every millisecond. We make it global so
00061     // that we can use the value for software development
00062     float f_rampVoltage = 0.0f;
00063     
00064 // ----------------------------------------------------------------------
00065 // TestOutputThread()
00066 //
00067 // This is called once a millisecond however it is not a thread, the
00068 // thread class on this board ended up with timing that could not be
00069 // controlled so the main() loop calls us once a millisecond.
00070 //
00071 // ----------------------------------------------------------------------
00072 void TestOutputThread(void)
00073 {
00074     static uint8_t u8_ledTimeoutTimer = 0;
00075 
00076     // Do we need to turn the scan-completed LED off?
00077     if (u8_ledTimeoutTimer > 0)
00078     {
00079         // Count down the timer and see if it expired
00080         if (0 == --u8_ledTimeoutTimer)
00081         {
00082             // Turn the LED off now that 10 milliseconds has expired
00083             st_testSignalLED = 0;
00084         }
00085     }
00086 
00087     // Are we stepping out the porch?
00088     if (true == b_onPorch)
00089     {
00090         // Drive the voltage down to zero for porch
00091         st_testSignalOut.write(f_rampVoltage = 0.0f);
00092 
00093         // Is the porch time remaining still have some time?
00094         if (u16_countRemaining > 0)
00095         {
00096             // Yes, so count it down 1 millisecond and see if it expired
00097             if (0 == --u16_countRemaining)
00098             {
00099                 // The porch time has expired so now we're on ramp
00100                 b_onPorch = false;
00101                 
00102                 // Set the ramp duration
00103                 u16_countRemaining = RAMP_WIDTH;
00104                 
00105                 // Set the next output voltage to the step height
00106                 f_rampVoltage = (STEP_HEIGHT - f_stepIncrement);
00107             }
00108         }
00109     }
00110     else
00111     {
00112         // We are stepping out the ramp. We go from the step height
00113         // all the way up to 3.3 volts, incrementally across the
00114         // entire length of the ramp.
00115         //
00116         // Add the incremental value to the ramp voltage going out
00117         f_rampVoltage += f_stepIncrement;
00118         
00119         // Write that voltage out
00120         st_testSignalOut.write(f_rampVoltage / 3.3f);
00121 
00122         // Is there any more ramp to go out?
00123         if (u16_countRemaining > 0)
00124         {
00125             // There is so count it down
00126             u16_countRemaining--;
00127         }
00128         
00129         // Is there no more ramp left to step out?
00130         if (0 == u16_countRemaining)
00131         {
00132             // No more ramp so we're back to porch
00133             b_onPorch = true;
00134             
00135             // 1 millisecond from now we start counting down porch again
00136             u16_countRemaining = PORCH_WIDTH;
00137             
00138             // At the completion of a scan we drive the LED
00139             st_testSignalLED = 1;
00140             
00141             // We flash the LED for 10 milliseconds
00142             u8_ledTimeoutTimer = 10;
00143         }
00144     }
00145 }
00146 
00147 // ----------------------------------------------------------------------
00148 // TestOutputInit()
00149 //
00150 // This function initializes this module's locally-held data
00151 //
00152 // ----------------------------------------------------------------------
00153 void TestOutputInit(void)
00154 {
00155     // Initialize this module
00156     b_onPorch          = true;
00157     u16_countRemaining = PORCH_WIDTH;
00158 }
00159 
00160 // End of file
00161