Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MCP23017 SDFileSystem WattBob_TextLCD mbed
Revision 4:b85bc0d810e1, committed 2016-02-26
- Comitter:
- sk398
- Date:
- Fri Feb 26 10:36:23 2016 +0000
- Parent:
- 3:c611b9bb5770
- Child:
- 5:250f51c80ac1
- Commit message:
- Display function works, Analog function works, digitalIN function works.; ; Freq measurement still to work.; ; Display to be changed to class structure
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MCP23017.lib Fri Feb 26 10:36:23 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/jimherd/code/MCP23017/#d57de266cf19
--- a/Tasks.cpp Wed Feb 17 10:22:50 2016 +0000
+++ b/Tasks.cpp Fri Feb 26 10:36:23 2016 +0000
@@ -1,37 +1,57 @@
-/* ###############################################################################
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-############################################################################### */
+/* #####################################################################
+ Tasks.cpp
+ ---------
+
+ Embedded Software - Assignment 2
+ --------------------------------
+
+ Written by: Steven Kay
+
+ Date: February 2016
+
+ Function: This
+
+ Version: 1.0
+
+ Version History
+ ---------------
+
+ 1.1 rgdfgdfgdfggdfgdg
+
+ 1.0 gdgddfdddgd
+
+ ##################################################################### */
#include "mbed.h"
#include "Tasks.h"
-
+#include "MCP23017.h"
+#include "WattBob_TextLCD.h"
/* ==================================== Task 1 ==================================== */
Task1::Task1(PinName squareWaveInPin)
{
- Timer Task1Timer;
- _squareWaveIn = new DigitalIn(squareWaveInPin);
+ _squareWaveIn = new InterruptIn(squareWaveInPin);
}
-int Task1::MeasureFreq()
-{
- return 0;
+void Task1::MeasureFrequency()
+{
+ _Task1Timer.start();
+ _squareWaveIn -> rise(this,&Task1::StopCounter);
}
+void Task1::StopCounter()
+{
+ _Task1Timer.stop();
+ measuredFrequency = _Task1Timer.read_us();
+ _Task1Timer.reset();
+}
+
+int Task1::ReadFrequency()
+{
+ _squareWaveIn -> rise(this,&Task1::MeasureFrequency);
+
+ return measuredFrequency;
+}
/* ==================================== Task 2 ==================================== */
Task2::Task2(PinName digitalInCheckPin)
@@ -79,19 +99,32 @@
float readBuffer_2 = 0.0;
float outputBuffer[2];
- float *outputBufferPtr =&outputBuffer[0];
// outputBuffer[0] = _AnalogIn1 -> read();
// outputBuffer[1] = _AnalogIn2 -> read();
for(int readCount = 0;readCount < NUM_ANALOG_SAMPLES; readCount++)
{
- readBuffer_1 += _AnalogIn1 -> read();
- readBuffer_2 += _AnalogIn2 -> read();
+ readBuffer_1 += ((_AnalogIn1 -> read())*3.3);
+// printf("Buffer 1 %f\r\n",readBuffer_1);
+ readBuffer_2 += ((_AnalogIn2 -> read())*3.3);
+// printf("Buffer 2 %f\r\n",readBuffer_2);
}
outputBuffer[0] = readBuffer_1/NUM_ANALOG_SAMPLES;
- outputBuffer[1] = readBuffer_1/NUM_ANALOG_SAMPLES;
+// printf("outputBuffer[0] %f\r\n",outputBuffer[0]);
+ outputBuffer[1] = readBuffer_2/NUM_ANALOG_SAMPLES;
+// printf("outputBuffer[1] %f\r\n",outputBuffer[1]);
+ float *outputBufferPtr =&outputBuffer[0];
+
return outputBufferPtr;
}
+
+/* ==================================== Task 5 ==================================== */
+Task5::Task5()
+{
+
+
+}
+
--- a/Tasks.h Wed Feb 17 10:22:50 2016 +0000
+++ b/Tasks.h Fri Feb 26 10:36:23 2016 +0000
@@ -1,20 +1,26 @@
-/* ###############################################################################
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-############################################################################### */
+/* #####################################################################
+ Tasks.h
+ -------
+
+ Embedded Software - Assignment 2
+ --------------------------------
+
+ Written by: Steven Kay
+
+ Date: February 2016
+
+ Function: This
+
+ Version: 1.0
+
+ Version History
+ ---------------
+
+ 1.1 rgdfgdfgdfggdfgdg
+
+ 1.0 gdgddfdddgd
+
+ ##################################################################### */
#ifndef _TASKS_H_
#define _TASKS_H_
@@ -34,7 +40,7 @@
// Task 3 definitions
// Task 4 definitions
-#define NUM_ANALOG_SAMPLES 4
+#define NUM_ANALOG_SAMPLES 4.0
// Task 5 definitions
@@ -49,10 +55,17 @@
{
public:
Task1(PinName squareWaveInPin);
- int MeasureFreq();
+ int ReadFrequency();
private:
- DigitalIn *_squareWaveIn;
+ Timer _Task1Timer;
+
+ void MeasureFrequency();
+ void StopCounter();
+
+ volatile int measuredFrequency;
+
+ InterruptIn *_squareWaveIn;
};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WattBob_TextLCD.lib Fri Feb 26 10:36:23 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/jimherd/code/WattBob_TextLCD/#3b26cd028e85
--- a/main.cpp Wed Feb 17 10:22:50 2016 +0000
+++ b/main.cpp Fri Feb 26 10:36:23 2016 +0000
@@ -1,40 +1,68 @@
-/* ###############################################################################
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-############################################################################### */
+/* #####################################################################
+ main.cpp
+ ---------
+
+ Embedded Software - Assignment 2
+ --------------------------------
+
+ Written by: Steven Kay
+
+ Date: February 2016
+
+ Function: This
+
+ Version: 1.0
+
+ Version History
+ ---------------
+
+ 1.1 rgdfgdfgdfggdfgdg
+
+ 1.0 gdgddfdddgd
+
+ ##################################################################### */
#include "mbed.h"
#include "Tasks.h"
+#include "MCP23017.h"
+#include "WattBob_TextLCD.h"
+#define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT)
+#define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT)
+
+MCP23017 *par_port;
+WattBob_TextLCD *lcd;
DigitalOut myled(LED1);
-Task1 task1(p5); // Square wave Measurement
-Task2 task2_switch1(p6); // Read digital Output
-Task3 task3(p7); // Watchdog Pulse
-Task4 task4(p15,p16); // Read analog Inputs
+Task1 task1(p11); // Square wave Measurement
+Task2 task2_switch1(p12); // Read digital Output
+Task3 task3(p13); // Watchdog Pulse
+Task4 task4(p15,p16); // Read analog Inputs
+void updateDisplay(int task1Param,int task2Param, float task4Channel1, float task4Channel2);
int main() {
- task1.MeasureFreq();
- int switch1State = task2_switch1.digitalInState();
+ par_port = new MCP23017(p9,p10,0x40);
+ lcd = new WattBob_TextLCD(par_port);
+ par_port -> write_bit(1,BL_BIT);
+
+
+ int task1Frequency = task1.ReadFrequency();
+ printf("Task 1 Frequency %d Hz\r\n",task1Frequency);
+
+ int task2SwitchState = task2_switch1.digitalInState();
+ printf("Switch 1 State: %d\r\n",task2SwitchState);
+
task3.OutputWatchdogPulse();
+
float *analogReading = task4.returnAnalogReadings();
+ float channel1 = *(analogReading);
+ float channel2 = *(analogReading+1);
+ printf("Analog Readings:\r\nChannel 1-%f\r\nChannel 2-%f\r\n",channel1,channel2);
+ updateDisplay(task1Frequency,task2SwitchState,channel1,channel2);
while(1) {
myled = 1;
wait(0.2);
@@ -42,3 +70,12 @@
wait(0.2);
}
}
+
+void updateDisplay(int task1Param,int task2Param, float task4Channel1, float task4Channel2)
+{
+ lcd -> cls();
+ lcd -> locate(0,0);
+ lcd -> printf("F-%4dHz S1-%d ",task1Param,task2Param);
+ lcd -> locate(1,0);
+ lcd -> printf("C1-%1.2f C2-%1.2f ",task4Channel1,task4Channel2);
+}
\ No newline at end of file