Example software for a Cyclic Executive

Dependencies:   MCP23017 SDFileSystem WattBob_TextLCD mbed

Committer:
sk398
Date:
Fri Feb 26 10:36:23 2016 +0000
Revision:
4:b85bc0d810e1
Parent:
3:c611b9bb5770
Child:
5:250f51c80ac1
Display function works, Analog function works, digitalIN function works.; ; Freq measurement still to work.; ; Display to be changed to class structure

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sk398 4:b85bc0d810e1 1 /* #####################################################################
sk398 4:b85bc0d810e1 2 Tasks.cpp
sk398 4:b85bc0d810e1 3 ---------
sk398 4:b85bc0d810e1 4
sk398 4:b85bc0d810e1 5 Embedded Software - Assignment 2
sk398 4:b85bc0d810e1 6 --------------------------------
sk398 4:b85bc0d810e1 7
sk398 4:b85bc0d810e1 8 Written by: Steven Kay
sk398 4:b85bc0d810e1 9
sk398 4:b85bc0d810e1 10 Date: February 2016
sk398 4:b85bc0d810e1 11
sk398 4:b85bc0d810e1 12 Function: This
sk398 4:b85bc0d810e1 13
sk398 4:b85bc0d810e1 14 Version: 1.0
sk398 4:b85bc0d810e1 15
sk398 4:b85bc0d810e1 16 Version History
sk398 4:b85bc0d810e1 17 ---------------
sk398 4:b85bc0d810e1 18
sk398 4:b85bc0d810e1 19 1.1 rgdfgdfgdfggdfgdg
sk398 4:b85bc0d810e1 20
sk398 4:b85bc0d810e1 21 1.0 gdgddfdddgd
sk398 4:b85bc0d810e1 22
sk398 4:b85bc0d810e1 23 ##################################################################### */
sk398 2:22ebabd78084 24
sk398 1:221d677fe0d3 25 #include "mbed.h"
sk398 1:221d677fe0d3 26 #include "Tasks.h"
sk398 4:b85bc0d810e1 27 #include "MCP23017.h"
sk398 4:b85bc0d810e1 28 #include "WattBob_TextLCD.h"
sk398 1:221d677fe0d3 29
sk398 1:221d677fe0d3 30 /* ==================================== Task 1 ==================================== */
sk398 1:221d677fe0d3 31 Task1::Task1(PinName squareWaveInPin)
sk398 1:221d677fe0d3 32 {
sk398 4:b85bc0d810e1 33 _squareWaveIn = new InterruptIn(squareWaveInPin);
sk398 1:221d677fe0d3 34 }
sk398 1:221d677fe0d3 35
sk398 4:b85bc0d810e1 36 void Task1::MeasureFrequency()
sk398 4:b85bc0d810e1 37 {
sk398 4:b85bc0d810e1 38 _Task1Timer.start();
sk398 4:b85bc0d810e1 39 _squareWaveIn -> rise(this,&Task1::StopCounter);
sk398 1:221d677fe0d3 40 }
sk398 1:221d677fe0d3 41
sk398 4:b85bc0d810e1 42 void Task1::StopCounter()
sk398 4:b85bc0d810e1 43 {
sk398 4:b85bc0d810e1 44 _Task1Timer.stop();
sk398 4:b85bc0d810e1 45 measuredFrequency = _Task1Timer.read_us();
sk398 4:b85bc0d810e1 46 _Task1Timer.reset();
sk398 4:b85bc0d810e1 47 }
sk398 4:b85bc0d810e1 48
sk398 4:b85bc0d810e1 49 int Task1::ReadFrequency()
sk398 4:b85bc0d810e1 50 {
sk398 4:b85bc0d810e1 51 _squareWaveIn -> rise(this,&Task1::MeasureFrequency);
sk398 4:b85bc0d810e1 52
sk398 4:b85bc0d810e1 53 return measuredFrequency;
sk398 4:b85bc0d810e1 54 }
sk398 1:221d677fe0d3 55
sk398 1:221d677fe0d3 56 /* ==================================== Task 2 ==================================== */
sk398 1:221d677fe0d3 57 Task2::Task2(PinName digitalInCheckPin)
sk398 1:221d677fe0d3 58 {
sk398 3:c611b9bb5770 59 _digitalInCheck = new DigitalIn(digitalInCheckPin);
sk398 1:221d677fe0d3 60 }
sk398 3:c611b9bb5770 61
sk398 3:c611b9bb5770 62 bool Task2::digitalInState()
sk398 3:c611b9bb5770 63 {
sk398 3:c611b9bb5770 64 if(_digitalInCheck -> read())
sk398 3:c611b9bb5770 65 {
sk398 3:c611b9bb5770 66 return TRUE;
sk398 3:c611b9bb5770 67 }
sk398 3:c611b9bb5770 68 else
sk398 3:c611b9bb5770 69 {
sk398 3:c611b9bb5770 70 return FALSE;
sk398 3:c611b9bb5770 71 }
sk398 3:c611b9bb5770 72 }
sk398 3:c611b9bb5770 73
sk398 1:221d677fe0d3 74
sk398 1:221d677fe0d3 75 /* ==================================== Task 3 ==================================== */
sk398 1:221d677fe0d3 76 Task3::Task3(PinName WatchdogPin)
sk398 1:221d677fe0d3 77 {
sk398 1:221d677fe0d3 78 _Watchdog = new DigitalOut(WatchdogPin);
sk398 1:221d677fe0d3 79 }
sk398 1:221d677fe0d3 80
sk398 1:221d677fe0d3 81 void Task3::OutputWatchdogPulse()
sk398 1:221d677fe0d3 82 {
sk398 1:221d677fe0d3 83 _Watchdog -> write(HIGH);
sk398 1:221d677fe0d3 84 wait_ms(WATCHDOG_PULSE_WIDTH);
sk398 1:221d677fe0d3 85 _Watchdog -> write(LOW);
sk398 1:221d677fe0d3 86 }
sk398 1:221d677fe0d3 87
sk398 1:221d677fe0d3 88
sk398 3:c611b9bb5770 89 /* ==================================== Task 4 ==================================== */
sk398 3:c611b9bb5770 90 Task4::Task4(PinName Analog1Pin,PinName Analog2Pin)
sk398 3:c611b9bb5770 91 {
sk398 3:c611b9bb5770 92 _AnalogIn1 = new AnalogIn(Analog1Pin);
sk398 3:c611b9bb5770 93 _AnalogIn2 = new AnalogIn(Analog2Pin);
sk398 3:c611b9bb5770 94 }
sk398 3:c611b9bb5770 95
sk398 3:c611b9bb5770 96 float *Task4::returnAnalogReadings()
sk398 3:c611b9bb5770 97 {
sk398 3:c611b9bb5770 98 float readBuffer_1 = 0.0;
sk398 3:c611b9bb5770 99 float readBuffer_2 = 0.0;
sk398 3:c611b9bb5770 100
sk398 3:c611b9bb5770 101 float outputBuffer[2];
sk398 3:c611b9bb5770 102
sk398 3:c611b9bb5770 103 // outputBuffer[0] = _AnalogIn1 -> read();
sk398 3:c611b9bb5770 104 // outputBuffer[1] = _AnalogIn2 -> read();
sk398 3:c611b9bb5770 105
sk398 3:c611b9bb5770 106 for(int readCount = 0;readCount < NUM_ANALOG_SAMPLES; readCount++)
sk398 3:c611b9bb5770 107 {
sk398 4:b85bc0d810e1 108 readBuffer_1 += ((_AnalogIn1 -> read())*3.3);
sk398 4:b85bc0d810e1 109 // printf("Buffer 1 %f\r\n",readBuffer_1);
sk398 4:b85bc0d810e1 110 readBuffer_2 += ((_AnalogIn2 -> read())*3.3);
sk398 4:b85bc0d810e1 111 // printf("Buffer 2 %f\r\n",readBuffer_2);
sk398 3:c611b9bb5770 112 }
sk398 3:c611b9bb5770 113
sk398 3:c611b9bb5770 114 outputBuffer[0] = readBuffer_1/NUM_ANALOG_SAMPLES;
sk398 4:b85bc0d810e1 115 // printf("outputBuffer[0] %f\r\n",outputBuffer[0]);
sk398 4:b85bc0d810e1 116 outputBuffer[1] = readBuffer_2/NUM_ANALOG_SAMPLES;
sk398 4:b85bc0d810e1 117 // printf("outputBuffer[1] %f\r\n",outputBuffer[1]);
sk398 3:c611b9bb5770 118
sk398 4:b85bc0d810e1 119 float *outputBufferPtr =&outputBuffer[0];
sk398 4:b85bc0d810e1 120
sk398 3:c611b9bb5770 121 return outputBufferPtr;
sk398 3:c611b9bb5770 122 }
sk398 4:b85bc0d810e1 123
sk398 4:b85bc0d810e1 124 /* ==================================== Task 5 ==================================== */
sk398 4:b85bc0d810e1 125 Task5::Task5()
sk398 4:b85bc0d810e1 126 {
sk398 4:b85bc0d810e1 127
sk398 4:b85bc0d810e1 128
sk398 4:b85bc0d810e1 129 }
sk398 4:b85bc0d810e1 130