chad

Dependencies:   MCP23017 WattBob_TextLCD mbed-rtos mbed

main.cpp

Committer:
f_legge
Date:
2017-03-07
Revision:
5:e1ade53bce83
Parent:
4:70553c83c65a
Child:
6:c538f317f426

File content as of revision 5:e1ade53bce83:

// Paramater Allocation
// Paramater: 17
// Log Option: 1 (uSD)
// Watchdog Pulse Length: 6ms
// Watchdog Repetion Rate: 0.5
// Error Display: 1 (LCD)
// Execution time display: Task5 (LDC display) 
 


#include "mbed.h"
#include "MCP23017.h"
#include "WattBob_TextLCD.h"
#include "SDFileSystem"

#define     BACK_LIGHT_ON(INTERFACE)    INTERFACE->write_bit(1,BL_BIT)
#define     BACK_LIGHT_OFF(INTERFACE)    INTERFACE->write_bit(0,BL_BIT)

// Pointers to LCD Screen
MCP23017            *par_port;  // pointer to 16-bit parallel I/O chip
WattBob_TextLCD     *lcd;       // pointer to 2*16 character LCD object

// Digital I/O p11 to p20
DigitalIn FqIn(p11);            // Digital frequency in for measurement
DigitalIn DSIn(p12);            // Digital switch input
DigitalOut WD_pulse(p14);       // Watchdog Pulse
SDFileSystem uSD(p5, p6, p7, p8, "uSD");    //uSD pinout

// Analogue I/O p15 to p20
AnalogIn A1_in(p15);            // Analogue input to be filtered  
AnalogIn A2_in(p16);            // Analogue input to be filtered

// Timer objects
Timer timer;                    // Frequency Timer
Timer tick;                     // Clock timer for CycExec
Timer idle;                     // Timer for idle states

// Constant Declaration
const int SampFreq = 100;       // Sampling Frequency
const int WD = 6000;            // Watchdog pulse length

// Variable Declaration
long int tck = 0;               // Used to define what task is called (CycExec)

int period = 0;                 // Frequency timer variable (Frequency Check)
int freq = 0;                   // Frequency return variable (Frequency Check)

bool switch_state = 0;          // Switch high or low (Digital In)
    
int A1_val = 0;                 // Analogue 1 return variable (Analogue In)
int A2_val = 0;                 // Analogue 2 return variable (Analogue In)


////////////////////////////////////////////////////////////////////////////////
//
// Main Program
//

int main()
{
    // LCD Init
    par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip
    lcd = new WattBob_TextLCD(par_port);    // initialise 2*26 char display
    par_port->write_bit(1,BL_BIT);          // turn LCD backlight ON
    lcd->cls(); // clear display 
    
    // .csv log Init
    fp = fopen ("/uSD/log.csv", "w");       // Pointer to log file on uSD
    fprintf(fp, "Log of Frazer Legge's Embedded Software Assignment 2\n\n"); 
    
    // 
    tick.attach(&CycExec, 0.025);           // Period set to 25ms
    while(1){
        }
}

void CycExec()
{
        idle.stop();
        
        if(tck % 40 = 0)        // Every Second (needs offset)