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 USBDevice WattBob_TextLCD mbed
Function.h
00001 #include "MCP23017.h" 00002 #include "WattBob_TextLCD.h" 00003 #include "mbed.h" 00004 #include "SDFileSystem.h" 00005 00006 MCP23017 Port(p9,p10,0x40) ; // 16-bit object with I2C Chip MCP23017 00007 WattBob_TextLCD LCD(&Port); // A 2*16 chacater LCD object 00008 00009 00010 BusOut BinLed(LED4, LED3, LED2, LED1); 00011 00012 DigitalIn FrequencyIn(p15); 00013 DigitalIn Switch1(p17); 00014 DigitalIn Switch2(p18); 00015 /* 00016 These pins are used to show the time between every execution. 00017 Because of the execution time is very small I used the pins to flip 00018 high and low with every time the functions are called. Consequently, 00019 the period of high or of low represent the complete time. 00020 00021 */ 00022 DigitalOut TickerPin(p30); 00023 00024 DigitalOut ReadDigitalinPin(p21); 00025 DigitalOut ReadAnaloginPin(p22); 00026 DigitalOut FreqMsurPin(p23); 00027 DigitalOut BinaryCounterPin(p24); 00028 DigitalOut InputCheckPin(p25); 00029 DigitalOut DisplayPin(p26); 00030 DigitalOut LogFilePin(p27); 00031 00032 00033 AnalogIn Analogue_in_1(p19); 00034 AnalogIn Analogue_in_2(p20); 00035 00036 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board 00037 00038 uint8_t Analug1_valu[5]={0,0,0,0,0}; 00039 uint8_t Analug2_valu[5]={0,0,0,0,0}; 00040 uint8_t Bin=0x00; 00041 bool Swch1; 00042 bool Swch2; 00043 bool Ena_BinCounter=0; 00044 bool FreqTimeOutHpn; 00045 uint8_t Error_Code; 00046 uint16_t Freq; 00047 char Temp[4]; 00048 FILE *fp; 00049 00050 Timer FreqMsurT; 00051 Timer FreqTimeOut; 00052 Timer LogTimer; 00053 00054 Ticker Cycle; 00055 00056 void Init_LCD(); 00057 void FreqMsur(); 00058 void ReadDigitalin(); 00059 void ReadAnalogin(); 00060 void Display(); 00061 void InputCheck(); 00062 void BinaryCounter(); 00063 void InitFile(); 00064 void LogFile(); 00065 00066 /****************************************************************************** 00067 Small function to writ on the LCD with one instruction 00068 ********************************************************************************/ 00069 void Write_LCD(const char STR[],int8_t PY,int8_t PX,bool clr){ 00070 if(clr) 00071 LCD.cls(); 00072 LCD.locate(PY,PX); 00073 LCD.printf(STR); 00074 } 00075 /************************************************************************** 00076 Intialise the LCD to be ready to writ on 00077 ***************************************************************************/ 00078 void Init_LCD(){ 00079 Port.write_bit(1,BL_BIT); 00080 Write_LCD("F=",0,0,1); 00081 Write_LCD("A1=",1,0,0); 00082 Write_LCD("A2=",1,7,0); 00083 Write_LCD("S1=",0,7,0); 00084 Write_LCD("S2=",0,12,0); 00085 Write_LCD("E",1,14,0); 00086 } 00087 00088 /************************************************************************* 00089 Cheaking the four input every 1.8 Sec 00090 ************************************************************************/ 00091 void InputCheck(){ 00092 InputCheckPin = ! (InputCheckPin); //Pin 25 00093 if(Swch1&&(Analug1_valu[4]>Analug2_valu[4])){ 00094 Error_Code=3; 00095 } 00096 else{ 00097 Error_Code=0; 00098 } 00099 if(Swch2){ 00100 Ena_BinCounter=1; 00101 } 00102 else{ 00103 Ena_BinCounter=0; 00104 } 00105 } 00106 00107 /*************************************************************** 00108 Initialising the SD card file 00109 *****************************************************************/ 00110 void InitFile(){ 00111 fp = fopen( "/sd/LogDir/LogHistory.csv" , "a"); 00112 if(fp == NULL) { 00113 Write_LCD("SD Card Error",0,0,1); 00114 Write_LCD("Try Reset",1,0,0); 00115 } 00116 fprintf(fp,"Time;Freq;Sw1;Sw2;An1;An2\r\n"); 00117 fclose(fp); 00118 } 00119 /************************************************************** 00120 Saving the flowing data in a file 00121 a. Frequency value 00122 b. digital input values 00123 c. Filtered analogue values 00124 ***************************************************************/ 00125 void LogFile(){ 00126 LogFilePin = ! (LogFilePin); //Pin 27 00127 fp = fopen( "/sd/LogDir/LogHistory.csv" , "a"); 00128 fprintf(fp,"%i;",(LogTimer.read_ms()/1000)); 00129 if (Freq !=0xffff){ 00130 fprintf(fp,"%4i;",Freq); 00131 } 00132 else{ 00133 fprintf(fp,"%4s;","Err"); 00134 } 00135 fprintf(fp,"%i;",Swch1); 00136 fprintf(fp,"%i;",Swch2); 00137 fprintf(fp,"%3d;",Analug1_valu[4]); 00138 fprintf(fp,"%3d;",Analug2_valu[4]); 00139 fprintf(fp,"%s","\r\n"); 00140 fclose(fp); 00141 //LogFilePin = ! (LogFilePin); 00142 }
Generated on Tue Jul 12 2022 21:34:48 by
