Embedded Software Assignment 1

Dependencies:   MCP23017 WattBob_TextLCD mbed

Fork of ES_Assignment_1_Pub by M L

Committer:
usmb192
Date:
Mon Feb 22 17:29:30 2016 +0000
Revision:
0:d16c044806a6
Child:
1:abf92edc970f
Embedded Systems Assignment 1 Final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
usmb192 0:d16c044806a6 1
usmb192 0:d16c044806a6 2 /***********************************************************************************************************************************************
usmb192 0:d16c044806a6 3 * *
usmb192 0:d16c044806a6 4 * Waveform Generator ( Embedded Software Assignment 1 ) *
usmb192 0:d16c044806a6 5 * @author *
usmb192 0:d16c044806a6 6 * @version 1.0 *
usmb192 0:d16c044806a6 7 * @lastupdate 27.01.2016 *
usmb192 0:d16c044806a6 8 * *
usmb192 0:d16c044806a6 9 * This program generates a waveform, and a synchronise pulse for an trigger, similar to the following example: *
usmb192 0:d16c044806a6 10 * *
usmb192 0:d16c044806a6 11 * in one period or block, the end of a block constis of a default wait(b), *
usmb192 0:d16c044806a6 12 * the signal a and wait b is exectued 20 times and an additional waiting time (d) *
usmb192 0:d16c044806a6 13 * _______ _________ _________ ________ _______ *
usmb192 0:d16c044806a6 14 * | | | | | | | | | | | | *
usmb192 0:d16c044806a6 15 * SIGNAL A | <---> | <---> | <-----> | <---> | <-----> | <---> | <--> | <---> | <---> | | <---> | *
usmb192 0:d16c044806a6 16 * (wave) | a | b | a+i*50 | b | a+i*50 | b... | a... | b | d | | a | ..... *
usmb192 0:d16c044806a6 17 * _______| |_______| |_______| |_______| |_______|_____________________|_____| |__________ *
usmb192 0:d16c044806a6 18 * | --> repeated in sum 20 times | *
usmb192 0:d16c044806a6 19 * | |_____________________________|________________________ *
usmb192 0:d16c044806a6 20 * | end pause | begin of the next block *
usmb192 0:d16c044806a6 21 * _____| |_____ *
usmb192 0:d16c044806a6 22 * SIGNAL B | | <---------------------------------------------> | | | *
usmb192 0:d16c044806a6 23 * (trigger) | <-> | c | | <-> | *
usmb192 0:d16c044806a6 24 * _| z |____________________________________________________________|_____________________________| z |__________________ *
usmb192 0:d16c044806a6 25 * *
usmb192 0:d16c044806a6 26 * *
usmb192 0:d16c044806a6 27 * *
usmb192 0:d16c044806a6 28 * *
usmb192 0:d16c044806a6 29 ***********************************************************************************************************************************************/
usmb192 0:d16c044806a6 30
usmb192 0:d16c044806a6 31
usmb192 0:d16c044806a6 32 /*
usmb192 0:d16c044806a6 33 ========================================================================================
usmb192 0:d16c044806a6 34 = =
usmb192 0:d16c044806a6 35 = INCLUDES and DIGITAL PORT DECLARATION =
usmb192 0:d16c044806a6 36 = =
usmb192 0:d16c044806a6 37 ========================================================================================
usmb192 0:d16c044806a6 38 */
usmb192 0:d16c044806a6 39
usmb192 0:d16c044806a6 40 #include "mbed.h" // Include the default mbed header file
usmb192 0:d16c044806a6 41
usmb192 0:d16c044806a6 42 DigitalOut sig_a(p18); // Digital Output for the Wave Signal
usmb192 0:d16c044806a6 43 DigitalOut sig_b(p17); // Digital Output for the Trigger pulse
usmb192 0:d16c044806a6 44 DigitalIn sw_onoff(p21); // Digital Input for the ON / OFF Switch
usmb192 0:d16c044806a6 45 DigitalIn sw_inv(p22); // Digital Input for the Inverted Switch
usmb192 0:d16c044806a6 46
usmb192 0:d16c044806a6 47 /*
usmb192 0:d16c044806a6 48 ========================================================================================
usmb192 0:d16c044806a6 49 = =
usmb192 0:d16c044806a6 50 = MAIN PROCEDURE - generating the Blocks =
usmb192 0:d16c044806a6 51 = =
usmb192 0:d16c044806a6 52 ========================================================================================
usmb192 0:d16c044806a6 53 */
usmb192 0:d16c044806a6 54
usmb192 0:d16c044806a6 55 int main()
usmb192 0:d16c044806a6 56 {
usmb192 0:d16c044806a6 57 int var_z = 10; // Signal B - Trigger Pulse in us
usmb192 0:d16c044806a6 58 int var_c = 7 + 13; // Letter M / number of pulses in one block
usmb192 0:d16c044806a6 59 int var_d = 500 * 16; // Letter P / number of space between the blocks
usmb192 0:d16c044806a6 60 int multiplier = 50; // is added to each pulse lenth after every pulse
usmb192 0:d16c044806a6 61
usmb192 0:d16c044806a6 62 while(1) { // repeat the signal procedure forever
usmb192 0:d16c044806a6 63
usmb192 0:d16c044806a6 64 if(sw_onoff) { // if the ON/OFF Switch is ON, proceede, else do nothing
usmb192 0:d16c044806a6 65
usmb192 0:d16c044806a6 66 sig_b = 1; // Send the Trigger pulse (set port B high)
usmb192 0:d16c044806a6 67 wait_us(var_z); // wait for var_z us
usmb192 0:d16c044806a6 68 sig_b = 0; // Stop the Signal B (set port B low)
usmb192 0:d16c044806a6 69
usmb192 0:d16c044806a6 70 int var_a = 100 * 12; // Letter L / the pulse length in us;
usmb192 0:d16c044806a6 71 int var_b = 100 * 1; // Letter A / wait us between the pulses
usmb192 0:d16c044806a6 72
usmb192 0:d16c044806a6 73
usmb192 0:d16c044806a6 74 if(sw_inv) { // if the Inverted Switch is ON, proceede, else jump over this
usmb192 0:d16c044806a6 75 // this inverts the values of var_a and var_b
usmb192 0:d16c044806a6 76 int temp = var_a; // save var_a to a temporary variable
usmb192 0:d16c044806a6 77 var_a = var_b; // replace var_a with var_b
usmb192 0:d16c044806a6 78 var_b = temp; // replace var_b with temp (value of var_a)
usmb192 0:d16c044806a6 79 }
usmb192 0:d16c044806a6 80
usmb192 0:d16c044806a6 81 // This for loop generates the BLOCKS
usmb192 0:d16c044806a6 82 for (int i=0; i<var_c; i++) { // run this loop var_c times
usmb192 0:d16c044806a6 83 sig_a = 1; // Start the Signal A (set port A to high)
usmb192 0:d16c044806a6 84 wait_us(var_a + i * multiplier); // wait for var_a + i * multiplier us
usmb192 0:d16c044806a6 85 sig_a = 0; // Stop the Signal A (set port A to low)
usmb192 0:d16c044806a6 86 wait_us(var_b); // wait for var_b us (wait between the pulses)
usmb192 0:d16c044806a6 87 }
usmb192 0:d16c044806a6 88
usmb192 0:d16c044806a6 89 wait_us(var_d); // wait vor var_d us (final wait)
usmb192 0:d16c044806a6 90 }
usmb192 0:d16c044806a6 91 }
usmb192 0:d16c044806a6 92 }