chad

Dependencies:   MCP23017 WattBob_TextLCD mbed-rtos mbed

Committer:
f_legge
Date:
Tue Mar 07 16:41:36 2017 +0000
Revision:
7:71a923f423f4
Parent:
6:c538f317f426
Child:
8:0e46cf19fc45
Added write to uSD

Who changed what in which revision?

UserRevisionLine numberNew contents of line
f_legge 4:70553c83c65a 1 // Paramater Allocation
f_legge 4:70553c83c65a 2 // Paramater: 17
f_legge 4:70553c83c65a 3 // Log Option: 1 (uSD)
f_legge 4:70553c83c65a 4 // Watchdog Pulse Length: 6ms
f_legge 4:70553c83c65a 5 // Watchdog Repetion Rate: 0.5
f_legge 4:70553c83c65a 6 // Error Display: 1 (LCD)
f_legge 4:70553c83c65a 7 // Execution time display: Task5 (LDC display)
f_legge 4:70553c83c65a 8
f_legge 4:70553c83c65a 9
f_legge 4:70553c83c65a 10
f_legge 0:10e3e2697134 11 #include "mbed.h"
f_legge 4:70553c83c65a 12 #include "MCP23017.h"
f_legge 4:70553c83c65a 13 #include "WattBob_TextLCD.h"
f_legge 4:70553c83c65a 14 #include "SDFileSystem"
f_legge 4:70553c83c65a 15
f_legge 4:70553c83c65a 16 #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT)
f_legge 4:70553c83c65a 17 #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT)
f_legge 0:10e3e2697134 18
f_legge 4:70553c83c65a 19 // Pointers to LCD Screen
f_legge 4:70553c83c65a 20 MCP23017 *par_port; // pointer to 16-bit parallel I/O chip
f_legge 4:70553c83c65a 21 WattBob_TextLCD *lcd; // pointer to 2*16 character LCD object
f_legge 7:71a923f423f4 22 FILE *fo; // pointer to uSD object
f_legge 4:70553c83c65a 23
f_legge 4:70553c83c65a 24 // Digital I/O p11 to p20
f_legge 4:70553c83c65a 25 DigitalIn FqIn(p11); // Digital frequency in for measurement
f_legge 4:70553c83c65a 26 DigitalIn DSIn(p12); // Digital switch input
f_legge 4:70553c83c65a 27 DigitalOut WD_pulse(p14); // Watchdog Pulse
f_legge 4:70553c83c65a 28 SDFileSystem uSD(p5, p6, p7, p8, "uSD"); //uSD pinout
f_legge 4:70553c83c65a 29
f_legge 4:70553c83c65a 30 // Analogue I/O p15 to p20
f_legge 4:70553c83c65a 31 AnalogIn A1_in(p15); // Analogue input to be filtered
f_legge 4:70553c83c65a 32 AnalogIn A2_in(p16); // Analogue input to be filtered
f_legge 4:70553c83c65a 33
f_legge 4:70553c83c65a 34 // Timer objects
f_legge 4:70553c83c65a 35 Timer timer; // Frequency Timer
f_legge 4:70553c83c65a 36 Timer tick; // Clock timer for CycExec
f_legge 4:70553c83c65a 37 Timer idle; // Timer for idle states
f_legge 4:70553c83c65a 38
f_legge 4:70553c83c65a 39 // Constant Declaration
f_legge 5:e1ade53bce83 40 const int SampFreq = 100; // Sampling Frequency
f_legge 5:e1ade53bce83 41 const int WD = 6000; // Watchdog pulse length
f_legge 4:70553c83c65a 42
f_legge 4:70553c83c65a 43 // Variable Declaration
f_legge 4:70553c83c65a 44 long int tck = 0; // Used to define what task is called (CycExec)
f_legge 0:10e3e2697134 45
f_legge 4:70553c83c65a 46 int period = 0; // Frequency timer variable (Frequency Check)
f_legge 4:70553c83c65a 47 int freq = 0; // Frequency return variable (Frequency Check)
f_legge 4:70553c83c65a 48
f_legge 4:70553c83c65a 49 bool switch_state = 0; // Switch high or low (Digital In)
f_legge 4:70553c83c65a 50
f_legge 4:70553c83c65a 51 int A1_val = 0; // Analogue 1 return variable (Analogue In)
f_legge 4:70553c83c65a 52 int A2_val = 0; // Analogue 2 return variable (Analogue In)
f_legge 4:70553c83c65a 53
f_legge 6:c538f317f426 54 int logcount = 0; // Keep track of log number
f_legge 6:c538f317f426 55
f_legge 6:c538f317f426 56
f_legge 4:70553c83c65a 57
f_legge 4:70553c83c65a 58 ////////////////////////////////////////////////////////////////////////////////
f_legge 4:70553c83c65a 59 //
f_legge 4:70553c83c65a 60 // Main Program
f_legge 4:70553c83c65a 61 //
f_legge 4:70553c83c65a 62
f_legge 4:70553c83c65a 63 int main()
f_legge 4:70553c83c65a 64 {
f_legge 4:70553c83c65a 65 // LCD Init
f_legge 4:70553c83c65a 66 par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip
f_legge 4:70553c83c65a 67 lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display
f_legge 4:70553c83c65a 68 par_port->write_bit(1,BL_BIT); // turn LCD backlight ON
f_legge 4:70553c83c65a 69 lcd->cls(); // clear display
f_legge 4:70553c83c65a 70
f_legge 4:70553c83c65a 71 // .csv log Init
f_legge 7:71a923f423f4 72 fo = fopen ("/uSD/log.csv", "a"); // Pointer to log file on uSD
f_legge 7:71a923f423f4 73 fprintf(fo, "Log of Frazer Legge's Embedded Software Assignment 2\n\n");
f_legge 4:70553c83c65a 74
f_legge 4:70553c83c65a 75 //
f_legge 4:70553c83c65a 76 tick.attach(&CycExec, 0.025); // Period set to 25ms
f_legge 4:70553c83c65a 77 while(1){
f_legge 4:70553c83c65a 78 }
f_legge 0:10e3e2697134 79 }
f_legge 4:70553c83c65a 80
f_legge 4:70553c83c65a 81 void CycExec()
f_legge 4:70553c83c65a 82 {
f_legge 4:70553c83c65a 83 idle.stop();
f_legge 4:70553c83c65a 84
f_legge 4:70553c83c65a 85 if(tck % 40 = 0) // Every Second (needs offset)
f_legge 4:70553c83c65a 86
f_legge 4:70553c83c65a 87
f_legge 4:70553c83c65a 88
f_legge 4:70553c83c65a 89
f_legge 4:70553c83c65a 90