SIMPLE PROJECT THAT COMMUNICATE WITH SLAVE , TRY TO GET DATA, ANALYZE IT AND PROVIDE OUTPUT. TWO UART INTERFACE, SEMAPHORE, THREAD COMMUNICATION, LCD INTERFACING,PRIORITY BASED THREAD SWITCHING,HEX TO FLOAT CONVERSION

Dependencies:   TextLCD

Committer:
radhey04ec
Date:
Sun Aug 09 04:33:50 2020 +0000
Revision:
1:bdc3ebd4e52b
Parent:
0:7945527e6a18
Child:
2:fab01e10358e
RED LED TEST INCLUDE SUCCESSFULLY; REF VOLTAGE 3.3 VOLT NOTE THIS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
radhey04ec 0:7945527e6a18 1 /* AXF --GLOBAL VALVE BOARD TESTER
radhey04ec 0:7945527e6a18 2 PROGRAMM CREATED BY : JAYDEEP SHAH
radhey04ec 0:7945527e6a18 3 RESEARCH & DEVLOPMENT DEPARTMENT -- KEPL
radhey04ec 0:7945527e6a18 4 DATE : 22 JULY 2020
radhey04ec 0:7945527e6a18 5 VERSION : 1.0 -- MBED OPEN VERSION FILE
radhey04ec 0:7945527e6a18 6 */
radhey04ec 0:7945527e6a18 7
radhey04ec 0:7945527e6a18 8 /*--------------------------------------------------------------------------*/
radhey04ec 0:7945527e6a18 9
radhey04ec 0:7945527e6a18 10 /* OUTPUT DATA AVAILABLE ON LCD SCREEN & ON TERMINAL ALSO
radhey04ec 0:7945527e6a18 11 TERMINAL 9600 BAUD 8-N-1 T TYPE
radhey04ec 0:7945527e6a18 12 SUGGESTED TERMINAL : COOLTERM & PUTTY
radhey04ec 0:7945527e6a18 13 If any query /problems --> contact to R&D Dept of KEPL A'bad.
radhey04ec 0:7945527e6a18 14 Board Turn on Time : 20 to 25 Sec acfetr power
radhey04ec 0:7945527e6a18 15 */
radhey04ec 0:7945527e6a18 16
radhey04ec 0:7945527e6a18 17 /*--------------------------------------------------------------------------*/
radhey04ec 0:7945527e6a18 18
radhey04ec 0:7945527e6a18 19
radhey04ec 0:7945527e6a18 20 #include "mbed.h" //MBED LIBRARY
radhey04ec 0:7945527e6a18 21 #include "TextLCD.h" //LCD LIBRARY
radhey04ec 0:7945527e6a18 22
radhey04ec 0:7945527e6a18 23
radhey04ec 0:7945527e6a18 24 /* *************************SEMAPHORE CREATION BINARY********************************* */
radhey04ec 0:7945527e6a18 25 Semaphore A(0);
radhey04ec 0:7945527e6a18 26
radhey04ec 0:7945527e6a18 27
radhey04ec 0:7945527e6a18 28
radhey04ec 0:7945527e6a18 29 #define BUFFER_SIZE 90 //SIZE OF BUFFER -- TO STORE UART DATA
radhey04ec 0:7945527e6a18 30
radhey04ec 0:7945527e6a18 31 TextLCD lcd(PC_0, PC_1, PB_4, PB_5, PB_3, PA_10, TextLCD::LCD20x4); //LCD OBJECT CREATION WITH PANEL SIZE
radhey04ec 0:7945527e6a18 32
radhey04ec 0:7945527e6a18 33
radhey04ec 0:7945527e6a18 34
radhey04ec 0:7945527e6a18 35
radhey04ec 0:7945527e6a18 36 //****************************************************************************** UART SECTION AND FUNCTIONS
radhey04ec 0:7945527e6a18 37
radhey04ec 0:7945527e6a18 38
radhey04ec 0:7945527e6a18 39 char rxBuffer[BUFFER_SIZE]; //CREATE CIRCULAR BUFFER -- TO STORE RECEIVE DATA
radhey04ec 0:7945527e6a18 40
radhey04ec 0:7945527e6a18 41 unsigned int bufferReadingIndex=0; //CREATE POINTER TO READ DATA FROM UART AND STORE INTO ARRAY
radhey04ec 0:7945527e6a18 42
radhey04ec 0:7945527e6a18 43 unsigned int i=0; //counter to read data from buffer Array
radhey04ec 0:7945527e6a18 44 RawSerial UT(PA_0,PA_1); //UART PIN DECLARATION
radhey04ec 0:7945527e6a18 45 RawSerial pc(USBTX,USBRX); //HOST PC TERMINAL - 9600 BAUD WITH 8-N-1 STTING
radhey04ec 0:7945527e6a18 46
radhey04ec 0:7945527e6a18 47 //NOTE : UT OBJ FOR SLAVE BOARD & pc OBJ FOR TERMINAL
radhey04ec 0:7945527e6a18 48
radhey04ec 0:7945527e6a18 49 //DEFINE Rx Interrupt function --DECLARATION
radhey04ec 0:7945527e6a18 50 void RxInterrupt(void);
radhey04ec 0:7945527e6a18 51
radhey04ec 0:7945527e6a18 52 //Function that read response data
radhey04ec 0:7945527e6a18 53 void response(void);
radhey04ec 0:7945527e6a18 54
radhey04ec 0:7945527e6a18 55 //****************************************************************************** UART SECTION & FUNCTIONS
radhey04ec 0:7945527e6a18 56 void WELCOME_SCREEN(void); //LCD TURN ON DETAILS / POWR ON OR RESTART TIME
radhey04ec 0:7945527e6a18 57
radhey04ec 0:7945527e6a18 58
radhey04ec 0:7945527e6a18 59 //void LCD_REFRESH(void); // Thread Function -- to refresh LCD screen------------------------------------------------------TH2
radhey04ec 0:7945527e6a18 60
radhey04ec 0:7945527e6a18 61 void START_NEW_TEST(void); // Function that call by button press -- new test start
radhey04ec 0:7945527e6a18 62 volatile bool TEST_FLAG = 0U; //FLAG TO AVOID PUSH BUTTON EFFECT WHEN BOARD ON
radhey04ec 0:7945527e6a18 63
radhey04ec 0:7945527e6a18 64 volatile bool PROCESS_FLAG = 0U; //PROCESS_FLAG -- DURING TESTING ITS ON = 1
radhey04ec 0:7945527e6a18 65
radhey04ec 0:7945527e6a18 66 volatile uint8_t PCB_COUNTER = 0; //GLOBAL PCB COUNTER
radhey04ec 0:7945527e6a18 67
radhey04ec 0:7945527e6a18 68 //float CURRENT_MEASUREMENT(void); //Thread Function current measurement function that return float value--------------------TH1
radhey04ec 0:7945527e6a18 69
radhey04ec 0:7945527e6a18 70 float voltage = 0; //Voltage measurement functions
radhey04ec 0:7945527e6a18 71
radhey04ec 0:7945527e6a18 72 //Create Interrupt object -- Pin -- Push button connection********************** DIGITAL I/O SECTION AND INTERRUPT
radhey04ec 0:7945527e6a18 73 InterruptIn swt(PB_2); //PUSH BUTTON CONNECTED WITH THIS PIN
radhey04ec 0:7945527e6a18 74
radhey04ec 0:7945527e6a18 75 //LED_BUZZER CONNECTION
radhey04ec 0:7945527e6a18 76 DigitalOut RED_LED(PB_13); //
radhey04ec 0:7945527e6a18 77 DigitalOut BLUE_LED(PB_14);
radhey04ec 0:7945527e6a18 78 DigitalOut GREEN_LED(PB_15);
radhey04ec 0:7945527e6a18 79 DigitalOut BUZZER(PC_8); //BUZZER CONNECT
radhey04ec 0:7945527e6a18 80
radhey04ec 0:7945527e6a18 81 //****************************************************************************** DIGITAL I/O SECTION END
radhey04ec 0:7945527e6a18 82
radhey04ec 0:7945527e6a18 83 //RESULT AND ERROR FUNCTIONS
radhey04ec 0:7945527e6a18 84 void result(void);
radhey04ec 0:7945527e6a18 85 void error(uint8_t);
radhey04ec 0:7945527e6a18 86
radhey04ec 0:7945527e6a18 87 //LCD FLAG -- THIS IS FOR RETRIVE DATA FROM ARRAY
radhey04ec 0:7945527e6a18 88 volatile uint8_t LCD_FLAG = 0;
radhey04ec 0:7945527e6a18 89
radhey04ec 0:7945527e6a18 90 //NEW_TEST_UPDATE_LCD
radhey04ec 0:7945527e6a18 91 void NEW_TEST_UPDATE_LCD();
radhey04ec 0:7945527e6a18 92
radhey04ec 0:7945527e6a18 93 //TESTING SCHEDULE FUNCTION
radhey04ec 0:7945527e6a18 94 void TEST_PROCESS(void);
radhey04ec 0:7945527e6a18 95
radhey04ec 0:7945527e6a18 96 //******************************* VARIABLE TO STORE ADC DATA
radhey04ec 0:7945527e6a18 97 float current = 0; //Global value
radhey04ec 0:7945527e6a18 98 float AARAY[10],SUM=0;
radhey04ec 0:7945527e6a18 99
radhey04ec 0:7945527e6a18 100 // THREAD FUNCTIONS************************************************************* THREAD SECTION
radhey04ec 0:7945527e6a18 101 void CURRENT(void); //TO FIND INPUT DC CURRENT
radhey04ec 0:7945527e6a18 102 void CURRENT_MEASUREMENT()
radhey04ec 0:7945527e6a18 103 {
radhey04ec 0:7945527e6a18 104 while(true)
radhey04ec 0:7945527e6a18 105 {
radhey04ec 0:7945527e6a18 106 CURRENT(); //FUNCTION CALL TO MEASURE CURRENT
radhey04ec 0:7945527e6a18 107
radhey04ec 0:7945527e6a18 108 //Thread Yield
radhey04ec 0:7945527e6a18 109 ThisThread::sleep_for(100); //Thread sleep
radhey04ec 0:7945527e6a18 110 }
radhey04ec 0:7945527e6a18 111
radhey04ec 0:7945527e6a18 112 }
radhey04ec 0:7945527e6a18 113
radhey04ec 0:7945527e6a18 114 void LCD_REFRESH()
radhey04ec 0:7945527e6a18 115 {
radhey04ec 0:7945527e6a18 116 volatile bool v =0;
radhey04ec 0:7945527e6a18 117 while(true)
radhey04ec 0:7945527e6a18 118 {
radhey04ec 0:7945527e6a18 119 v = A.try_acquire();
radhey04ec 0:7945527e6a18 120
radhey04ec 0:7945527e6a18 121 if(v==1)
radhey04ec 0:7945527e6a18 122 {
radhey04ec 0:7945527e6a18 123 lcd.locate(0,3);
radhey04ec 0:7945527e6a18 124 lcd.printf("Current = %.2f mA",current);
radhey04ec 0:7945527e6a18 125 lcd.locate(19,3);
radhey04ec 0:7945527e6a18 126 lcd.printf("ET");
radhey04ec 0:7945527e6a18 127 pc.printf("\n Input Current is = %.2f mA",current);
radhey04ec 0:7945527e6a18 128 ThisThread::sleep_for(150);
radhey04ec 0:7945527e6a18 129 }
radhey04ec 0:7945527e6a18 130 }
radhey04ec 0:7945527e6a18 131
radhey04ec 0:7945527e6a18 132 }
radhey04ec 0:7945527e6a18 133 //****************************************************************************** THREAD SECTION END
radhey04ec 0:7945527e6a18 134
radhey04ec 0:7945527e6a18 135 //CREATE TWO THREAD
radhey04ec 0:7945527e6a18 136 Thread T1(osPriorityLow),T2;
radhey04ec 0:7945527e6a18 137
radhey04ec 0:7945527e6a18 138
radhey04ec 0:7945527e6a18 139 //****************************************************************************** ADC SECTION
radhey04ec 0:7945527e6a18 140 /*
radhey04ec 0:7945527e6a18 141 // INA-225 TEXAS INSTRUMENT BOARDS TO AMPLIFY LOW VOLTAGE SIGNAL WITH GAIN 200
radhey04ec 0:7945527e6a18 142 //SHUNT RESISTOR = 0.6 Ohm
radhey04ec 0:7945527e6a18 143 //Vref : 3.3
radhey04ec 0:7945527e6a18 144 // I (current) = ((((ADC O/P - Offset)) * 3.3) *200 ) / 0.6) * 1000 mA
radhey04ec 0:7945527e6a18 145 CLASS --> AnalogIn
radhey04ec 0:7945527e6a18 146 Object return value between 0 to 1
radhey04ec 0:7945527e6a18 147 If 5 V system and you try to read 2.5 V from ADC PIN than OP = 0.5
radhey04ec 0:7945527e6a18 148 PLEASE NOTE : MBED USE 3.3 Vref
radhey04ec 0:7945527e6a18 149 For more information look at thread details
radhey04ec 0:7945527e6a18 150 */
radhey04ec 0:7945527e6a18 151 AnalogIn ANG(PC_3); //Port pin PC_3 last pin for ADC -- Create object
radhey04ec 0:7945527e6a18 152
radhey04ec 0:7945527e6a18 153
radhey04ec 0:7945527e6a18 154 /***************************************************************************
radhey04ec 0:7945527e6a18 155 UART BUFFER PROBLEMS : FLUSH ()
radhey04ec 0:7945527e6a18 156 NOTE : MBED HAVE NO SUCH TYPE OF FUNCTIONS
radhey04ec 0:7945527e6a18 157 SO YOU NEED TO CLEAR UART BUFFER BEFORE REPEAT THE PROCEDURE
radhey04ec 0:7945527e6a18 158 SIMPLE WAY IS READ THE INTERNAL UART BUFFER
radhey04ec 0:7945527e6a18 159 ***************************************************************************/
radhey04ec 0:7945527e6a18 160 //MAKE FUNCTION TO RESET BUFFER DATA AND COUNTER
radhey04ec 0:7945527e6a18 161
radhey04ec 0:7945527e6a18 162 void BUFFER_CLEAR(void);
radhey04ec 0:7945527e6a18 163
radhey04ec 0:7945527e6a18 164
radhey04ec 0:7945527e6a18 165 //MAIN FUNCTIONAL AREA*************************************************************
radhey04ec 0:7945527e6a18 166
radhey04ec 0:7945527e6a18 167 //****************FOR NEXT STAGE OF PROJECT
radhey04ec 0:7945527e6a18 168
radhey04ec 0:7945527e6a18 169 bool NEXT = 0U;
radhey04ec 0:7945527e6a18 170 bool ERROR_FLAG = 0U;
radhey04ec 1:bdc3ebd4e52b 171
radhey04ec 1:bdc3ebd4e52b 172 //*************************************LDR AREA LIGHT DETECTION*****************************
radhey04ec 1:bdc3ebd4e52b 173 //NOTE LDR SUPPLY BY 3.3 VOLT -- PLEASE NOTE THIS
radhey04ec 1:bdc3ebd4e52b 174 AnalogIn LDR(PB_0); //PB_0 is LDR sensor input
radhey04ec 1:bdc3ebd4e52b 175 float LDR_VALUE = 0; // TO STORE LDR DATA
radhey04ec 1:bdc3ebd4e52b 176
radhey04ec 1:bdc3ebd4e52b 177
radhey04ec 1:bdc3ebd4e52b 178
radhey04ec 0:7945527e6a18 179 int main()
radhey04ec 0:7945527e6a18 180 {
radhey04ec 0:7945527e6a18 181
radhey04ec 0:7945527e6a18 182 UT.baud(57600); //BAUD RATE SETTING
radhey04ec 0:7945527e6a18 183 UT.format(8,Serial::None,1); //FORMAT OF UART COMMUNICATION
radhey04ec 0:7945527e6a18 184
radhey04ec 0:7945527e6a18 185 //INTERRUPT ATTACHMENT WHEN RECEIVE DATA --UART INTERRUPT
radhey04ec 0:7945527e6a18 186 UT.attach(&RxInterrupt,Serial::RxIrq);
radhey04ec 0:7945527e6a18 187
radhey04ec 0:7945527e6a18 188 //PUSH BUTTON INTERRUPT FUNCTION -- PUSH BUTTON INTERRUPT
radhey04ec 0:7945527e6a18 189 swt.rise(&TEST_PROCESS); //THIS FUNCTION Call when push button press
radhey04ec 0:7945527e6a18 190
radhey04ec 0:7945527e6a18 191 pc.printf("\n STM POWER ON -- DATA INITIALIZATION \n");
radhey04ec 0:7945527e6a18 192 pc.printf("\n PROGRAM CREATED BY : R_AND_D DEPT of KEPL \n");
radhey04ec 0:7945527e6a18 193 pc.printf("\n Program Version 1.0 \n");
radhey04ec 0:7945527e6a18 194 pc.printf("\n Any changes of the program lead toward Board OS Crash or bugs");
radhey04ec 1:bdc3ebd4e52b 195 pc.printf("\n Permission require before any Hardware / software changes \n");
radhey04ec 1:bdc3ebd4e52b 196 pc.printf("\n RTOS TRYING TO ACCESS THREAD CODE......INITIALIZATIO OF RTOS START.....");
radhey04ec 0:7945527e6a18 197 pc.printf("\n Do not press any Button");
radhey04ec 0:7945527e6a18 198
radhey04ec 0:7945527e6a18 199
radhey04ec 0:7945527e6a18 200 //INITIAL ALL LED OFF
radhey04ec 0:7945527e6a18 201 pc.printf("\n MAKE ALL LEDS and BUZZER OFF \n");
radhey04ec 0:7945527e6a18 202 RED_LED = 0;
radhey04ec 0:7945527e6a18 203 GREEN_LED = 0;
radhey04ec 0:7945527e6a18 204 BLUE_LED = 0;
radhey04ec 0:7945527e6a18 205 BUZZER = 0;
radhey04ec 0:7945527e6a18 206
radhey04ec 0:7945527e6a18 207 WELCOME_SCREEN(); //TO INITIALIZE DATA
radhey04ec 0:7945527e6a18 208
radhey04ec 0:7945527e6a18 209 pc.printf("\n Good Luck !!!!");
radhey04ec 0:7945527e6a18 210 pc.printf("\n CURRENT MEASUREMENT UNIT TURNING ON");
radhey04ec 0:7945527e6a18 211
radhey04ec 0:7945527e6a18 212 T1.start(CURRENT_MEASUREMENT);
radhey04ec 0:7945527e6a18 213 T2.start(LCD_REFRESH);
radhey04ec 0:7945527e6a18 214
radhey04ec 1:bdc3ebd4e52b 215 pc.printf("\n All Thread create succesffully\n");
radhey04ec 0:7945527e6a18 216 wait_ms(500);
radhey04ec 1:bdc3ebd4e52b 217 pc.printf("\n NOW PLUG THE UNIT AND PRESS THE BUTTON \n");
radhey04ec 0:7945527e6a18 218 while(true)
radhey04ec 0:7945527e6a18 219 {
radhey04ec 0:7945527e6a18 220 BLUE_LED = 0;
radhey04ec 0:7945527e6a18 221 START_NEW_TEST(); //This function only work if FLAG SET
radhey04ec 0:7945527e6a18 222 wait_ms(500);
radhey04ec 0:7945527e6a18 223
radhey04ec 0:7945527e6a18 224 BLUE_LED = 1;
radhey04ec 0:7945527e6a18 225
radhey04ec 0:7945527e6a18 226 }
radhey04ec 0:7945527e6a18 227
radhey04ec 0:7945527e6a18 228 }
radhey04ec 0:7945527e6a18 229
radhey04ec 0:7945527e6a18 230 void RxInterrupt() //if Rx buffer have data --- Interrupt call
radhey04ec 0:7945527e6a18 231 {
radhey04ec 0:7945527e6a18 232 //Because of Interrupt -- Ideally no CONTEXT SWITCH
radhey04ec 0:7945527e6a18 233 if(UT.readable()) //IF data available
radhey04ec 0:7945527e6a18 234 {
radhey04ec 0:7945527e6a18 235 rxBuffer[bufferReadingIndex++] = UT.getc(); // read and store into Buffer
radhey04ec 0:7945527e6a18 236 if(bufferReadingIndex >= BUFFER_SIZE) // If limit cross
radhey04ec 0:7945527e6a18 237 {
radhey04ec 0:7945527e6a18 238 bufferReadingIndex =0; // RESET CONTER
radhey04ec 0:7945527e6a18 239 }
radhey04ec 0:7945527e6a18 240 }
radhey04ec 0:7945527e6a18 241 }
radhey04ec 0:7945527e6a18 242
radhey04ec 0:7945527e6a18 243 void response() //FUNCTION TO READ DATA
radhey04ec 0:7945527e6a18 244 {
radhey04ec 0:7945527e6a18 245 char rxByte;
radhey04ec 0:7945527e6a18 246 printf("\n");
radhey04ec 0:7945527e6a18 247
radhey04ec 0:7945527e6a18 248 //NEED TO STOP CONTEXT SWITCH
radhey04ec 0:7945527e6a18 249 while(i != bufferReadingIndex) //READ WHILE COMPLETE DATA NOT RECEIVED
radhey04ec 0:7945527e6a18 250 {
radhey04ec 0:7945527e6a18 251 rxByte = rxBuffer[i]; //READ DATA ONE BY ONE CHARACTER
radhey04ec 0:7945527e6a18 252 pc.putc(rxByte); // SEND ON TERMINAL
radhey04ec 0:7945527e6a18 253 i++; //COUNTER INCREMEN
radhey04ec 0:7945527e6a18 254
radhey04ec 0:7945527e6a18 255 if(i >= BUFFER_SIZE) //IF LIMIT CROSS
radhey04ec 0:7945527e6a18 256 {
radhey04ec 0:7945527e6a18 257 i = 0; //RESET COUNTER
radhey04ec 0:7945527e6a18 258 }
radhey04ec 0:7945527e6a18 259 }
radhey04ec 0:7945527e6a18 260
radhey04ec 0:7945527e6a18 261 //USE THREAD YIELD FOR UPDATE OTHER THREADS
radhey04ec 0:7945527e6a18 262
radhey04ec 0:7945527e6a18 263
radhey04ec 0:7945527e6a18 264
radhey04ec 0:7945527e6a18 265 LCD_FLAG = 0; //RESET -- VERSION READ COMPLETED
radhey04ec 0:7945527e6a18 266 //THREA YIELD
radhey04ec 0:7945527e6a18 267
radhey04ec 0:7945527e6a18 268
radhey04ec 0:7945527e6a18 269 }
radhey04ec 0:7945527e6a18 270
radhey04ec 0:7945527e6a18 271 void START_NEW_TEST(void)
radhey04ec 0:7945527e6a18 272 {
radhey04ec 0:7945527e6a18 273 if(TEST_FLAG == 1U && PROCESS_FLAG == 0U)
radhey04ec 0:7945527e6a18 274 {
radhey04ec 0:7945527e6a18 275 //FLAG MUST BE ZERO
radhey04ec 0:7945527e6a18 276 NEXT = 0;
radhey04ec 0:7945527e6a18 277 ERROR_FLAG = 0;
radhey04ec 0:7945527e6a18 278 RED_LED =0;
radhey04ec 0:7945527e6a18 279 GREEN_LED =1;
radhey04ec 0:7945527e6a18 280 PROCESS_FLAG = 1U;
radhey04ec 0:7945527e6a18 281 //turn test flag on
radhey04ec 0:7945527e6a18 282 TEST_FLAG =1U;
radhey04ec 0:7945527e6a18 283 //COUNTER++
radhey04ec 0:7945527e6a18 284 PCB_COUNTER++;
radhey04ec 0:7945527e6a18 285 //NEED TO WAIT 25 ms
radhey04ec 0:7945527e6a18 286 pc.printf("\n \n \n");
radhey04ec 0:7945527e6a18 287 pc.printf("***********************************************************");
radhey04ec 0:7945527e6a18 288 pc.printf("AXV 001 PCB NUMBER = %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 289 NEW_TEST_UPDATE_LCD(); //THIS FUNCTION IS ONLY FOR DELAY
radhey04ec 0:7945527e6a18 290
radhey04ec 0:7945527e6a18 291
radhey04ec 0:7945527e6a18 292 A.release();
radhey04ec 0:7945527e6a18 293 //last fucntion to reset flag and display test result
radhey04ec 0:7945527e6a18 294 wait(0.150);
radhey04ec 0:7945527e6a18 295 //CLEAR THE BUFFER BEFORE UART COMM
radhey04ec 0:7945527e6a18 296 //***************TEST - 1 ENTER INTEST MODE AND VERSION READ------------------------------TEST1
radhey04ec 0:7945527e6a18 297 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 298 UT.putc('T'); //ENTER IN TEST MODE -- SLAVE BOARD ENTER INTO TEST MODE
radhey04ec 0:7945527e6a18 299 A.release();
radhey04ec 0:7945527e6a18 300 ThisThread::sleep_for(1000);
radhey04ec 0:7945527e6a18 301 response();
radhey04ec 0:7945527e6a18 302 wait(0.10);
radhey04ec 0:7945527e6a18 303 //FETCHING VERSION NUMBER 01.34
radhey04ec 0:7945527e6a18 304 lcd.cls();
radhey04ec 0:7945527e6a18 305 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 306 lcd.printf("VERSION TEST ON");
radhey04ec 0:7945527e6a18 307 {
radhey04ec 0:7945527e6a18 308 uint8_t j=0;
radhey04ec 0:7945527e6a18 309 char temp_buf[6];
radhey04ec 0:7945527e6a18 310 char ver[] = "01.34";
radhey04ec 0:7945527e6a18 311 pc.puts("\n FETCHING VERSION FROM IC: ");
radhey04ec 0:7945527e6a18 312 for(j=13;j<18;j++)
radhey04ec 0:7945527e6a18 313 {
radhey04ec 0:7945527e6a18 314 pc.putc(rxBuffer[j]);
radhey04ec 0:7945527e6a18 315 temp_buf[j-13] = rxBuffer[j];
radhey04ec 0:7945527e6a18 316 }
radhey04ec 0:7945527e6a18 317 temp_buf[5] = '\n';
radhey04ec 0:7945527e6a18 318 float value = atof(temp_buf);
radhey04ec 0:7945527e6a18 319 pc.printf("\n VERSION VALUE IS %f",value);
radhey04ec 0:7945527e6a18 320 if(value == 1.340000f)
radhey04ec 0:7945527e6a18 321 {
radhey04ec 0:7945527e6a18 322 pc.printf("\n Correct Version receive \n");
radhey04ec 0:7945527e6a18 323 //PRINT DATA ON LCD
radhey04ec 0:7945527e6a18 324 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 325 lcd.printf("VERSION = 1.34");
radhey04ec 0:7945527e6a18 326 lcd.printf("VERSION TEST OK");
radhey04ec 0:7945527e6a18 327 //GO FOR NEXT TEST
radhey04ec 0:7945527e6a18 328 NEXT = 1; //READY FOR NEXT TEST
radhey04ec 0:7945527e6a18 329 A.release();
radhey04ec 0:7945527e6a18 330 wait(2);
radhey04ec 0:7945527e6a18 331
radhey04ec 0:7945527e6a18 332
radhey04ec 0:7945527e6a18 333 }
radhey04ec 0:7945527e6a18 334 else
radhey04ec 0:7945527e6a18 335 {
radhey04ec 0:7945527e6a18 336 pc.printf("\n Wrong version \n");
radhey04ec 0:7945527e6a18 337 //ERROR - STOP TEST
radhey04ec 0:7945527e6a18 338 ERROR_FLAG = 1;
radhey04ec 0:7945527e6a18 339 error(1);
radhey04ec 0:7945527e6a18 340 NEXT = 0;
radhey04ec 0:7945527e6a18 341 }
radhey04ec 0:7945527e6a18 342
radhey04ec 0:7945527e6a18 343 j = 0;
radhey04ec 0:7945527e6a18 344 //Clear the buffer data to avoid mistakes
radhey04ec 0:7945527e6a18 345
radhey04ec 0:7945527e6a18 346 }
radhey04ec 0:7945527e6a18 347 if(NEXT == 1) //**************** RED LED TESTING *********************
radhey04ec 0:7945527e6a18 348 {
radhey04ec 0:7945527e6a18 349 NEXT = 0;
radhey04ec 0:7945527e6a18 350 lcd.cls();
radhey04ec 0:7945527e6a18 351 A.release();
radhey04ec 0:7945527e6a18 352 wait(1);
radhey04ec 0:7945527e6a18 353 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 354 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 355 lcd.printf("RED LED TEST ON");
radhey04ec 0:7945527e6a18 356 pc.printf("\n RED LED TESTING START");
radhey04ec 0:7945527e6a18 357 UT.putc('d'); // RED LED OF SLAVE BOARD ON
radhey04ec 0:7945527e6a18 358 A.release();
radhey04ec 0:7945527e6a18 359 wait(1);
radhey04ec 0:7945527e6a18 360 response(); //Read Response from Slave
radhey04ec 1:bdc3ebd4e52b 361 pc.printf("\n RED LED COMMAND RELEASE ");
radhey04ec 0:7945527e6a18 362 lcd.locate(0,1);
radhey04ec 1:bdc3ebd4e52b 363 {
radhey04ec 1:bdc3ebd4e52b 364 float LDR_AVG =0;
radhey04ec 1:bdc3ebd4e52b 365 float S = 0;
radhey04ec 1:bdc3ebd4e52b 366 int8_t z;
radhey04ec 1:bdc3ebd4e52b 367
radhey04ec 1:bdc3ebd4e52b 368 for(z = 0; z < 10; z++)
radhey04ec 1:bdc3ebd4e52b 369 {
radhey04ec 1:bdc3ebd4e52b 370
radhey04ec 1:bdc3ebd4e52b 371 LDR_VALUE = LDR.read();
radhey04ec 1:bdc3ebd4e52b 372 wait_ms(20);
radhey04ec 1:bdc3ebd4e52b 373 S = S + LDR_VALUE;
radhey04ec 1:bdc3ebd4e52b 374
radhey04ec 1:bdc3ebd4e52b 375 }
radhey04ec 1:bdc3ebd4e52b 376 LDR_AVG = S /10;
radhey04ec 1:bdc3ebd4e52b 377 LDR_VALUE = LDR_AVG;
radhey04ec 1:bdc3ebd4e52b 378 }
radhey04ec 0:7945527e6a18 379 lcd.printf(" ");
radhey04ec 1:bdc3ebd4e52b 380 lcd.printf("RED LED ON CMD");
radhey04ec 0:7945527e6a18 381 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 382 A.release();
radhey04ec 0:7945527e6a18 383 wait(1);
radhey04ec 0:7945527e6a18 384 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 385 lcd.printf(" ");
radhey04ec 0:7945527e6a18 386 lcd.printf("RED LED OFF");
radhey04ec 0:7945527e6a18 387 UT.putc('b');
radhey04ec 0:7945527e6a18 388 A.release();
radhey04ec 0:7945527e6a18 389 wait(1);
radhey04ec 0:7945527e6a18 390 response();
radhey04ec 0:7945527e6a18 391 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 392 pc.printf("RED LED TEST FINISH");
radhey04ec 1:bdc3ebd4e52b 393
radhey04ec 1:bdc3ebd4e52b 394 //result time
radhey04ec 1:bdc3ebd4e52b 395 if(LDR_VALUE > 0.650)
radhey04ec 1:bdc3ebd4e52b 396 {
radhey04ec 0:7945527e6a18 397 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 398 lcd.printf(" ");
radhey04ec 0:7945527e6a18 399 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 400 lcd.printf("RED LED TEST OK");
radhey04ec 0:7945527e6a18 401 NEXT = 1;
radhey04ec 1:bdc3ebd4e52b 402 pc.printf("\n RED LED DETECT SUCCESSFULLY");
radhey04ec 1:bdc3ebd4e52b 403
radhey04ec 1:bdc3ebd4e52b 404 //CLEAR LCD CONTENT
radhey04ec 0:7945527e6a18 405 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 406 lcd.printf(" ");
radhey04ec 0:7945527e6a18 407 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 408 lcd.printf(" ");
radhey04ec 0:7945527e6a18 409 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 410 lcd.printf(" ");
radhey04ec 1:bdc3ebd4e52b 411 LDR_VALUE = 0;
radhey04ec 0:7945527e6a18 412 }
radhey04ec 0:7945527e6a18 413 else
radhey04ec 0:7945527e6a18 414 {
radhey04ec 1:bdc3ebd4e52b 415 pc.printf("\n PROBLEM in LED DETECTION");
radhey04ec 1:bdc3ebd4e52b 416 NEXT = 0;
radhey04ec 1:bdc3ebd4e52b 417 ERROR_FLAG = 1;
radhey04ec 1:bdc3ebd4e52b 418 error(5);
radhey04ec 1:bdc3ebd4e52b 419
radhey04ec 0:7945527e6a18 420
radhey04ec 0:7945527e6a18 421 }
radhey04ec 1:bdc3ebd4e52b 422
radhey04ec 1:bdc3ebd4e52b 423
radhey04ec 0:7945527e6a18 424 }
radhey04ec 0:7945527e6a18 425 if(NEXT == 1)//**********************************CALIBRATION ON
radhey04ec 0:7945527e6a18 426 {
radhey04ec 0:7945527e6a18 427 NEXT =0;
radhey04ec 0:7945527e6a18 428 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 429 lcd.printf(" ");
radhey04ec 0:7945527e6a18 430 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 431 lcd.printf(" ");
radhey04ec 0:7945527e6a18 432 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 433 lcd.printf(" ");
radhey04ec 0:7945527e6a18 434 pc.printf("\n CALIBRATION ON ");
radhey04ec 0:7945527e6a18 435 lcd.printf("CALIBRATION ON");
radhey04ec 0:7945527e6a18 436 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 437 lcd.printf("PROCESSING");
radhey04ec 0:7945527e6a18 438 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 439 UT.putc('c');
radhey04ec 0:7945527e6a18 440 A.release();
radhey04ec 0:7945527e6a18 441 wait(3);
radhey04ec 0:7945527e6a18 442 UT.putc('s');
radhey04ec 0:7945527e6a18 443 A.release();
radhey04ec 0:7945527e6a18 444 wait(1);
radhey04ec 0:7945527e6a18 445 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 446 pc.printf("\n CALIBRATION COMPLETE");
radhey04ec 0:7945527e6a18 447 lcd.printf("DATA SAVE OK");
radhey04ec 0:7945527e6a18 448 NEXT = 1;
radhey04ec 0:7945527e6a18 449
radhey04ec 0:7945527e6a18 450 }
radhey04ec 0:7945527e6a18 451 if(NEXT ==1)//*****************************BATTERY VOLTAGE TEST
radhey04ec 0:7945527e6a18 452 {
radhey04ec 0:7945527e6a18 453 NEXT =0;
radhey04ec 0:7945527e6a18 454 ERROR_FLAG = 0;
radhey04ec 0:7945527e6a18 455 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 456 lcd.printf(" ");
radhey04ec 0:7945527e6a18 457 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 458 lcd.printf(" ");
radhey04ec 0:7945527e6a18 459 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 460 lcd.printf(" ");
radhey04ec 0:7945527e6a18 461 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 462 lcd.printf("Voltage test");
radhey04ec 0:7945527e6a18 463 pc.printf("\n VOLTAGE TEST BEGIN");
radhey04ec 0:7945527e6a18 464 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 465 UT.putc('A');
radhey04ec 0:7945527e6a18 466 A.release();
radhey04ec 0:7945527e6a18 467 wait(1);
radhey04ec 0:7945527e6a18 468 response();
radhey04ec 0:7945527e6a18 469 NEXT = 1;
radhey04ec 0:7945527e6a18 470
radhey04ec 0:7945527e6a18 471
radhey04ec 0:7945527e6a18 472
radhey04ec 0:7945527e6a18 473 }
radhey04ec 1:bdc3ebd4e52b 474 if(NEXT == 1)// ********************************* CURRENT TEST
radhey04ec 1:bdc3ebd4e52b 475 {
radhey04ec 1:bdc3ebd4e52b 476 lcd.locate(0,0);
radhey04ec 1:bdc3ebd4e52b 477 BUFFER_CLEAR();
radhey04ec 1:bdc3ebd4e52b 478 NEXT = 0;
radhey04ec 1:bdc3ebd4e52b 479 pc.printf("\n CURRENT TEST START");
radhey04ec 1:bdc3ebd4e52b 480 A.release();
radhey04ec 1:bdc3ebd4e52b 481 wait(1);
radhey04ec 1:bdc3ebd4e52b 482 CURRENT();
radhey04ec 1:bdc3ebd4e52b 483 lcd.locate(0,1);
radhey04ec 1:bdc3ebd4e52b 484 lcd.printf(" ");
radhey04ec 1:bdc3ebd4e52b 485 lcd.locate(0,2);
radhey04ec 1:bdc3ebd4e52b 486 lcd.printf(" ");
radhey04ec 1:bdc3ebd4e52b 487 lcd.locate(0,0);
radhey04ec 1:bdc3ebd4e52b 488 lcd.printf(" ");
radhey04ec 1:bdc3ebd4e52b 489 lcd.locate(0,1);
radhey04ec 1:bdc3ebd4e52b 490 lcd.printf("CURRENT = %f",current);
radhey04ec 1:bdc3ebd4e52b 491 if(current > 6.5)
radhey04ec 1:bdc3ebd4e52b 492 {
radhey04ec 1:bdc3ebd4e52b 493 error(2);
radhey04ec 1:bdc3ebd4e52b 494 NEXT = 0;
radhey04ec 1:bdc3ebd4e52b 495 ERROR_FLAG = 1;
radhey04ec 1:bdc3ebd4e52b 496 }
radhey04ec 1:bdc3ebd4e52b 497 else
radhey04ec 1:bdc3ebd4e52b 498 {
radhey04ec 1:bdc3ebd4e52b 499
radhey04ec 1:bdc3ebd4e52b 500 NEXT = 1;
radhey04ec 1:bdc3ebd4e52b 501 ERROR_FLAG = 0;
radhey04ec 1:bdc3ebd4e52b 502 }
radhey04ec 1:bdc3ebd4e52b 503
radhey04ec 1:bdc3ebd4e52b 504 }
radhey04ec 1:bdc3ebd4e52b 505
radhey04ec 0:7945527e6a18 506 //END OF TEST -- NO NEED TO CHECK NEXT FLAG
radhey04ec 0:7945527e6a18 507 UT.putc('Q');
radhey04ec 0:7945527e6a18 508 wait(1);
radhey04ec 0:7945527e6a18 509 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 510
radhey04ec 0:7945527e6a18 511 if(ERROR_FLAG == 0)
radhey04ec 0:7945527e6a18 512 {
radhey04ec 0:7945527e6a18 513 result();
radhey04ec 0:7945527e6a18 514 }
radhey04ec 0:7945527e6a18 515
radhey04ec 0:7945527e6a18 516 } //OUTER SIDE BEGIN
radhey04ec 0:7945527e6a18 517 TEST_FLAG = 0U;
radhey04ec 0:7945527e6a18 518 PROCESS_FLAG = 0U;
radhey04ec 0:7945527e6a18 519 GREEN_LED = 0U;
radhey04ec 0:7945527e6a18 520 RED_LED = 0U;
radhey04ec 0:7945527e6a18 521 NEXT = 0;
radhey04ec 0:7945527e6a18 522 ERROR_FLAG =0;
radhey04ec 0:7945527e6a18 523
radhey04ec 0:7945527e6a18 524 }
radhey04ec 0:7945527e6a18 525 void result()
radhey04ec 0:7945527e6a18 526 {
radhey04ec 0:7945527e6a18 527 {
radhey04ec 0:7945527e6a18 528 wait(3);
radhey04ec 0:7945527e6a18 529 lcd.cls();
radhey04ec 0:7945527e6a18 530 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 531 lcd.printf("TEST SUCCESSFUL OK");
radhey04ec 0:7945527e6a18 532 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 533 lcd.printf("BOARD TEST - PASS");
radhey04ec 0:7945527e6a18 534 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 535 lcd.printf("PLUG NEW BOARD");
radhey04ec 0:7945527e6a18 536 lcd.locate(0,3);
radhey04ec 0:7945527e6a18 537 lcd.printf("Total Test = %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 538 GREEN_LED =1;
radhey04ec 0:7945527e6a18 539 RED_LED =0;
radhey04ec 0:7945527e6a18 540 BLUE_LED =0;
radhey04ec 0:7945527e6a18 541 BUZZER = 1;
radhey04ec 0:7945527e6a18 542 wait(0.1);
radhey04ec 0:7945527e6a18 543 BUZZER =0;
radhey04ec 0:7945527e6a18 544 wait(3);
radhey04ec 0:7945527e6a18 545 }
radhey04ec 0:7945527e6a18 546
radhey04ec 0:7945527e6a18 547 //AT END OF PROCESS
radhey04ec 0:7945527e6a18 548 TEST_FLAG = 0U;
radhey04ec 0:7945527e6a18 549 PROCESS_FLAG = 0U;
radhey04ec 0:7945527e6a18 550 GREEN_LED = 1U;
radhey04ec 0:7945527e6a18 551 pc.printf("\n PCB AXV 001 TEST COMPLETED : TEST STATUS - PASS \n");
radhey04ec 0:7945527e6a18 552 pc.printf("\n ******************************END OF TEST************************************ \n");
radhey04ec 0:7945527e6a18 553 pc.printf("\n \n \n");
radhey04ec 0:7945527e6a18 554 pc.printf("\n PLUG NEW BOARD AND PRESS THE BUTTON");
radhey04ec 0:7945527e6a18 555 pc.printf("\n \n \n");
radhey04ec 0:7945527e6a18 556 wait(5);
radhey04ec 0:7945527e6a18 557
radhey04ec 0:7945527e6a18 558 }
radhey04ec 0:7945527e6a18 559
radhey04ec 0:7945527e6a18 560 void error(uint8_t error_number)
radhey04ec 0:7945527e6a18 561 {
radhey04ec 0:7945527e6a18 562 {
radhey04ec 0:7945527e6a18 563 RED_LED=1;
radhey04ec 0:7945527e6a18 564 GREEN_LED=0;
radhey04ec 0:7945527e6a18 565 BLUE_LED=0;
radhey04ec 0:7945527e6a18 566 BUZZER = 1;
radhey04ec 0:7945527e6a18 567 wait(1);
radhey04ec 0:7945527e6a18 568 BUZZER =0;
radhey04ec 0:7945527e6a18 569 lcd.cls();
radhey04ec 0:7945527e6a18 570 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 571 lcd.printf("Oops ..ERROR");
radhey04ec 0:7945527e6a18 572 pc.printf("\n Test Fail ");
radhey04ec 0:7945527e6a18 573 pc.printf("\n Error -- Contact to HOD");
radhey04ec 0:7945527e6a18 574 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 575 lcd.printf("PLUG NEW BOARD");
radhey04ec 0:7945527e6a18 576 lcd.locate(0,3);
radhey04ec 0:7945527e6a18 577 lcd.printf("Total Test = %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 578 if(error_number == 1)
radhey04ec 0:7945527e6a18 579 {
radhey04ec 0:7945527e6a18 580 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 581 lcd.printf("WRONG VERSION");
radhey04ec 0:7945527e6a18 582 pc.printf("\n ERROR CODE = 0x1");
radhey04ec 0:7945527e6a18 583 pc.printf("\n WRONG VERSION OF SOFTWARE , PLEASE CHECK");
radhey04ec 0:7945527e6a18 584 pc.printf("\n POSSIBLE SOLUTION \n");
radhey04ec 0:7945527e6a18 585 pc.printf("\n 1) REPROGRAM BOARD 2) CHECK SUPPLY VOLTAGE ");
radhey04ec 0:7945527e6a18 586 wait(3);
radhey04ec 0:7945527e6a18 587 }
radhey04ec 0:7945527e6a18 588 if(error_number == 2)
radhey04ec 0:7945527e6a18 589 {
radhey04ec 0:7945527e6a18 590 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 591 lcd.printf("OVER CURRENT ");
radhey04ec 0:7945527e6a18 592 pc.printf("\n ERROR CODE = 0X2");
radhey04ec 0:7945527e6a18 593 pc.printf("\n OVER CURRENT ERROR");
radhey04ec 0:7945527e6a18 594 pc.printf("\n POSSIBLE SOLUTION");
radhey04ec 0:7945527e6a18 595 pc.printf("\n TRY TO WASH BOARD AGAIN and RECHECK");
radhey04ec 0:7945527e6a18 596 wait(3);
radhey04ec 0:7945527e6a18 597 }
radhey04ec 1:bdc3ebd4e52b 598 if(error_number == 5)
radhey04ec 1:bdc3ebd4e52b 599 {
radhey04ec 1:bdc3ebd4e52b 600 pc.printf("\n ERROR NUMBER = 0X5");
radhey04ec 1:bdc3ebd4e52b 601 pc.printf("\n RED LED DETECTION FAIL");
radhey04ec 1:bdc3ebd4e52b 602 lcd.printf("LED TEST FAIL");
radhey04ec 1:bdc3ebd4e52b 603 A.release();
radhey04ec 1:bdc3ebd4e52b 604 wait(1);
radhey04ec 1:bdc3ebd4e52b 605 pc.printf("\n POSSIBLE SOLUTION");
radhey04ec 1:bdc3ebd4e52b 606 pc.printf("\n 1) CHECK LED MANUALLY - IF IT IS IN ON STATE PLEASE ADJUST SENSOR POSITION ");
radhey04ec 1:bdc3ebd4e52b 607 pc.printf("\n Contact to R&D DEPT. for Hardare Amendement");
radhey04ec 1:bdc3ebd4e52b 608 pc.printf("\n 2) If LED is not working state - check polarity");
radhey04ec 1:bdc3ebd4e52b 609 pc.printf("\n contact to HOD");
radhey04ec 1:bdc3ebd4e52b 610
radhey04ec 1:bdc3ebd4e52b 611 }
radhey04ec 0:7945527e6a18 612
radhey04ec 0:7945527e6a18 613 }
radhey04ec 0:7945527e6a18 614
radhey04ec 0:7945527e6a18 615 //AT END OF PROCESS
radhey04ec 0:7945527e6a18 616 TEST_FLAG = 0U;
radhey04ec 0:7945527e6a18 617 PROCESS_FLAG = 0U;
radhey04ec 0:7945527e6a18 618 RED_LED =1;
radhey04ec 0:7945527e6a18 619 BUZZER = 1;
radhey04ec 0:7945527e6a18 620 NEXT = 0;
radhey04ec 0:7945527e6a18 621 //ERROR_FLAG =0;
radhey04ec 0:7945527e6a18 622 wait(3);
radhey04ec 0:7945527e6a18 623 BUZZER =0;
radhey04ec 0:7945527e6a18 624 pc.printf("\n *******************ERROR DESCRIPTION END **************************");
radhey04ec 0:7945527e6a18 625 pc.printf("\n ***************************END OF TEST ****************************");
radhey04ec 0:7945527e6a18 626 }
radhey04ec 0:7945527e6a18 627
radhey04ec 0:7945527e6a18 628 void WELCOME_SCREEN()
radhey04ec 0:7945527e6a18 629 {
radhey04ec 0:7945527e6a18 630 pc.printf("\n");
radhey04ec 0:7945527e6a18 631 pc.printf("AXV GOLBAL VALVE TESTER -- FOLLOW THE STEPS \n");
radhey04ec 0:7945527e6a18 632
radhey04ec 0:7945527e6a18 633 RED_LED = 1;
radhey04ec 0:7945527e6a18 634 GREEN_LED = 1;
radhey04ec 0:7945527e6a18 635 BLUE_LED =1;
radhey04ec 0:7945527e6a18 636 BUZZER = 1;
radhey04ec 0:7945527e6a18 637 wait(1);
radhey04ec 0:7945527e6a18 638 BUZZER = 0;
radhey04ec 0:7945527e6a18 639
radhey04ec 0:7945527e6a18 640
radhey04ec 0:7945527e6a18 641 //WELCOME SCREEN DATA
radhey04ec 0:7945527e6a18 642 lcd.cls(); //clear the screen first
radhey04ec 0:7945527e6a18 643 lcd.printf(" Welcome !!!");
radhey04ec 0:7945527e6a18 644 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 645 lcd.printf("GLOBAL V- TESTER");
radhey04ec 0:7945527e6a18 646 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 647 lcd.printf("POWERED BY : KEPL ");
radhey04ec 0:7945527e6a18 648 lcd.locate(0,3);
radhey04ec 0:7945527e6a18 649 lcd.printf("R_AND_D DEPARTMENT");
radhey04ec 0:7945527e6a18 650 wait(5);
radhey04ec 0:7945527e6a18 651 lcd.cls();
radhey04ec 0:7945527e6a18 652 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 653 lcd.printf("Loading...");
radhey04ec 0:7945527e6a18 654 lcd.locate(11,0);
radhey04ec 0:7945527e6a18 655 pc.printf("\n DATA LOADING .....");
radhey04ec 0:7945527e6a18 656 pc.printf("\n Veryfying....");
radhey04ec 0:7945527e6a18 657 wait_ms(500);
radhey04ec 0:7945527e6a18 658 lcd.printf(".");
radhey04ec 0:7945527e6a18 659 lcd.locate(12,0);
radhey04ec 0:7945527e6a18 660 wait_ms(500);
radhey04ec 0:7945527e6a18 661 lcd.printf("...");
radhey04ec 0:7945527e6a18 662 wait_ms(1000);
radhey04ec 0:7945527e6a18 663 lcd.locate(13,0);
radhey04ec 0:7945527e6a18 664 lcd.printf("..");
radhey04ec 0:7945527e6a18 665 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 666 lcd.printf("Veryfied.........");
radhey04ec 0:7945527e6a18 667 wait_ms(3000);
radhey04ec 0:7945527e6a18 668 pc.printf("\n LCD COMMUNICATION Successful \n");
radhey04ec 0:7945527e6a18 669 lcd.cls();
radhey04ec 0:7945527e6a18 670 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 671 lcd.printf("Done !!!!");
radhey04ec 0:7945527e6a18 672 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 673 lcd.printf("TEST MODE ON");
radhey04ec 0:7945527e6a18 674 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 675 lcd.printf("COUNT = 0");
radhey04ec 0:7945527e6a18 676 wait_ms(5000);
radhey04ec 0:7945527e6a18 677 lcd.cls();
radhey04ec 0:7945527e6a18 678 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 679 BLUE_LED = 1;
radhey04ec 0:7945527e6a18 680 BUZZER = 1;
radhey04ec 0:7945527e6a18 681 wait_ms(250);
radhey04ec 0:7945527e6a18 682 BUZZER = 0;
radhey04ec 0:7945527e6a18 683 pc.printf("\n SOFTWARE CHECKED & READY TO USE \n");
radhey04ec 0:7945527e6a18 684 pc.printf("\n ESD PROTECTION REQUIRE");
radhey04ec 0:7945527e6a18 685 pc.printf("\n KEEP YOUR EYES ON TERMINAL OR ON LCD");
radhey04ec 0:7945527e6a18 686 pc.printf("\n LED VISUAL AND BUZZER SOUND INDICATION HELPS YOU !!!");
radhey04ec 0:7945527e6a18 687 lcd.printf("AXV -T");
radhey04ec 0:7945527e6a18 688 lcd.locate(10,0);
radhey04ec 0:7945527e6a18 689 lcd.printf("Count %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 690
radhey04ec 0:7945527e6a18 691 }
radhey04ec 0:7945527e6a18 692
radhey04ec 0:7945527e6a18 693 void NEW_TEST_UPDATE_LCD()
radhey04ec 0:7945527e6a18 694 {
radhey04ec 0:7945527e6a18 695 GREEN_LED = 1;
radhey04ec 0:7945527e6a18 696 BLUE_LED = 1;
radhey04ec 0:7945527e6a18 697 lcd.cls();
radhey04ec 0:7945527e6a18 698 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 699 lcd.printf("TESTING ON...");
radhey04ec 0:7945527e6a18 700 pc.printf("\n \n \n");
radhey04ec 0:7945527e6a18 701 pc.printf("\n NEW TEST START");
radhey04ec 0:7945527e6a18 702 wait(8); //8 SECOND
radhey04ec 0:7945527e6a18 703 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 704 lcd.printf("BOARD SCANING..");
radhey04ec 0:7945527e6a18 705 pc.printf("\n BOARD SCANNING...");
radhey04ec 0:7945527e6a18 706 wait(8);
radhey04ec 0:7945527e6a18 707 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 708 lcd.printf("COMMUNICATING...");
radhey04ec 0:7945527e6a18 709 pc.printf("\n COMMUNICATION ESTABLISHMENT \n");
radhey04ec 0:7945527e6a18 710 wait(5);
radhey04ec 0:7945527e6a18 711 lcd.printf("READY FOR TEST");
radhey04ec 0:7945527e6a18 712 wait(5);
radhey04ec 0:7945527e6a18 713 lcd.cls();
radhey04ec 0:7945527e6a18 714 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 715 lcd.printf("TEST MODE N 0%u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 716 pc.printf("TEST MODE ON - COUNT = %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 717 A.release();
radhey04ec 0:7945527e6a18 718 wait(0.5);
radhey04ec 0:7945527e6a18 719
radhey04ec 0:7945527e6a18 720 }
radhey04ec 0:7945527e6a18 721
radhey04ec 0:7945527e6a18 722 /*Below Function is part of ISR ;so do not write big code inside it
radhey04ec 0:7945527e6a18 723 If possible than only set and reset flag only
radhey04ec 0:7945527e6a18 724 Because while servicing Interrupt OS can not schedule or switch other thread or Task
radhey04ec 0:7945527e6a18 725 In future during updation of version please consider RTOS Management Rule
radhey04ec 0:7945527e6a18 726 or contact Reserach & development team : JAYDEEP SHAH
radhey04ec 0:7945527e6a18 727 */
radhey04ec 0:7945527e6a18 728
radhey04ec 0:7945527e6a18 729 void TEST_PROCESS() //This Function is connected with ISR Of Push_button
radhey04ec 0:7945527e6a18 730 {
radhey04ec 0:7945527e6a18 731 if(TEST_FLAG == 0U && PROCESS_FLAG == 0U)
radhey04ec 0:7945527e6a18 732 {
radhey04ec 0:7945527e6a18 733 TEST_FLAG = 1U;
radhey04ec 0:7945527e6a18 734 }
radhey04ec 0:7945527e6a18 735 else
radhey04ec 0:7945527e6a18 736 {
radhey04ec 0:7945527e6a18 737 TEST_FLAG = 0U;
radhey04ec 0:7945527e6a18 738
radhey04ec 0:7945527e6a18 739 }
radhey04ec 0:7945527e6a18 740
radhey04ec 0:7945527e6a18 741 }
radhey04ec 0:7945527e6a18 742 void CURRENT()
radhey04ec 0:7945527e6a18 743 {
radhey04ec 0:7945527e6a18 744 for(int i =0;i <10 ; i++) //Array to make result smoother
radhey04ec 0:7945527e6a18 745 {
radhey04ec 0:7945527e6a18 746 AARAY[i] = ANG.read(); //Read the data
radhey04ec 0:7945527e6a18 747 ThisThread::sleep_for(20); //Thread sleep for make ADC ready for next result
radhey04ec 0:7945527e6a18 748 SUM = SUM + AARAY[i]; //Store result
radhey04ec 0:7945527e6a18 749 }
radhey04ec 0:7945527e6a18 750 float value = (SUM /10); //Finding Average value
radhey04ec 0:7945527e6a18 751
radhey04ec 0:7945527e6a18 752 current = (((((((value)) * 3.3)-0.28)/200)/0.6)*1000); //Finding current
radhey04ec 0:7945527e6a18 753 current = current + 2.5; // 2.5 is offset (when current is < 50 mA)
radhey04ec 0:7945527e6a18 754
radhey04ec 0:7945527e6a18 755 //pc.printf("\n Current (mA) = %f",current); //Print data on Serial console -- I used CoolTerm
radhey04ec 0:7945527e6a18 756
radhey04ec 0:7945527e6a18 757 SUM = 0; //At the end sum must be zero
radhey04ec 0:7945527e6a18 758 //A.release();
radhey04ec 0:7945527e6a18 759
radhey04ec 0:7945527e6a18 760 }
radhey04ec 0:7945527e6a18 761
radhey04ec 0:7945527e6a18 762 void BUFFER_CLEAR()
radhey04ec 0:7945527e6a18 763 {
radhey04ec 0:7945527e6a18 764 RxInterrupt(); // To clear serial buffer
radhey04ec 0:7945527e6a18 765 i = 0U;
radhey04ec 0:7945527e6a18 766 bufferReadingIndex = 0U;
radhey04ec 0:7945527e6a18 767 for(int k =0; k<50 ; k++) // ****************CLEAR 50 BYTES BUFFER
radhey04ec 0:7945527e6a18 768 {
radhey04ec 0:7945527e6a18 769 rxBuffer[k] = ' ';
radhey04ec 0:7945527e6a18 770 }
radhey04ec 0:7945527e6a18 771 }