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 03:06:50 2020 +0000
Revision:
0:7945527e6a18
Child:
1:bdc3ebd4e52b
80% WORK ON AXV001 TESTER COMPLETED ; COMMUNICATION AND SUCCESSFUL; RED LED DETECTION REMAINING;

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 0:7945527e6a18 171 int main()
radhey04ec 0:7945527e6a18 172 {
radhey04ec 0:7945527e6a18 173
radhey04ec 0:7945527e6a18 174 UT.baud(57600); //BAUD RATE SETTING
radhey04ec 0:7945527e6a18 175 UT.format(8,Serial::None,1); //FORMAT OF UART COMMUNICATION
radhey04ec 0:7945527e6a18 176
radhey04ec 0:7945527e6a18 177 //INTERRUPT ATTACHMENT WHEN RECEIVE DATA --UART INTERRUPT
radhey04ec 0:7945527e6a18 178 UT.attach(&RxInterrupt,Serial::RxIrq);
radhey04ec 0:7945527e6a18 179
radhey04ec 0:7945527e6a18 180 //PUSH BUTTON INTERRUPT FUNCTION -- PUSH BUTTON INTERRUPT
radhey04ec 0:7945527e6a18 181 swt.rise(&TEST_PROCESS); //THIS FUNCTION Call when push button press
radhey04ec 0:7945527e6a18 182
radhey04ec 0:7945527e6a18 183 pc.printf("\n STM POWER ON -- DATA INITIALIZATION \n");
radhey04ec 0:7945527e6a18 184 pc.printf("\n PROGRAM CREATED BY : R_AND_D DEPT of KEPL \n");
radhey04ec 0:7945527e6a18 185 pc.printf("\n Program Version 1.0 \n");
radhey04ec 0:7945527e6a18 186 pc.printf("\n Any changes of the program lead toward Board OS Crash or bugs");
radhey04ec 0:7945527e6a18 187 pc.printf("\n Permission require before any Hardware / software changes");
radhey04ec 0:7945527e6a18 188 pc.printf("\n TRY TO ACCESS main.C CODE......INITIALIZATIO OF RTOS START.....");
radhey04ec 0:7945527e6a18 189 pc.printf("\n Do not press any Button");
radhey04ec 0:7945527e6a18 190
radhey04ec 0:7945527e6a18 191
radhey04ec 0:7945527e6a18 192 //INITIAL ALL LED OFF
radhey04ec 0:7945527e6a18 193 pc.printf("\n MAKE ALL LEDS and BUZZER OFF \n");
radhey04ec 0:7945527e6a18 194 RED_LED = 0;
radhey04ec 0:7945527e6a18 195 GREEN_LED = 0;
radhey04ec 0:7945527e6a18 196 BLUE_LED = 0;
radhey04ec 0:7945527e6a18 197 BUZZER = 0;
radhey04ec 0:7945527e6a18 198
radhey04ec 0:7945527e6a18 199 WELCOME_SCREEN(); //TO INITIALIZE DATA
radhey04ec 0:7945527e6a18 200
radhey04ec 0:7945527e6a18 201 pc.printf("\n Good Luck !!!!");
radhey04ec 0:7945527e6a18 202 pc.printf("\n CURRENT MEASUREMENT UNIT TURNING ON");
radhey04ec 0:7945527e6a18 203
radhey04ec 0:7945527e6a18 204 T1.start(CURRENT_MEASUREMENT);
radhey04ec 0:7945527e6a18 205 T2.start(LCD_REFRESH);
radhey04ec 0:7945527e6a18 206
radhey04ec 0:7945527e6a18 207 pc.printf("\n All Thread create succesffully");
radhey04ec 0:7945527e6a18 208 wait_ms(500);
radhey04ec 0:7945527e6a18 209 while(true)
radhey04ec 0:7945527e6a18 210 {
radhey04ec 0:7945527e6a18 211 BLUE_LED = 0;
radhey04ec 0:7945527e6a18 212 START_NEW_TEST(); //This function only work if FLAG SET
radhey04ec 0:7945527e6a18 213 wait_ms(500);
radhey04ec 0:7945527e6a18 214
radhey04ec 0:7945527e6a18 215 BLUE_LED = 1;
radhey04ec 0:7945527e6a18 216
radhey04ec 0:7945527e6a18 217 }
radhey04ec 0:7945527e6a18 218
radhey04ec 0:7945527e6a18 219 }
radhey04ec 0:7945527e6a18 220
radhey04ec 0:7945527e6a18 221 void RxInterrupt() //if Rx buffer have data --- Interrupt call
radhey04ec 0:7945527e6a18 222 {
radhey04ec 0:7945527e6a18 223 //Because of Interrupt -- Ideally no CONTEXT SWITCH
radhey04ec 0:7945527e6a18 224 if(UT.readable()) //IF data available
radhey04ec 0:7945527e6a18 225 {
radhey04ec 0:7945527e6a18 226 rxBuffer[bufferReadingIndex++] = UT.getc(); // read and store into Buffer
radhey04ec 0:7945527e6a18 227 if(bufferReadingIndex >= BUFFER_SIZE) // If limit cross
radhey04ec 0:7945527e6a18 228 {
radhey04ec 0:7945527e6a18 229 bufferReadingIndex =0; // RESET CONTER
radhey04ec 0:7945527e6a18 230 }
radhey04ec 0:7945527e6a18 231 }
radhey04ec 0:7945527e6a18 232 }
radhey04ec 0:7945527e6a18 233
radhey04ec 0:7945527e6a18 234 void response() //FUNCTION TO READ DATA
radhey04ec 0:7945527e6a18 235 {
radhey04ec 0:7945527e6a18 236 char rxByte;
radhey04ec 0:7945527e6a18 237 printf("\n");
radhey04ec 0:7945527e6a18 238
radhey04ec 0:7945527e6a18 239 //NEED TO STOP CONTEXT SWITCH
radhey04ec 0:7945527e6a18 240 while(i != bufferReadingIndex) //READ WHILE COMPLETE DATA NOT RECEIVED
radhey04ec 0:7945527e6a18 241 {
radhey04ec 0:7945527e6a18 242 rxByte = rxBuffer[i]; //READ DATA ONE BY ONE CHARACTER
radhey04ec 0:7945527e6a18 243 pc.putc(rxByte); // SEND ON TERMINAL
radhey04ec 0:7945527e6a18 244 i++; //COUNTER INCREMEN
radhey04ec 0:7945527e6a18 245
radhey04ec 0:7945527e6a18 246 if(i >= BUFFER_SIZE) //IF LIMIT CROSS
radhey04ec 0:7945527e6a18 247 {
radhey04ec 0:7945527e6a18 248 i = 0; //RESET COUNTER
radhey04ec 0:7945527e6a18 249 }
radhey04ec 0:7945527e6a18 250 }
radhey04ec 0:7945527e6a18 251
radhey04ec 0:7945527e6a18 252 //USE THREAD YIELD FOR UPDATE OTHER THREADS
radhey04ec 0:7945527e6a18 253
radhey04ec 0:7945527e6a18 254
radhey04ec 0:7945527e6a18 255
radhey04ec 0:7945527e6a18 256 LCD_FLAG = 0; //RESET -- VERSION READ COMPLETED
radhey04ec 0:7945527e6a18 257 //THREA YIELD
radhey04ec 0:7945527e6a18 258
radhey04ec 0:7945527e6a18 259
radhey04ec 0:7945527e6a18 260 }
radhey04ec 0:7945527e6a18 261
radhey04ec 0:7945527e6a18 262 void START_NEW_TEST(void)
radhey04ec 0:7945527e6a18 263 {
radhey04ec 0:7945527e6a18 264 if(TEST_FLAG == 1U && PROCESS_FLAG == 0U)
radhey04ec 0:7945527e6a18 265 {
radhey04ec 0:7945527e6a18 266 //FLAG MUST BE ZERO
radhey04ec 0:7945527e6a18 267 NEXT = 0;
radhey04ec 0:7945527e6a18 268 ERROR_FLAG = 0;
radhey04ec 0:7945527e6a18 269 RED_LED =0;
radhey04ec 0:7945527e6a18 270 GREEN_LED =1;
radhey04ec 0:7945527e6a18 271 PROCESS_FLAG = 1U;
radhey04ec 0:7945527e6a18 272 //turn test flag on
radhey04ec 0:7945527e6a18 273 TEST_FLAG =1U;
radhey04ec 0:7945527e6a18 274 //COUNTER++
radhey04ec 0:7945527e6a18 275 PCB_COUNTER++;
radhey04ec 0:7945527e6a18 276 //NEED TO WAIT 25 ms
radhey04ec 0:7945527e6a18 277 pc.printf("\n \n \n");
radhey04ec 0:7945527e6a18 278 pc.printf("***********************************************************");
radhey04ec 0:7945527e6a18 279 pc.printf("AXV 001 PCB NUMBER = %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 280 NEW_TEST_UPDATE_LCD(); //THIS FUNCTION IS ONLY FOR DELAY
radhey04ec 0:7945527e6a18 281
radhey04ec 0:7945527e6a18 282
radhey04ec 0:7945527e6a18 283 A.release();
radhey04ec 0:7945527e6a18 284 //last fucntion to reset flag and display test result
radhey04ec 0:7945527e6a18 285 wait(0.150);
radhey04ec 0:7945527e6a18 286 //CLEAR THE BUFFER BEFORE UART COMM
radhey04ec 0:7945527e6a18 287 //***************TEST - 1 ENTER INTEST MODE AND VERSION READ------------------------------TEST1
radhey04ec 0:7945527e6a18 288 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 289 UT.putc('T'); //ENTER IN TEST MODE -- SLAVE BOARD ENTER INTO TEST MODE
radhey04ec 0:7945527e6a18 290 A.release();
radhey04ec 0:7945527e6a18 291 ThisThread::sleep_for(1000);
radhey04ec 0:7945527e6a18 292 response();
radhey04ec 0:7945527e6a18 293 wait(0.10);
radhey04ec 0:7945527e6a18 294 //FETCHING VERSION NUMBER 01.34
radhey04ec 0:7945527e6a18 295 lcd.cls();
radhey04ec 0:7945527e6a18 296 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 297 lcd.printf("VERSION TEST ON");
radhey04ec 0:7945527e6a18 298 {
radhey04ec 0:7945527e6a18 299 uint8_t j=0;
radhey04ec 0:7945527e6a18 300 char temp_buf[6];
radhey04ec 0:7945527e6a18 301 char ver[] = "01.34";
radhey04ec 0:7945527e6a18 302 pc.puts("\n FETCHING VERSION FROM IC: ");
radhey04ec 0:7945527e6a18 303 for(j=13;j<18;j++)
radhey04ec 0:7945527e6a18 304 {
radhey04ec 0:7945527e6a18 305 pc.putc(rxBuffer[j]);
radhey04ec 0:7945527e6a18 306 temp_buf[j-13] = rxBuffer[j];
radhey04ec 0:7945527e6a18 307 }
radhey04ec 0:7945527e6a18 308 temp_buf[5] = '\n';
radhey04ec 0:7945527e6a18 309 float value = atof(temp_buf);
radhey04ec 0:7945527e6a18 310 pc.printf("\n VERSION VALUE IS %f",value);
radhey04ec 0:7945527e6a18 311 if(value == 1.340000f)
radhey04ec 0:7945527e6a18 312 {
radhey04ec 0:7945527e6a18 313 pc.printf("\n Correct Version receive \n");
radhey04ec 0:7945527e6a18 314 //PRINT DATA ON LCD
radhey04ec 0:7945527e6a18 315 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 316 lcd.printf("VERSION = 1.34");
radhey04ec 0:7945527e6a18 317 lcd.printf("VERSION TEST OK");
radhey04ec 0:7945527e6a18 318 //GO FOR NEXT TEST
radhey04ec 0:7945527e6a18 319 NEXT = 1; //READY FOR NEXT TEST
radhey04ec 0:7945527e6a18 320 A.release();
radhey04ec 0:7945527e6a18 321 wait(2);
radhey04ec 0:7945527e6a18 322
radhey04ec 0:7945527e6a18 323
radhey04ec 0:7945527e6a18 324 }
radhey04ec 0:7945527e6a18 325 else
radhey04ec 0:7945527e6a18 326 {
radhey04ec 0:7945527e6a18 327 pc.printf("\n Wrong version \n");
radhey04ec 0:7945527e6a18 328 //ERROR - STOP TEST
radhey04ec 0:7945527e6a18 329 ERROR_FLAG = 1;
radhey04ec 0:7945527e6a18 330 error(1);
radhey04ec 0:7945527e6a18 331 NEXT = 0;
radhey04ec 0:7945527e6a18 332 }
radhey04ec 0:7945527e6a18 333
radhey04ec 0:7945527e6a18 334 j = 0;
radhey04ec 0:7945527e6a18 335 //Clear the buffer data to avoid mistakes
radhey04ec 0:7945527e6a18 336
radhey04ec 0:7945527e6a18 337 }
radhey04ec 0:7945527e6a18 338 if(NEXT == 1) //**************** RED LED TESTING *********************
radhey04ec 0:7945527e6a18 339 {
radhey04ec 0:7945527e6a18 340 NEXT = 0;
radhey04ec 0:7945527e6a18 341 lcd.cls();
radhey04ec 0:7945527e6a18 342 A.release();
radhey04ec 0:7945527e6a18 343 wait(1);
radhey04ec 0:7945527e6a18 344 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 345 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 346 lcd.printf("RED LED TEST ON");
radhey04ec 0:7945527e6a18 347 pc.printf("\n RED LED TESTING START");
radhey04ec 0:7945527e6a18 348 UT.putc('d'); // RED LED OF SLAVE BOARD ON
radhey04ec 0:7945527e6a18 349 A.release();
radhey04ec 0:7945527e6a18 350 wait(1);
radhey04ec 0:7945527e6a18 351 response(); //Read Response from Slave
radhey04ec 0:7945527e6a18 352 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 353 lcd.printf(" ");
radhey04ec 0:7945527e6a18 354 lcd.printf("RED LED ON ***");
radhey04ec 0:7945527e6a18 355 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 356 A.release();
radhey04ec 0:7945527e6a18 357 wait(1);
radhey04ec 0:7945527e6a18 358 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 359 lcd.printf(" ");
radhey04ec 0:7945527e6a18 360 lcd.printf("RED LED OFF");
radhey04ec 0:7945527e6a18 361 UT.putc('b');
radhey04ec 0:7945527e6a18 362 A.release();
radhey04ec 0:7945527e6a18 363 wait(1);
radhey04ec 0:7945527e6a18 364 response();
radhey04ec 0:7945527e6a18 365 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 366 pc.printf("RED LED TEST FINISH");
radhey04ec 0:7945527e6a18 367 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 368 lcd.printf(" ");
radhey04ec 0:7945527e6a18 369 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 370 lcd.printf("RED LED TEST OK");
radhey04ec 0:7945527e6a18 371 NEXT = 1;
radhey04ec 0:7945527e6a18 372 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 373 lcd.printf(" ");
radhey04ec 0:7945527e6a18 374 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 375 lcd.printf(" ");
radhey04ec 0:7945527e6a18 376 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 377 lcd.printf(" ");
radhey04ec 0:7945527e6a18 378 }
radhey04ec 0:7945527e6a18 379 if(NEXT == 1)// ********************************* CURRENT TEST
radhey04ec 0:7945527e6a18 380 {
radhey04ec 0:7945527e6a18 381 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 382 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 383 NEXT = 0;
radhey04ec 0:7945527e6a18 384 pc.printf("\n CURRENT TEST START");
radhey04ec 0:7945527e6a18 385 A.release();
radhey04ec 0:7945527e6a18 386 wait(1);
radhey04ec 0:7945527e6a18 387 CURRENT();
radhey04ec 0:7945527e6a18 388 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 389 lcd.printf(" ");
radhey04ec 0:7945527e6a18 390 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 391 lcd.printf(" ");
radhey04ec 0:7945527e6a18 392 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 393 lcd.printf(" ");
radhey04ec 0:7945527e6a18 394 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 395 lcd.printf("CURRENT = %f",current);
radhey04ec 0:7945527e6a18 396 if(current > 6.5)
radhey04ec 0:7945527e6a18 397 {
radhey04ec 0:7945527e6a18 398 error(2);
radhey04ec 0:7945527e6a18 399 NEXT = 0;
radhey04ec 0:7945527e6a18 400 ERROR_FLAG = 1;
radhey04ec 0:7945527e6a18 401 }
radhey04ec 0:7945527e6a18 402 else
radhey04ec 0:7945527e6a18 403 {
radhey04ec 0:7945527e6a18 404
radhey04ec 0:7945527e6a18 405 NEXT = 1;
radhey04ec 0:7945527e6a18 406 ERROR_FLAG = 0;
radhey04ec 0:7945527e6a18 407 }
radhey04ec 0:7945527e6a18 408
radhey04ec 0:7945527e6a18 409 }
radhey04ec 0:7945527e6a18 410 if(NEXT == 1)//**********************************CALIBRATION ON
radhey04ec 0:7945527e6a18 411 {
radhey04ec 0:7945527e6a18 412 NEXT =0;
radhey04ec 0:7945527e6a18 413 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 414 lcd.printf(" ");
radhey04ec 0:7945527e6a18 415 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 416 lcd.printf(" ");
radhey04ec 0:7945527e6a18 417 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 418 lcd.printf(" ");
radhey04ec 0:7945527e6a18 419 pc.printf("\n CALIBRATION ON ");
radhey04ec 0:7945527e6a18 420 lcd.printf("CALIBRATION ON");
radhey04ec 0:7945527e6a18 421 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 422 lcd.printf("PROCESSING");
radhey04ec 0:7945527e6a18 423 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 424 UT.putc('c');
radhey04ec 0:7945527e6a18 425 A.release();
radhey04ec 0:7945527e6a18 426 wait(3);
radhey04ec 0:7945527e6a18 427 UT.putc('s');
radhey04ec 0:7945527e6a18 428 A.release();
radhey04ec 0:7945527e6a18 429 wait(1);
radhey04ec 0:7945527e6a18 430 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 431 pc.printf("\n CALIBRATION COMPLETE");
radhey04ec 0:7945527e6a18 432 lcd.printf("DATA SAVE OK");
radhey04ec 0:7945527e6a18 433 NEXT = 1;
radhey04ec 0:7945527e6a18 434
radhey04ec 0:7945527e6a18 435 }
radhey04ec 0:7945527e6a18 436 if(NEXT ==1)//*****************************BATTERY VOLTAGE TEST
radhey04ec 0:7945527e6a18 437 {
radhey04ec 0:7945527e6a18 438 NEXT =0;
radhey04ec 0:7945527e6a18 439 ERROR_FLAG = 0;
radhey04ec 0:7945527e6a18 440 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 441 lcd.printf(" ");
radhey04ec 0:7945527e6a18 442 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 443 lcd.printf(" ");
radhey04ec 0:7945527e6a18 444 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 445 lcd.printf(" ");
radhey04ec 0:7945527e6a18 446 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 447 lcd.printf("Voltage test");
radhey04ec 0:7945527e6a18 448 pc.printf("\n VOLTAGE TEST BEGIN");
radhey04ec 0:7945527e6a18 449 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 450 UT.putc('A');
radhey04ec 0:7945527e6a18 451 A.release();
radhey04ec 0:7945527e6a18 452 wait(1);
radhey04ec 0:7945527e6a18 453 response();
radhey04ec 0:7945527e6a18 454 NEXT = 1;
radhey04ec 0:7945527e6a18 455
radhey04ec 0:7945527e6a18 456
radhey04ec 0:7945527e6a18 457
radhey04ec 0:7945527e6a18 458 }
radhey04ec 0:7945527e6a18 459 //END OF TEST -- NO NEED TO CHECK NEXT FLAG
radhey04ec 0:7945527e6a18 460 UT.putc('Q');
radhey04ec 0:7945527e6a18 461 wait(1);
radhey04ec 0:7945527e6a18 462 BUFFER_CLEAR();
radhey04ec 0:7945527e6a18 463
radhey04ec 0:7945527e6a18 464 if(ERROR_FLAG == 0)
radhey04ec 0:7945527e6a18 465 {
radhey04ec 0:7945527e6a18 466 result();
radhey04ec 0:7945527e6a18 467 }
radhey04ec 0:7945527e6a18 468
radhey04ec 0:7945527e6a18 469 } //OUTER SIDE BEGIN
radhey04ec 0:7945527e6a18 470 TEST_FLAG = 0U;
radhey04ec 0:7945527e6a18 471 PROCESS_FLAG = 0U;
radhey04ec 0:7945527e6a18 472 GREEN_LED = 0U;
radhey04ec 0:7945527e6a18 473 RED_LED = 0U;
radhey04ec 0:7945527e6a18 474 NEXT = 0;
radhey04ec 0:7945527e6a18 475 ERROR_FLAG =0;
radhey04ec 0:7945527e6a18 476
radhey04ec 0:7945527e6a18 477 }
radhey04ec 0:7945527e6a18 478 void result()
radhey04ec 0:7945527e6a18 479 {
radhey04ec 0:7945527e6a18 480 {
radhey04ec 0:7945527e6a18 481 wait(3);
radhey04ec 0:7945527e6a18 482 lcd.cls();
radhey04ec 0:7945527e6a18 483 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 484 lcd.printf("TEST SUCCESSFUL OK");
radhey04ec 0:7945527e6a18 485 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 486 lcd.printf("BOARD TEST - PASS");
radhey04ec 0:7945527e6a18 487 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 488 lcd.printf("PLUG NEW BOARD");
radhey04ec 0:7945527e6a18 489 lcd.locate(0,3);
radhey04ec 0:7945527e6a18 490 lcd.printf("Total Test = %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 491 GREEN_LED =1;
radhey04ec 0:7945527e6a18 492 RED_LED =0;
radhey04ec 0:7945527e6a18 493 BLUE_LED =0;
radhey04ec 0:7945527e6a18 494 BUZZER = 1;
radhey04ec 0:7945527e6a18 495 wait(0.1);
radhey04ec 0:7945527e6a18 496 BUZZER =0;
radhey04ec 0:7945527e6a18 497 wait(3);
radhey04ec 0:7945527e6a18 498 }
radhey04ec 0:7945527e6a18 499
radhey04ec 0:7945527e6a18 500 //AT END OF PROCESS
radhey04ec 0:7945527e6a18 501 TEST_FLAG = 0U;
radhey04ec 0:7945527e6a18 502 PROCESS_FLAG = 0U;
radhey04ec 0:7945527e6a18 503 GREEN_LED = 1U;
radhey04ec 0:7945527e6a18 504 pc.printf("\n PCB AXV 001 TEST COMPLETED : TEST STATUS - PASS \n");
radhey04ec 0:7945527e6a18 505 pc.printf("\n ******************************END OF TEST************************************ \n");
radhey04ec 0:7945527e6a18 506 pc.printf("\n \n \n");
radhey04ec 0:7945527e6a18 507 pc.printf("\n PLUG NEW BOARD AND PRESS THE BUTTON");
radhey04ec 0:7945527e6a18 508 pc.printf("\n \n \n");
radhey04ec 0:7945527e6a18 509 wait(5);
radhey04ec 0:7945527e6a18 510
radhey04ec 0:7945527e6a18 511 }
radhey04ec 0:7945527e6a18 512
radhey04ec 0:7945527e6a18 513 void error(uint8_t error_number)
radhey04ec 0:7945527e6a18 514 {
radhey04ec 0:7945527e6a18 515 {
radhey04ec 0:7945527e6a18 516 RED_LED=1;
radhey04ec 0:7945527e6a18 517 GREEN_LED=0;
radhey04ec 0:7945527e6a18 518 BLUE_LED=0;
radhey04ec 0:7945527e6a18 519 BUZZER = 1;
radhey04ec 0:7945527e6a18 520 wait(1);
radhey04ec 0:7945527e6a18 521 BUZZER =0;
radhey04ec 0:7945527e6a18 522 lcd.cls();
radhey04ec 0:7945527e6a18 523 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 524 lcd.printf("Oops ..ERROR");
radhey04ec 0:7945527e6a18 525 pc.printf("\n Test Fail ");
radhey04ec 0:7945527e6a18 526 pc.printf("\n Error -- Contact to HOD");
radhey04ec 0:7945527e6a18 527 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 528 lcd.printf("PLUG NEW BOARD");
radhey04ec 0:7945527e6a18 529 lcd.locate(0,3);
radhey04ec 0:7945527e6a18 530 lcd.printf("Total Test = %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 531 if(error_number == 1)
radhey04ec 0:7945527e6a18 532 {
radhey04ec 0:7945527e6a18 533 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 534 lcd.printf("WRONG VERSION");
radhey04ec 0:7945527e6a18 535 pc.printf("\n ERROR CODE = 0x1");
radhey04ec 0:7945527e6a18 536 pc.printf("\n WRONG VERSION OF SOFTWARE , PLEASE CHECK");
radhey04ec 0:7945527e6a18 537 pc.printf("\n POSSIBLE SOLUTION \n");
radhey04ec 0:7945527e6a18 538 pc.printf("\n 1) REPROGRAM BOARD 2) CHECK SUPPLY VOLTAGE ");
radhey04ec 0:7945527e6a18 539 wait(3);
radhey04ec 0:7945527e6a18 540 }
radhey04ec 0:7945527e6a18 541 if(error_number == 2)
radhey04ec 0:7945527e6a18 542 {
radhey04ec 0:7945527e6a18 543 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 544 lcd.printf("OVER CURRENT ");
radhey04ec 0:7945527e6a18 545 pc.printf("\n ERROR CODE = 0X2");
radhey04ec 0:7945527e6a18 546 pc.printf("\n OVER CURRENT ERROR");
radhey04ec 0:7945527e6a18 547 pc.printf("\n POSSIBLE SOLUTION");
radhey04ec 0:7945527e6a18 548 pc.printf("\n TRY TO WASH BOARD AGAIN and RECHECK");
radhey04ec 0:7945527e6a18 549 wait(3);
radhey04ec 0:7945527e6a18 550 }
radhey04ec 0:7945527e6a18 551
radhey04ec 0:7945527e6a18 552 }
radhey04ec 0:7945527e6a18 553
radhey04ec 0:7945527e6a18 554 //AT END OF PROCESS
radhey04ec 0:7945527e6a18 555 TEST_FLAG = 0U;
radhey04ec 0:7945527e6a18 556 PROCESS_FLAG = 0U;
radhey04ec 0:7945527e6a18 557 RED_LED =1;
radhey04ec 0:7945527e6a18 558 BUZZER = 1;
radhey04ec 0:7945527e6a18 559 NEXT = 0;
radhey04ec 0:7945527e6a18 560 //ERROR_FLAG =0;
radhey04ec 0:7945527e6a18 561 wait(3);
radhey04ec 0:7945527e6a18 562 BUZZER =0;
radhey04ec 0:7945527e6a18 563 pc.printf("\n *******************ERROR DESCRIPTION END **************************");
radhey04ec 0:7945527e6a18 564 pc.printf("\n ***************************END OF TEST ****************************");
radhey04ec 0:7945527e6a18 565 }
radhey04ec 0:7945527e6a18 566
radhey04ec 0:7945527e6a18 567 void WELCOME_SCREEN()
radhey04ec 0:7945527e6a18 568 {
radhey04ec 0:7945527e6a18 569 pc.printf("\n");
radhey04ec 0:7945527e6a18 570 pc.printf("AXV GOLBAL VALVE TESTER -- FOLLOW THE STEPS \n");
radhey04ec 0:7945527e6a18 571
radhey04ec 0:7945527e6a18 572 RED_LED = 1;
radhey04ec 0:7945527e6a18 573 GREEN_LED = 1;
radhey04ec 0:7945527e6a18 574 BLUE_LED =1;
radhey04ec 0:7945527e6a18 575 BUZZER = 1;
radhey04ec 0:7945527e6a18 576 wait(1);
radhey04ec 0:7945527e6a18 577 BUZZER = 0;
radhey04ec 0:7945527e6a18 578
radhey04ec 0:7945527e6a18 579
radhey04ec 0:7945527e6a18 580 //WELCOME SCREEN DATA
radhey04ec 0:7945527e6a18 581 lcd.cls(); //clear the screen first
radhey04ec 0:7945527e6a18 582 lcd.printf(" Welcome !!!");
radhey04ec 0:7945527e6a18 583 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 584 lcd.printf("GLOBAL V- TESTER");
radhey04ec 0:7945527e6a18 585 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 586 lcd.printf("POWERED BY : KEPL ");
radhey04ec 0:7945527e6a18 587 lcd.locate(0,3);
radhey04ec 0:7945527e6a18 588 lcd.printf("R_AND_D DEPARTMENT");
radhey04ec 0:7945527e6a18 589 wait(5);
radhey04ec 0:7945527e6a18 590 lcd.cls();
radhey04ec 0:7945527e6a18 591 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 592 lcd.printf("Loading...");
radhey04ec 0:7945527e6a18 593 lcd.locate(11,0);
radhey04ec 0:7945527e6a18 594 pc.printf("\n DATA LOADING .....");
radhey04ec 0:7945527e6a18 595 pc.printf("\n Veryfying....");
radhey04ec 0:7945527e6a18 596 wait_ms(500);
radhey04ec 0:7945527e6a18 597 lcd.printf(".");
radhey04ec 0:7945527e6a18 598 lcd.locate(12,0);
radhey04ec 0:7945527e6a18 599 wait_ms(500);
radhey04ec 0:7945527e6a18 600 lcd.printf("...");
radhey04ec 0:7945527e6a18 601 wait_ms(1000);
radhey04ec 0:7945527e6a18 602 lcd.locate(13,0);
radhey04ec 0:7945527e6a18 603 lcd.printf("..");
radhey04ec 0:7945527e6a18 604 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 605 lcd.printf("Veryfied.........");
radhey04ec 0:7945527e6a18 606 wait_ms(3000);
radhey04ec 0:7945527e6a18 607 pc.printf("\n LCD COMMUNICATION Successful \n");
radhey04ec 0:7945527e6a18 608 lcd.cls();
radhey04ec 0:7945527e6a18 609 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 610 lcd.printf("Done !!!!");
radhey04ec 0:7945527e6a18 611 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 612 lcd.printf("TEST MODE ON");
radhey04ec 0:7945527e6a18 613 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 614 lcd.printf("COUNT = 0");
radhey04ec 0:7945527e6a18 615 wait_ms(5000);
radhey04ec 0:7945527e6a18 616 lcd.cls();
radhey04ec 0:7945527e6a18 617 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 618 BLUE_LED = 1;
radhey04ec 0:7945527e6a18 619 BUZZER = 1;
radhey04ec 0:7945527e6a18 620 wait_ms(250);
radhey04ec 0:7945527e6a18 621 BUZZER = 0;
radhey04ec 0:7945527e6a18 622 pc.printf("\n SOFTWARE CHECKED & READY TO USE \n");
radhey04ec 0:7945527e6a18 623 pc.printf("\n ESD PROTECTION REQUIRE");
radhey04ec 0:7945527e6a18 624 pc.printf("\n KEEP YOUR EYES ON TERMINAL OR ON LCD");
radhey04ec 0:7945527e6a18 625 pc.printf("\n LED VISUAL AND BUZZER SOUND INDICATION HELPS YOU !!!");
radhey04ec 0:7945527e6a18 626 lcd.printf("AXV -T");
radhey04ec 0:7945527e6a18 627 lcd.locate(10,0);
radhey04ec 0:7945527e6a18 628 lcd.printf("Count %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 629
radhey04ec 0:7945527e6a18 630 }
radhey04ec 0:7945527e6a18 631
radhey04ec 0:7945527e6a18 632 void NEW_TEST_UPDATE_LCD()
radhey04ec 0:7945527e6a18 633 {
radhey04ec 0:7945527e6a18 634 GREEN_LED = 1;
radhey04ec 0:7945527e6a18 635 BLUE_LED = 1;
radhey04ec 0:7945527e6a18 636 lcd.cls();
radhey04ec 0:7945527e6a18 637 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 638 lcd.printf("TESTING ON...");
radhey04ec 0:7945527e6a18 639 pc.printf("\n \n \n");
radhey04ec 0:7945527e6a18 640 pc.printf("\n NEW TEST START");
radhey04ec 0:7945527e6a18 641 wait(8); //8 SECOND
radhey04ec 0:7945527e6a18 642 lcd.locate(0,1);
radhey04ec 0:7945527e6a18 643 lcd.printf("BOARD SCANING..");
radhey04ec 0:7945527e6a18 644 pc.printf("\n BOARD SCANNING...");
radhey04ec 0:7945527e6a18 645 wait(8);
radhey04ec 0:7945527e6a18 646 lcd.locate(0,2);
radhey04ec 0:7945527e6a18 647 lcd.printf("COMMUNICATING...");
radhey04ec 0:7945527e6a18 648 pc.printf("\n COMMUNICATION ESTABLISHMENT \n");
radhey04ec 0:7945527e6a18 649 wait(5);
radhey04ec 0:7945527e6a18 650 lcd.printf("READY FOR TEST");
radhey04ec 0:7945527e6a18 651 wait(5);
radhey04ec 0:7945527e6a18 652 lcd.cls();
radhey04ec 0:7945527e6a18 653 lcd.locate(0,0);
radhey04ec 0:7945527e6a18 654 lcd.printf("TEST MODE N 0%u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 655 pc.printf("TEST MODE ON - COUNT = %u",PCB_COUNTER);
radhey04ec 0:7945527e6a18 656 A.release();
radhey04ec 0:7945527e6a18 657 wait(0.5);
radhey04ec 0:7945527e6a18 658
radhey04ec 0:7945527e6a18 659 }
radhey04ec 0:7945527e6a18 660
radhey04ec 0:7945527e6a18 661 /*Below Function is part of ISR ;so do not write big code inside it
radhey04ec 0:7945527e6a18 662 If possible than only set and reset flag only
radhey04ec 0:7945527e6a18 663 Because while servicing Interrupt OS can not schedule or switch other thread or Task
radhey04ec 0:7945527e6a18 664 In future during updation of version please consider RTOS Management Rule
radhey04ec 0:7945527e6a18 665 or contact Reserach & development team : JAYDEEP SHAH
radhey04ec 0:7945527e6a18 666 */
radhey04ec 0:7945527e6a18 667
radhey04ec 0:7945527e6a18 668 void TEST_PROCESS() //This Function is connected with ISR Of Push_button
radhey04ec 0:7945527e6a18 669 {
radhey04ec 0:7945527e6a18 670 if(TEST_FLAG == 0U && PROCESS_FLAG == 0U)
radhey04ec 0:7945527e6a18 671 {
radhey04ec 0:7945527e6a18 672 TEST_FLAG = 1U;
radhey04ec 0:7945527e6a18 673 }
radhey04ec 0:7945527e6a18 674 else
radhey04ec 0:7945527e6a18 675 {
radhey04ec 0:7945527e6a18 676 TEST_FLAG = 0U;
radhey04ec 0:7945527e6a18 677
radhey04ec 0:7945527e6a18 678 }
radhey04ec 0:7945527e6a18 679
radhey04ec 0:7945527e6a18 680 }
radhey04ec 0:7945527e6a18 681 void CURRENT()
radhey04ec 0:7945527e6a18 682 {
radhey04ec 0:7945527e6a18 683 for(int i =0;i <10 ; i++) //Array to make result smoother
radhey04ec 0:7945527e6a18 684 {
radhey04ec 0:7945527e6a18 685 AARAY[i] = ANG.read(); //Read the data
radhey04ec 0:7945527e6a18 686 ThisThread::sleep_for(20); //Thread sleep for make ADC ready for next result
radhey04ec 0:7945527e6a18 687 SUM = SUM + AARAY[i]; //Store result
radhey04ec 0:7945527e6a18 688 }
radhey04ec 0:7945527e6a18 689 float value = (SUM /10); //Finding Average value
radhey04ec 0:7945527e6a18 690
radhey04ec 0:7945527e6a18 691 current = (((((((value)) * 3.3)-0.28)/200)/0.6)*1000); //Finding current
radhey04ec 0:7945527e6a18 692 current = current + 2.5; // 2.5 is offset (when current is < 50 mA)
radhey04ec 0:7945527e6a18 693
radhey04ec 0:7945527e6a18 694 //pc.printf("\n Current (mA) = %f",current); //Print data on Serial console -- I used CoolTerm
radhey04ec 0:7945527e6a18 695
radhey04ec 0:7945527e6a18 696 SUM = 0; //At the end sum must be zero
radhey04ec 0:7945527e6a18 697 //A.release();
radhey04ec 0:7945527e6a18 698
radhey04ec 0:7945527e6a18 699 }
radhey04ec 0:7945527e6a18 700
radhey04ec 0:7945527e6a18 701 void BUFFER_CLEAR()
radhey04ec 0:7945527e6a18 702 {
radhey04ec 0:7945527e6a18 703 RxInterrupt(); // To clear serial buffer
radhey04ec 0:7945527e6a18 704 i = 0U;
radhey04ec 0:7945527e6a18 705 bufferReadingIndex = 0U;
radhey04ec 0:7945527e6a18 706 for(int k =0; k<50 ; k++) // ****************CLEAR 50 BYTES BUFFER
radhey04ec 0:7945527e6a18 707 {
radhey04ec 0:7945527e6a18 708 rxBuffer[k] = ' ';
radhey04ec 0:7945527e6a18 709 }
radhey04ec 0:7945527e6a18 710 }