Embedded Software Assignment 1

Dependencies:   MCP23017 WattBob_TextLCD mbed

Fork of ES_Assignment_1_Pub by M L

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 /***********************************************************************************************************************************************
00003 *                                                                                                                                              *
00004 *                                              Waveform Generator ( Embedded Software Assignment 1 )                                           *
00005 * @author Markus                                                                                                                               *
00006 * @version 1.0                                                                                                                                 *
00007 * @lastupdate 27.01.2016                                                                                                                       *
00008 *                                                                                                                                              *
00009 * This program generates a waveform, and a synchronise pulse for an trigger, similar to the following example:                                 *
00010 *                                                                                                                                              *
00011 *                                           in one period or block,                   the end of a block constis of a default wait(b),         *
00012 *                                   the signal a and wait b is exectued 20 times            and an additional waiting time (d)                 *
00013 *                          _______         _________         _________         ________                                     _______            *
00014 *                         |       |       |         |       |         |       |        |       |                     |     |       |           *
00015 *    SIGNAL A             | <---> | <---> | <-----> | <---> | <-----> | <---> |  <-->  | <---> |         <--->       |     | <---> |           *
00016 *     (wave)              |   a   |   b   |  a+i*50 |   b   |  a+i*50 | b...  |  a...  |   b   |           d         |     |   a   | .....     *
00017 *                  _______|       |_______|         |_______|         |_______|        |_______|_____________________|_____|       |__________ *
00018 *                         |                              --> repeated in sum 20 times                                |                         *
00019 *                         |                                                            |_____________________________|________________________ *
00020 *                         |                                                                      end pause           | begin of the next block *
00021 *                    _____|                                                                                          |_____                    *
00022 *     SIGNAL B      |     |      <--------------------------------------------->       |                             |     |                   *
00023 *     (trigger)     | <-> |                            c                               |                             | <-> |                   *
00024 *                  _|  z  |____________________________________________________________|_____________________________|  z  |__________________ *
00025 *                                                                                                                                              *
00026 *                                                                                                                                              *
00027 *                                                                                                                                              *
00028 *                                                                                                                                              *
00029 ***********************************************************************************************************************************************/
00030 
00031 
00032 /*
00033 ========================================================================================
00034 =                                                                                      =
00035 =                       INCLUDES and DIGITAL PORT DECLARATION                          =
00036 =                                                                                      =
00037 ========================================================================================
00038 */
00039 
00040 #include "mbed.h"                                    // Include the default mbed header file
00041 
00042 DigitalOut sig_a(p18);                               // Digital Output for the Wave Signal
00043 DigitalOut sig_b(p17);                               // Digital Output for the Trigger pulse
00044 DigitalIn sw_onoff(p21);                             // Digital Input for the ON / OFF Switch
00045 DigitalIn sw_inv(p22);                               // Digital Input for the Inverted Switch
00046 
00047 /*
00048 ========================================================================================
00049 =                                                                                      =
00050 =                       MAIN PROCEDURE - generating the Blocks                         =
00051 =                                                                                      =
00052 ========================================================================================
00053 */
00054 
00055 int main()
00056 {
00057     int var_z = 10;                                  // Signal B - Trigger Pulse in us
00058     int var_c = 7   +   13;                          // Letter M / number of pulses in one block
00059     int var_d = 500 *   16;                          // Letter P / number of space between the blocks
00060     int multiplier = 50;                             // is added to each pulse lenth after every pulse
00061 
00062     while(1) {                                       // repeat the signal procedure forever
00063 
00064         if(sw_onoff) {                               // if the ON/OFF Switch is ON, proceede, else do nothing
00065 
00066             sig_b = 1;                               // Send the Trigger pulse (set port B high)
00067             wait_us(var_z);                          // wait for var_z us
00068             sig_b = 0;                               // Stop the Signal B (set port B low)
00069 
00070             int var_a = 100 *   12;                  // Letter L / the pulse length in us;
00071             int var_b = 100 *   1;                   // Letter A / wait us between the pulses
00072 
00073 
00074             if(sw_inv) {                             // if the Inverted Switch is ON, proceede, else jump over this
00075                                                      // this inverts the values of var_a and var_b
00076                 int temp = var_a;                    // save var_a to a temporary variable
00077                 var_a = var_b;                       // replace var_a with var_b
00078                 var_b = temp;                        // replace var_b with temp (value of var_a)
00079             }
00080 
00081                                                       // This for loop generates the BLOCKS
00082             for (int i=0; i<var_c; i++) {             // run this loop var_c times
00083                 sig_a = 1;                            // Start the Signal A (set port A to high)
00084                 wait_us(var_a + i * multiplier);      // wait for var_a + i * multiplier us
00085                 sig_a = 0;                            // Stop the Signal A (set port A to low)
00086                 wait_us(var_b);                       // wait for var_b us (wait between the pulses)
00087             }
00088             
00089             wait_us(var_d);                           // wait vor var_d us (final wait)
00090         }
00091     }
00092 }