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
main.cpp@2:fab01e10358e, 2020-08-10 (annotated)
- Committer:
- radhey04ec
- Date:
- Mon Aug 10 13:17:13 2020 +0000
- Revision:
- 2:fab01e10358e
- Parent:
- 1:bdc3ebd4e52b
FINAL COMMIT PROGRAM TESTED OK
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:fab01e10358e | 126 | lcd.printf("."); |
radhey04ec | 0:7945527e6a18 | 127 | pc.printf("\n Input Current is = %.2f mA",current); |
radhey04ec | 2:fab01e10358e | 128 | ThisThread::sleep_for(10); |
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 | 2:fab01e10358e | 190 | wait(5); |
radhey04ec | 2:fab01e10358e | 191 | pc.printf("*********************************************************************\n"); |
radhey04ec | 0:7945527e6a18 | 192 | pc.printf("\n STM POWER ON -- DATA INITIALIZATION \n"); |
radhey04ec | 0:7945527e6a18 | 193 | pc.printf("\n PROGRAM CREATED BY : R_AND_D DEPT of KEPL \n"); |
radhey04ec | 0:7945527e6a18 | 194 | pc.printf("\n Program Version 1.0 \n"); |
radhey04ec | 0:7945527e6a18 | 195 | pc.printf("\n Any changes of the program lead toward Board OS Crash or bugs"); |
radhey04ec | 2:fab01e10358e | 196 | pc.printf("\n NOTE : Permission require before any Hardware /or software changes \n"); |
radhey04ec | 2:fab01e10358e | 197 | pc.printf("\n RTOS TRYING TO ACCESS THREAD CODE......INITIALIZATIO OF RTOS START.....\n"); |
radhey04ec | 2:fab01e10358e | 198 | pc.printf("\n"); |
radhey04ec | 2:fab01e10358e | 199 | pc.printf("\n Do not press any Button\n"); |
radhey04ec | 2:fab01e10358e | 200 | pc.printf("\n *******************************************************************\n"); |
radhey04ec | 0:7945527e6a18 | 201 | |
radhey04ec | 0:7945527e6a18 | 202 | |
radhey04ec | 0:7945527e6a18 | 203 | //INITIAL ALL LED OFF |
radhey04ec | 0:7945527e6a18 | 204 | pc.printf("\n MAKE ALL LEDS and BUZZER OFF \n"); |
radhey04ec | 0:7945527e6a18 | 205 | RED_LED = 0; |
radhey04ec | 0:7945527e6a18 | 206 | GREEN_LED = 0; |
radhey04ec | 0:7945527e6a18 | 207 | BLUE_LED = 0; |
radhey04ec | 0:7945527e6a18 | 208 | BUZZER = 0; |
radhey04ec | 0:7945527e6a18 | 209 | |
radhey04ec | 0:7945527e6a18 | 210 | WELCOME_SCREEN(); //TO INITIALIZE DATA |
radhey04ec | 0:7945527e6a18 | 211 | |
radhey04ec | 2:fab01e10358e | 212 | pc.printf("\n \n \n Good Luck !!!! \n"); |
radhey04ec | 2:fab01e10358e | 213 | pc.printf("\n CURRENT MEASUREMENT UNIT TURNING ON...........\n"); |
radhey04ec | 0:7945527e6a18 | 214 | |
radhey04ec | 0:7945527e6a18 | 215 | T1.start(CURRENT_MEASUREMENT); |
radhey04ec | 0:7945527e6a18 | 216 | T2.start(LCD_REFRESH); |
radhey04ec | 0:7945527e6a18 | 217 | |
radhey04ec | 1:bdc3ebd4e52b | 218 | pc.printf("\n All Thread create succesffully\n"); |
radhey04ec | 0:7945527e6a18 | 219 | wait_ms(500); |
radhey04ec | 1:bdc3ebd4e52b | 220 | pc.printf("\n NOW PLUG THE UNIT AND PRESS THE BUTTON \n"); |
radhey04ec | 0:7945527e6a18 | 221 | while(true) |
radhey04ec | 0:7945527e6a18 | 222 | { |
radhey04ec | 0:7945527e6a18 | 223 | BLUE_LED = 0; |
radhey04ec | 0:7945527e6a18 | 224 | START_NEW_TEST(); //This function only work if FLAG SET |
radhey04ec | 0:7945527e6a18 | 225 | wait_ms(500); |
radhey04ec | 0:7945527e6a18 | 226 | |
radhey04ec | 0:7945527e6a18 | 227 | BLUE_LED = 1; |
radhey04ec | 0:7945527e6a18 | 228 | |
radhey04ec | 0:7945527e6a18 | 229 | } |
radhey04ec | 0:7945527e6a18 | 230 | |
radhey04ec | 0:7945527e6a18 | 231 | } |
radhey04ec | 0:7945527e6a18 | 232 | |
radhey04ec | 0:7945527e6a18 | 233 | void RxInterrupt() //if Rx buffer have data --- Interrupt call |
radhey04ec | 0:7945527e6a18 | 234 | { |
radhey04ec | 0:7945527e6a18 | 235 | //Because of Interrupt -- Ideally no CONTEXT SWITCH |
radhey04ec | 0:7945527e6a18 | 236 | if(UT.readable()) //IF data available |
radhey04ec | 0:7945527e6a18 | 237 | { |
radhey04ec | 0:7945527e6a18 | 238 | rxBuffer[bufferReadingIndex++] = UT.getc(); // read and store into Buffer |
radhey04ec | 0:7945527e6a18 | 239 | if(bufferReadingIndex >= BUFFER_SIZE) // If limit cross |
radhey04ec | 0:7945527e6a18 | 240 | { |
radhey04ec | 0:7945527e6a18 | 241 | bufferReadingIndex =0; // RESET CONTER |
radhey04ec | 0:7945527e6a18 | 242 | } |
radhey04ec | 0:7945527e6a18 | 243 | } |
radhey04ec | 0:7945527e6a18 | 244 | } |
radhey04ec | 0:7945527e6a18 | 245 | |
radhey04ec | 0:7945527e6a18 | 246 | void response() //FUNCTION TO READ DATA |
radhey04ec | 0:7945527e6a18 | 247 | { |
radhey04ec | 0:7945527e6a18 | 248 | char rxByte; |
radhey04ec | 0:7945527e6a18 | 249 | printf("\n"); |
radhey04ec | 0:7945527e6a18 | 250 | |
radhey04ec | 0:7945527e6a18 | 251 | //NEED TO STOP CONTEXT SWITCH |
radhey04ec | 0:7945527e6a18 | 252 | while(i != bufferReadingIndex) //READ WHILE COMPLETE DATA NOT RECEIVED |
radhey04ec | 0:7945527e6a18 | 253 | { |
radhey04ec | 0:7945527e6a18 | 254 | rxByte = rxBuffer[i]; //READ DATA ONE BY ONE CHARACTER |
radhey04ec | 0:7945527e6a18 | 255 | pc.putc(rxByte); // SEND ON TERMINAL |
radhey04ec | 0:7945527e6a18 | 256 | i++; //COUNTER INCREMEN |
radhey04ec | 0:7945527e6a18 | 257 | |
radhey04ec | 0:7945527e6a18 | 258 | if(i >= BUFFER_SIZE) //IF LIMIT CROSS |
radhey04ec | 0:7945527e6a18 | 259 | { |
radhey04ec | 0:7945527e6a18 | 260 | i = 0; //RESET COUNTER |
radhey04ec | 0:7945527e6a18 | 261 | } |
radhey04ec | 0:7945527e6a18 | 262 | } |
radhey04ec | 0:7945527e6a18 | 263 | |
radhey04ec | 0:7945527e6a18 | 264 | //USE THREAD YIELD FOR UPDATE OTHER THREADS |
radhey04ec | 0:7945527e6a18 | 265 | |
radhey04ec | 0:7945527e6a18 | 266 | |
radhey04ec | 0:7945527e6a18 | 267 | |
radhey04ec | 0:7945527e6a18 | 268 | LCD_FLAG = 0; //RESET -- VERSION READ COMPLETED |
radhey04ec | 0:7945527e6a18 | 269 | //THREA YIELD |
radhey04ec | 0:7945527e6a18 | 270 | |
radhey04ec | 0:7945527e6a18 | 271 | |
radhey04ec | 0:7945527e6a18 | 272 | } |
radhey04ec | 0:7945527e6a18 | 273 | |
radhey04ec | 0:7945527e6a18 | 274 | void START_NEW_TEST(void) |
radhey04ec | 0:7945527e6a18 | 275 | { |
radhey04ec | 0:7945527e6a18 | 276 | if(TEST_FLAG == 1U && PROCESS_FLAG == 0U) |
radhey04ec | 0:7945527e6a18 | 277 | { |
radhey04ec | 0:7945527e6a18 | 278 | //FLAG MUST BE ZERO |
radhey04ec | 0:7945527e6a18 | 279 | NEXT = 0; |
radhey04ec | 0:7945527e6a18 | 280 | ERROR_FLAG = 0; |
radhey04ec | 0:7945527e6a18 | 281 | RED_LED =0; |
radhey04ec | 0:7945527e6a18 | 282 | GREEN_LED =1; |
radhey04ec | 0:7945527e6a18 | 283 | PROCESS_FLAG = 1U; |
radhey04ec | 0:7945527e6a18 | 284 | //turn test flag on |
radhey04ec | 0:7945527e6a18 | 285 | TEST_FLAG =1U; |
radhey04ec | 0:7945527e6a18 | 286 | //COUNTER++ |
radhey04ec | 0:7945527e6a18 | 287 | PCB_COUNTER++; |
radhey04ec | 0:7945527e6a18 | 288 | //NEED TO WAIT 25 ms |
radhey04ec | 0:7945527e6a18 | 289 | pc.printf("\n \n \n"); |
radhey04ec | 0:7945527e6a18 | 290 | pc.printf("***********************************************************"); |
radhey04ec | 0:7945527e6a18 | 291 | pc.printf("AXV 001 PCB NUMBER = %u",PCB_COUNTER); |
radhey04ec | 0:7945527e6a18 | 292 | NEW_TEST_UPDATE_LCD(); //THIS FUNCTION IS ONLY FOR DELAY |
radhey04ec | 0:7945527e6a18 | 293 | |
radhey04ec | 0:7945527e6a18 | 294 | |
radhey04ec | 0:7945527e6a18 | 295 | A.release(); |
radhey04ec | 0:7945527e6a18 | 296 | //last fucntion to reset flag and display test result |
radhey04ec | 2:fab01e10358e | 297 | wait(0.5); |
radhey04ec | 0:7945527e6a18 | 298 | //CLEAR THE BUFFER BEFORE UART COMM |
radhey04ec | 0:7945527e6a18 | 299 | //***************TEST - 1 ENTER INTEST MODE AND VERSION READ------------------------------TEST1 |
radhey04ec | 0:7945527e6a18 | 300 | BUFFER_CLEAR(); |
radhey04ec | 0:7945527e6a18 | 301 | UT.putc('T'); //ENTER IN TEST MODE -- SLAVE BOARD ENTER INTO TEST MODE |
radhey04ec | 0:7945527e6a18 | 302 | A.release(); |
radhey04ec | 0:7945527e6a18 | 303 | ThisThread::sleep_for(1000); |
radhey04ec | 0:7945527e6a18 | 304 | response(); |
radhey04ec | 0:7945527e6a18 | 305 | wait(0.10); |
radhey04ec | 0:7945527e6a18 | 306 | //FETCHING VERSION NUMBER 01.34 |
radhey04ec | 0:7945527e6a18 | 307 | lcd.cls(); |
radhey04ec | 2:fab01e10358e | 308 | wait(1); |
radhey04ec | 0:7945527e6a18 | 309 | lcd.locate(0,0); |
radhey04ec | 2:fab01e10358e | 310 | lcd.printf(""); |
radhey04ec | 0:7945527e6a18 | 311 | lcd.printf("VERSION TEST ON"); |
radhey04ec | 0:7945527e6a18 | 312 | { |
radhey04ec | 0:7945527e6a18 | 313 | uint8_t j=0; |
radhey04ec | 0:7945527e6a18 | 314 | char temp_buf[6]; |
radhey04ec | 0:7945527e6a18 | 315 | char ver[] = "01.34"; |
radhey04ec | 0:7945527e6a18 | 316 | pc.puts("\n FETCHING VERSION FROM IC: "); |
radhey04ec | 0:7945527e6a18 | 317 | for(j=13;j<18;j++) |
radhey04ec | 0:7945527e6a18 | 318 | { |
radhey04ec | 0:7945527e6a18 | 319 | pc.putc(rxBuffer[j]); |
radhey04ec | 0:7945527e6a18 | 320 | temp_buf[j-13] = rxBuffer[j]; |
radhey04ec | 0:7945527e6a18 | 321 | } |
radhey04ec | 0:7945527e6a18 | 322 | temp_buf[5] = '\n'; |
radhey04ec | 0:7945527e6a18 | 323 | float value = atof(temp_buf); |
radhey04ec | 0:7945527e6a18 | 324 | pc.printf("\n VERSION VALUE IS %f",value); |
radhey04ec | 0:7945527e6a18 | 325 | if(value == 1.340000f) |
radhey04ec | 0:7945527e6a18 | 326 | { |
radhey04ec | 0:7945527e6a18 | 327 | pc.printf("\n Correct Version receive \n"); |
radhey04ec | 0:7945527e6a18 | 328 | //PRINT DATA ON LCD |
radhey04ec | 0:7945527e6a18 | 329 | lcd.locate(0,1); |
radhey04ec | 0:7945527e6a18 | 330 | lcd.printf("VERSION = 1.34"); |
radhey04ec | 2:fab01e10358e | 331 | lcd.locate(0,2); |
radhey04ec | 0:7945527e6a18 | 332 | lcd.printf("VERSION TEST OK"); |
radhey04ec | 0:7945527e6a18 | 333 | //GO FOR NEXT TEST |
radhey04ec | 0:7945527e6a18 | 334 | NEXT = 1; //READY FOR NEXT TEST |
radhey04ec | 2:fab01e10358e | 335 | CURRENT(); |
radhey04ec | 0:7945527e6a18 | 336 | A.release(); |
radhey04ec | 2:fab01e10358e | 337 | wait(6); |
radhey04ec | 0:7945527e6a18 | 338 | |
radhey04ec | 0:7945527e6a18 | 339 | |
radhey04ec | 0:7945527e6a18 | 340 | } |
radhey04ec | 0:7945527e6a18 | 341 | else |
radhey04ec | 0:7945527e6a18 | 342 | { |
radhey04ec | 0:7945527e6a18 | 343 | pc.printf("\n Wrong version \n"); |
radhey04ec | 0:7945527e6a18 | 344 | //ERROR - STOP TEST |
radhey04ec | 0:7945527e6a18 | 345 | ERROR_FLAG = 1; |
radhey04ec | 0:7945527e6a18 | 346 | error(1); |
radhey04ec | 0:7945527e6a18 | 347 | NEXT = 0; |
radhey04ec | 0:7945527e6a18 | 348 | } |
radhey04ec | 0:7945527e6a18 | 349 | |
radhey04ec | 0:7945527e6a18 | 350 | j = 0; |
radhey04ec | 0:7945527e6a18 | 351 | //Clear the buffer data to avoid mistakes |
radhey04ec | 0:7945527e6a18 | 352 | |
radhey04ec | 0:7945527e6a18 | 353 | } |
radhey04ec | 0:7945527e6a18 | 354 | if(NEXT == 1) //**************** RED LED TESTING ********************* |
radhey04ec | 0:7945527e6a18 | 355 | { |
radhey04ec | 2:fab01e10358e | 356 | float CURRENT_TEMP = 0; |
radhey04ec | 0:7945527e6a18 | 357 | NEXT = 0; |
radhey04ec | 0:7945527e6a18 | 358 | lcd.cls(); |
radhey04ec | 2:fab01e10358e | 359 | CURRENT(); |
radhey04ec | 0:7945527e6a18 | 360 | A.release(); |
radhey04ec | 2:fab01e10358e | 361 | wait(2); |
radhey04ec | 0:7945527e6a18 | 362 | BUFFER_CLEAR(); |
radhey04ec | 0:7945527e6a18 | 363 | lcd.locate(0,0); |
radhey04ec | 2:fab01e10358e | 364 | lcd.printf(""); |
radhey04ec | 2:fab01e10358e | 365 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 366 | lcd.printf("RED LED TEST ON"); |
radhey04ec | 0:7945527e6a18 | 367 | pc.printf("\n RED LED TESTING START"); |
radhey04ec | 0:7945527e6a18 | 368 | UT.putc('d'); // RED LED OF SLAVE BOARD ON |
radhey04ec | 0:7945527e6a18 | 369 | A.release(); |
radhey04ec | 0:7945527e6a18 | 370 | wait(1); |
radhey04ec | 0:7945527e6a18 | 371 | response(); //Read Response from Slave |
radhey04ec | 1:bdc3ebd4e52b | 372 | pc.printf("\n RED LED COMMAND RELEASE "); |
radhey04ec | 0:7945527e6a18 | 373 | lcd.locate(0,1); |
radhey04ec | 1:bdc3ebd4e52b | 374 | { |
radhey04ec | 1:bdc3ebd4e52b | 375 | float LDR_AVG =0; |
radhey04ec | 1:bdc3ebd4e52b | 376 | float S = 0; |
radhey04ec | 1:bdc3ebd4e52b | 377 | int8_t z; |
radhey04ec | 2:fab01e10358e | 378 | |
radhey04ec | 1:bdc3ebd4e52b | 379 | |
radhey04ec | 1:bdc3ebd4e52b | 380 | for(z = 0; z < 10; z++) |
radhey04ec | 1:bdc3ebd4e52b | 381 | { |
radhey04ec | 1:bdc3ebd4e52b | 382 | |
radhey04ec | 1:bdc3ebd4e52b | 383 | LDR_VALUE = LDR.read(); |
radhey04ec | 1:bdc3ebd4e52b | 384 | wait_ms(20); |
radhey04ec | 1:bdc3ebd4e52b | 385 | S = S + LDR_VALUE; |
radhey04ec | 1:bdc3ebd4e52b | 386 | |
radhey04ec | 1:bdc3ebd4e52b | 387 | } |
radhey04ec | 1:bdc3ebd4e52b | 388 | LDR_AVG = S /10; |
radhey04ec | 1:bdc3ebd4e52b | 389 | LDR_VALUE = LDR_AVG; |
radhey04ec | 1:bdc3ebd4e52b | 390 | } |
radhey04ec | 2:fab01e10358e | 391 | lcd.printf("RED LED ON COMMAND"); |
radhey04ec | 0:7945527e6a18 | 392 | BUFFER_CLEAR(); |
radhey04ec | 0:7945527e6a18 | 393 | A.release(); |
radhey04ec | 2:fab01e10358e | 394 | wait(2); |
radhey04ec | 2:fab01e10358e | 395 | A.release(); |
radhey04ec | 2:fab01e10358e | 396 | wait(2); |
radhey04ec | 2:fab01e10358e | 397 | CURRENT(); |
radhey04ec | 2:fab01e10358e | 398 | A.release(); |
radhey04ec | 2:fab01e10358e | 399 | wait(2); |
radhey04ec | 2:fab01e10358e | 400 | CURRENT_TEMP = current; |
radhey04ec | 2:fab01e10358e | 401 | pc.printf("\n RED LED ON TIME CURRENT = %f",current); |
radhey04ec | 0:7945527e6a18 | 402 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 403 | lcd.printf("RED LED OFF COMMAND"); |
radhey04ec | 0:7945527e6a18 | 404 | UT.putc('b'); |
radhey04ec | 0:7945527e6a18 | 405 | A.release(); |
radhey04ec | 2:fab01e10358e | 406 | wait(2); |
radhey04ec | 0:7945527e6a18 | 407 | response(); |
radhey04ec | 0:7945527e6a18 | 408 | BUFFER_CLEAR(); |
radhey04ec | 0:7945527e6a18 | 409 | pc.printf("RED LED TEST FINISH"); |
radhey04ec | 1:bdc3ebd4e52b | 410 | |
radhey04ec | 1:bdc3ebd4e52b | 411 | //result time |
radhey04ec | 1:bdc3ebd4e52b | 412 | if(LDR_VALUE > 0.650) |
radhey04ec | 1:bdc3ebd4e52b | 413 | { |
radhey04ec | 0:7945527e6a18 | 414 | lcd.locate(0,0); |
radhey04ec | 2:fab01e10358e | 415 | lcd.printf(""); |
radhey04ec | 2:fab01e10358e | 416 | lcd.printf("RED LED TEST OK"); |
radhey04ec | 2:fab01e10358e | 417 | lcd.locate(0,1); |
radhey04ec | 0:7945527e6a18 | 418 | lcd.printf(" "); |
radhey04ec | 2:fab01e10358e | 419 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 420 | lcd.printf("LED ON DETECTED"); |
radhey04ec | 0:7945527e6a18 | 421 | NEXT = 1; |
radhey04ec | 1:bdc3ebd4e52b | 422 | pc.printf("\n RED LED DETECT SUCCESSFULLY"); |
radhey04ec | 1:bdc3ebd4e52b | 423 | |
radhey04ec | 1:bdc3ebd4e52b | 424 | //CLEAR LCD CONTENT |
radhey04ec | 2:fab01e10358e | 425 | wait(6); |
radhey04ec | 1:bdc3ebd4e52b | 426 | LDR_VALUE = 0; |
radhey04ec | 0:7945527e6a18 | 427 | } |
radhey04ec | 0:7945527e6a18 | 428 | else |
radhey04ec | 0:7945527e6a18 | 429 | { |
radhey04ec | 1:bdc3ebd4e52b | 430 | pc.printf("\n PROBLEM in LED DETECTION"); |
radhey04ec | 1:bdc3ebd4e52b | 431 | NEXT = 0; |
radhey04ec | 1:bdc3ebd4e52b | 432 | ERROR_FLAG = 1; |
radhey04ec | 1:bdc3ebd4e52b | 433 | error(5); |
radhey04ec | 1:bdc3ebd4e52b | 434 | |
radhey04ec | 0:7945527e6a18 | 435 | |
radhey04ec | 0:7945527e6a18 | 436 | } |
radhey04ec | 2:fab01e10358e | 437 | wait_ms(200); |
radhey04ec | 2:fab01e10358e | 438 | if(CURRENT_TEMP < 12.0 || CURRENT_TEMP > 20.5) |
radhey04ec | 2:fab01e10358e | 439 | { |
radhey04ec | 2:fab01e10358e | 440 | pc.printf("\n OVER OR UNDER CURRENT ERROR \n"); |
radhey04ec | 2:fab01e10358e | 441 | pc.printf("\n This Error at time of LED on/off process \n"); |
radhey04ec | 2:fab01e10358e | 442 | NEXT = 0; |
radhey04ec | 2:fab01e10358e | 443 | ERROR_FLAG = 1; |
radhey04ec | 2:fab01e10358e | 444 | CURRENT_TEMP =0; |
radhey04ec | 2:fab01e10358e | 445 | error(7); |
radhey04ec | 2:fab01e10358e | 446 | |
radhey04ec | 2:fab01e10358e | 447 | } |
radhey04ec | 1:bdc3ebd4e52b | 448 | |
radhey04ec | 0:7945527e6a18 | 449 | } |
radhey04ec | 0:7945527e6a18 | 450 | if(NEXT == 1)//**********************************CALIBRATION ON |
radhey04ec | 0:7945527e6a18 | 451 | { |
radhey04ec | 0:7945527e6a18 | 452 | NEXT =0; |
radhey04ec | 2:fab01e10358e | 453 | pc.printf("\n CALIBRATION ON "); |
radhey04ec | 2:fab01e10358e | 454 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 455 | lcd.printf(" "); |
radhey04ec | 0:7945527e6a18 | 456 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 457 | lcd.printf("CALIBRATION ON"); |
radhey04ec | 0:7945527e6a18 | 458 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 459 | lcd.printf(" "); |
radhey04ec | 2:fab01e10358e | 460 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 461 | wait(1); |
radhey04ec | 2:fab01e10358e | 462 | lcd.printf("In PROGRESS...."); |
radhey04ec | 2:fab01e10358e | 463 | pc.printf("\n CALIBRATION PROCESS IN PROGRESS"); |
radhey04ec | 0:7945527e6a18 | 464 | BUFFER_CLEAR(); |
radhey04ec | 0:7945527e6a18 | 465 | UT.putc('c'); |
radhey04ec | 0:7945527e6a18 | 466 | A.release(); |
radhey04ec | 2:fab01e10358e | 467 | wait(5); |
radhey04ec | 0:7945527e6a18 | 468 | UT.putc('s'); |
radhey04ec | 0:7945527e6a18 | 469 | A.release(); |
radhey04ec | 0:7945527e6a18 | 470 | wait(1); |
radhey04ec | 0:7945527e6a18 | 471 | lcd.locate(0,2); |
radhey04ec | 2:fab01e10358e | 472 | lcd.printf(" "); |
radhey04ec | 2:fab01e10358e | 473 | lcd.locate(0,2); |
radhey04ec | 0:7945527e6a18 | 474 | pc.printf("\n CALIBRATION COMPLETE"); |
radhey04ec | 0:7945527e6a18 | 475 | lcd.printf("DATA SAVE OK"); |
radhey04ec | 2:fab01e10358e | 476 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 477 | lcd.printf(" "); |
radhey04ec | 2:fab01e10358e | 478 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 479 | lcd.printf("CALIBRATION DONE"); |
radhey04ec | 2:fab01e10358e | 480 | A.release(); |
radhey04ec | 2:fab01e10358e | 481 | wait(3); |
radhey04ec | 2:fab01e10358e | 482 | A.release(); |
radhey04ec | 2:fab01e10358e | 483 | wait(4); |
radhey04ec | 0:7945527e6a18 | 484 | NEXT = 1; |
radhey04ec | 0:7945527e6a18 | 485 | |
radhey04ec | 0:7945527e6a18 | 486 | } |
radhey04ec | 0:7945527e6a18 | 487 | if(NEXT ==1)//*****************************BATTERY VOLTAGE TEST |
radhey04ec | 0:7945527e6a18 | 488 | { |
radhey04ec | 2:fab01e10358e | 489 | uint32_t G_VAL = 0; |
radhey04ec | 2:fab01e10358e | 490 | float vol = 0; |
radhey04ec | 0:7945527e6a18 | 491 | NEXT =0; |
radhey04ec | 0:7945527e6a18 | 492 | ERROR_FLAG = 0; |
radhey04ec | 0:7945527e6a18 | 493 | lcd.locate(0,1); |
radhey04ec | 0:7945527e6a18 | 494 | lcd.printf(" "); |
radhey04ec | 0:7945527e6a18 | 495 | lcd.locate(0,2); |
radhey04ec | 0:7945527e6a18 | 496 | lcd.printf(" "); |
radhey04ec | 0:7945527e6a18 | 497 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 498 | lcd.printf(" "); |
radhey04ec | 0:7945527e6a18 | 499 | lcd.locate(0,0); |
radhey04ec | 2:fab01e10358e | 500 | lcd.printf("Voltage Test ON"); |
radhey04ec | 0:7945527e6a18 | 501 | pc.printf("\n VOLTAGE TEST BEGIN"); |
radhey04ec | 0:7945527e6a18 | 502 | BUFFER_CLEAR(); |
radhey04ec | 0:7945527e6a18 | 503 | UT.putc('A'); |
radhey04ec | 0:7945527e6a18 | 504 | A.release(); |
radhey04ec | 0:7945527e6a18 | 505 | wait(1); |
radhey04ec | 0:7945527e6a18 | 506 | response(); |
radhey04ec | 2:fab01e10358e | 507 | //DECODE DATA >>>>>>>>>>>>>>>>>>>>>>>BATTERY VOLTAGE <<<<<<<<<<<<<<<<<<< |
radhey04ec | 2:fab01e10358e | 508 | { |
radhey04ec | 2:fab01e10358e | 509 | uint8_t b=0; |
radhey04ec | 2:fab01e10358e | 510 | char temp_buf[5]; |
radhey04ec | 2:fab01e10358e | 511 | pc.puts("\n \n \n DECODE BATTERY VOLTAGE: "); |
radhey04ec | 2:fab01e10358e | 512 | for(b=1;b<5;b++) |
radhey04ec | 2:fab01e10358e | 513 | { |
radhey04ec | 2:fab01e10358e | 514 | pc.putc(rxBuffer[b]); |
radhey04ec | 2:fab01e10358e | 515 | temp_buf[b-1] = rxBuffer[b]; |
radhey04ec | 2:fab01e10358e | 516 | } |
radhey04ec | 2:fab01e10358e | 517 | temp_buf[4] = '\n'; |
radhey04ec | 2:fab01e10358e | 518 | |
radhey04ec | 2:fab01e10358e | 519 | //*****************************HEX TO DEC******************************* |
radhey04ec | 2:fab01e10358e | 520 | { |
radhey04ec | 2:fab01e10358e | 521 | int base = 1; |
radhey04ec | 2:fab01e10358e | 522 | |
radhey04ec | 2:fab01e10358e | 523 | int dec_val = 0; |
radhey04ec | 2:fab01e10358e | 524 | int i1; |
radhey04ec | 2:fab01e10358e | 525 | |
radhey04ec | 2:fab01e10358e | 526 | // Extracting characters as digits from last character |
radhey04ec | 2:fab01e10358e | 527 | for (i1=3; i1>=0; i1--) |
radhey04ec | 2:fab01e10358e | 528 | { |
radhey04ec | 2:fab01e10358e | 529 | // if character lies in '0'-'9', converting |
radhey04ec | 2:fab01e10358e | 530 | // it to integral 0-9 by subtracting 48 from |
radhey04ec | 2:fab01e10358e | 531 | // ASCII value. |
radhey04ec | 2:fab01e10358e | 532 | if (temp_buf[i1]>='0' && temp_buf[i1]<='9') |
radhey04ec | 2:fab01e10358e | 533 | { |
radhey04ec | 2:fab01e10358e | 534 | dec_val += (temp_buf[i1] - 48)*base; |
radhey04ec | 2:fab01e10358e | 535 | |
radhey04ec | 2:fab01e10358e | 536 | // incrementing base by power |
radhey04ec | 2:fab01e10358e | 537 | base = base * 16; |
radhey04ec | 2:fab01e10358e | 538 | } |
radhey04ec | 2:fab01e10358e | 539 | |
radhey04ec | 2:fab01e10358e | 540 | // if character lies in 'A'-'F' , converting |
radhey04ec | 2:fab01e10358e | 541 | // it to integral 10 - 15 by subtracting 55 |
radhey04ec | 2:fab01e10358e | 542 | // from ASCII value |
radhey04ec | 2:fab01e10358e | 543 | else if (temp_buf[i1]>='A' && temp_buf[i1]<='F') |
radhey04ec | 2:fab01e10358e | 544 | { |
radhey04ec | 2:fab01e10358e | 545 | dec_val += (temp_buf[i1] - 55)*base; |
radhey04ec | 2:fab01e10358e | 546 | base = base*16; |
radhey04ec | 2:fab01e10358e | 547 | } |
radhey04ec | 2:fab01e10358e | 548 | |
radhey04ec | 2:fab01e10358e | 549 | } |
radhey04ec | 2:fab01e10358e | 550 | pc.printf("\n value = %d",dec_val); |
radhey04ec | 2:fab01e10358e | 551 | G_VAL = dec_val; |
radhey04ec | 2:fab01e10358e | 552 | } |
radhey04ec | 2:fab01e10358e | 553 | } |
radhey04ec | 2:fab01e10358e | 554 | pc.printf("\n GVAL %d",G_VAL); |
radhey04ec | 2:fab01e10358e | 555 | float T1; |
radhey04ec | 2:fab01e10358e | 556 | T1 = (float)(G_VAL/65535.0); |
radhey04ec | 2:fab01e10358e | 557 | pc.printf("\n T1 = %f",T1); |
radhey04ec | 2:fab01e10358e | 558 | float T2; |
radhey04ec | 2:fab01e10358e | 559 | T2 = (float)(T1*3.6); |
radhey04ec | 2:fab01e10358e | 560 | pc.printf("\n T2 = %f",T2); |
radhey04ec | 2:fab01e10358e | 561 | vol = (23.68 * (T2/10)); |
radhey04ec | 2:fab01e10358e | 562 | pc.printf("\n VOLTAGE LEVEL = %f",vol); |
radhey04ec | 2:fab01e10358e | 563 | lcd.locate(0,2); |
radhey04ec | 2:fab01e10358e | 564 | lcd.printf(" "); |
radhey04ec | 2:fab01e10358e | 565 | lcd.locate(0,2); |
radhey04ec | 2:fab01e10358e | 566 | lcd.printf("Voltage = %.2f V",vol); |
radhey04ec | 2:fab01e10358e | 567 | G_VAL = 0; |
radhey04ec | 2:fab01e10358e | 568 | BUFFER_CLEAR(); |
radhey04ec | 2:fab01e10358e | 569 | wait(5); |
radhey04ec | 2:fab01e10358e | 570 | if(vol >= 6 || vol <= 4.5) |
radhey04ec | 2:fab01e10358e | 571 | { |
radhey04ec | 2:fab01e10358e | 572 | NEXT = 0; |
radhey04ec | 2:fab01e10358e | 573 | ERROR_FLAG = 1; |
radhey04ec | 2:fab01e10358e | 574 | error(10); |
radhey04ec | 2:fab01e10358e | 575 | } |
radhey04ec | 2:fab01e10358e | 576 | else |
radhey04ec | 2:fab01e10358e | 577 | { |
radhey04ec | 0:7945527e6a18 | 578 | NEXT = 1; |
radhey04ec | 2:fab01e10358e | 579 | ERROR_FLAG = 0; |
radhey04ec | 2:fab01e10358e | 580 | } |
radhey04ec | 0:7945527e6a18 | 581 | |
radhey04ec | 0:7945527e6a18 | 582 | |
radhey04ec | 0:7945527e6a18 | 583 | } |
radhey04ec | 1:bdc3ebd4e52b | 584 | if(NEXT == 1)// ********************************* CURRENT TEST |
radhey04ec | 1:bdc3ebd4e52b | 585 | { |
radhey04ec | 1:bdc3ebd4e52b | 586 | lcd.locate(0,0); |
radhey04ec | 1:bdc3ebd4e52b | 587 | BUFFER_CLEAR(); |
radhey04ec | 1:bdc3ebd4e52b | 588 | NEXT = 0; |
radhey04ec | 1:bdc3ebd4e52b | 589 | pc.printf("\n CURRENT TEST START"); |
radhey04ec | 1:bdc3ebd4e52b | 590 | A.release(); |
radhey04ec | 2:fab01e10358e | 591 | wait(2); |
radhey04ec | 1:bdc3ebd4e52b | 592 | CURRENT(); |
radhey04ec | 1:bdc3ebd4e52b | 593 | lcd.locate(0,1); |
radhey04ec | 1:bdc3ebd4e52b | 594 | lcd.printf(" "); |
radhey04ec | 1:bdc3ebd4e52b | 595 | lcd.locate(0,1); |
radhey04ec | 1:bdc3ebd4e52b | 596 | lcd.printf("CURRENT = %f",current); |
radhey04ec | 1:bdc3ebd4e52b | 597 | if(current > 6.5) |
radhey04ec | 1:bdc3ebd4e52b | 598 | { |
radhey04ec | 2:fab01e10358e | 599 | CURRENT(); |
radhey04ec | 2:fab01e10358e | 600 | wait(2); |
radhey04ec | 2:fab01e10358e | 601 | } |
radhey04ec | 2:fab01e10358e | 602 | if(current > 6.5) |
radhey04ec | 2:fab01e10358e | 603 | { |
radhey04ec | 1:bdc3ebd4e52b | 604 | error(2); |
radhey04ec | 1:bdc3ebd4e52b | 605 | NEXT = 0; |
radhey04ec | 2:fab01e10358e | 606 | ERROR_FLAG = 1; |
radhey04ec | 1:bdc3ebd4e52b | 607 | } |
radhey04ec | 1:bdc3ebd4e52b | 608 | else |
radhey04ec | 1:bdc3ebd4e52b | 609 | { |
radhey04ec | 1:bdc3ebd4e52b | 610 | |
radhey04ec | 1:bdc3ebd4e52b | 611 | NEXT = 1; |
radhey04ec | 1:bdc3ebd4e52b | 612 | ERROR_FLAG = 0; |
radhey04ec | 1:bdc3ebd4e52b | 613 | } |
radhey04ec | 1:bdc3ebd4e52b | 614 | |
radhey04ec | 1:bdc3ebd4e52b | 615 | } |
radhey04ec | 1:bdc3ebd4e52b | 616 | |
radhey04ec | 0:7945527e6a18 | 617 | //END OF TEST -- NO NEED TO CHECK NEXT FLAG |
radhey04ec | 0:7945527e6a18 | 618 | UT.putc('Q'); |
radhey04ec | 0:7945527e6a18 | 619 | wait(1); |
radhey04ec | 0:7945527e6a18 | 620 | BUFFER_CLEAR(); |
radhey04ec | 0:7945527e6a18 | 621 | |
radhey04ec | 0:7945527e6a18 | 622 | if(ERROR_FLAG == 0) |
radhey04ec | 0:7945527e6a18 | 623 | { |
radhey04ec | 0:7945527e6a18 | 624 | result(); |
radhey04ec | 0:7945527e6a18 | 625 | } |
radhey04ec | 0:7945527e6a18 | 626 | |
radhey04ec | 0:7945527e6a18 | 627 | } //OUTER SIDE BEGIN |
radhey04ec | 0:7945527e6a18 | 628 | TEST_FLAG = 0U; |
radhey04ec | 0:7945527e6a18 | 629 | PROCESS_FLAG = 0U; |
radhey04ec | 0:7945527e6a18 | 630 | GREEN_LED = 0U; |
radhey04ec | 0:7945527e6a18 | 631 | RED_LED = 0U; |
radhey04ec | 0:7945527e6a18 | 632 | NEXT = 0; |
radhey04ec | 0:7945527e6a18 | 633 | ERROR_FLAG =0; |
radhey04ec | 0:7945527e6a18 | 634 | |
radhey04ec | 0:7945527e6a18 | 635 | } |
radhey04ec | 0:7945527e6a18 | 636 | void result() |
radhey04ec | 0:7945527e6a18 | 637 | { |
radhey04ec | 0:7945527e6a18 | 638 | { |
radhey04ec | 0:7945527e6a18 | 639 | wait(3); |
radhey04ec | 0:7945527e6a18 | 640 | lcd.cls(); |
radhey04ec | 0:7945527e6a18 | 641 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 642 | lcd.printf("TEST SUCCESSFUL OK"); |
radhey04ec | 0:7945527e6a18 | 643 | lcd.locate(0,1); |
radhey04ec | 0:7945527e6a18 | 644 | lcd.printf("BOARD TEST - PASS"); |
radhey04ec | 0:7945527e6a18 | 645 | lcd.locate(0,2); |
radhey04ec | 0:7945527e6a18 | 646 | lcd.printf("PLUG NEW BOARD"); |
radhey04ec | 0:7945527e6a18 | 647 | lcd.locate(0,3); |
radhey04ec | 0:7945527e6a18 | 648 | lcd.printf("Total Test = %u",PCB_COUNTER); |
radhey04ec | 0:7945527e6a18 | 649 | GREEN_LED =1; |
radhey04ec | 0:7945527e6a18 | 650 | RED_LED =0; |
radhey04ec | 0:7945527e6a18 | 651 | BLUE_LED =0; |
radhey04ec | 0:7945527e6a18 | 652 | BUZZER = 1; |
radhey04ec | 2:fab01e10358e | 653 | wait(0.5); |
radhey04ec | 0:7945527e6a18 | 654 | BUZZER =0; |
radhey04ec | 0:7945527e6a18 | 655 | wait(3); |
radhey04ec | 0:7945527e6a18 | 656 | } |
radhey04ec | 0:7945527e6a18 | 657 | |
radhey04ec | 0:7945527e6a18 | 658 | //AT END OF PROCESS |
radhey04ec | 0:7945527e6a18 | 659 | TEST_FLAG = 0U; |
radhey04ec | 0:7945527e6a18 | 660 | PROCESS_FLAG = 0U; |
radhey04ec | 0:7945527e6a18 | 661 | GREEN_LED = 1U; |
radhey04ec | 0:7945527e6a18 | 662 | pc.printf("\n PCB AXV 001 TEST COMPLETED : TEST STATUS - PASS \n"); |
radhey04ec | 0:7945527e6a18 | 663 | pc.printf("\n ******************************END OF TEST************************************ \n"); |
radhey04ec | 2:fab01e10358e | 664 | pc.printf("Total Test = %u",PCB_COUNTER); |
radhey04ec | 0:7945527e6a18 | 665 | pc.printf("\n \n \n"); |
radhey04ec | 0:7945527e6a18 | 666 | pc.printf("\n PLUG NEW BOARD AND PRESS THE BUTTON"); |
radhey04ec | 0:7945527e6a18 | 667 | pc.printf("\n \n \n"); |
radhey04ec | 0:7945527e6a18 | 668 | wait(5); |
radhey04ec | 0:7945527e6a18 | 669 | |
radhey04ec | 0:7945527e6a18 | 670 | } |
radhey04ec | 0:7945527e6a18 | 671 | |
radhey04ec | 0:7945527e6a18 | 672 | void error(uint8_t error_number) |
radhey04ec | 0:7945527e6a18 | 673 | { |
radhey04ec | 0:7945527e6a18 | 674 | { |
radhey04ec | 0:7945527e6a18 | 675 | RED_LED=1; |
radhey04ec | 0:7945527e6a18 | 676 | GREEN_LED=0; |
radhey04ec | 0:7945527e6a18 | 677 | BLUE_LED=0; |
radhey04ec | 0:7945527e6a18 | 678 | BUZZER = 1; |
radhey04ec | 2:fab01e10358e | 679 | wait(3); |
radhey04ec | 0:7945527e6a18 | 680 | BUZZER =0; |
radhey04ec | 0:7945527e6a18 | 681 | lcd.cls(); |
radhey04ec | 0:7945527e6a18 | 682 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 683 | lcd.printf("Oops ..ERROR"); |
radhey04ec | 0:7945527e6a18 | 684 | pc.printf("\n Test Fail "); |
radhey04ec | 0:7945527e6a18 | 685 | pc.printf("\n Error -- Contact to HOD"); |
radhey04ec | 0:7945527e6a18 | 686 | lcd.locate(0,2); |
radhey04ec | 0:7945527e6a18 | 687 | lcd.printf("PLUG NEW BOARD"); |
radhey04ec | 0:7945527e6a18 | 688 | lcd.locate(0,3); |
radhey04ec | 0:7945527e6a18 | 689 | lcd.printf("Total Test = %u",PCB_COUNTER); |
radhey04ec | 0:7945527e6a18 | 690 | if(error_number == 1) |
radhey04ec | 0:7945527e6a18 | 691 | { |
radhey04ec | 0:7945527e6a18 | 692 | lcd.locate(0,1); |
radhey04ec | 0:7945527e6a18 | 693 | lcd.printf("WRONG VERSION"); |
radhey04ec | 0:7945527e6a18 | 694 | pc.printf("\n ERROR CODE = 0x1"); |
radhey04ec | 0:7945527e6a18 | 695 | pc.printf("\n WRONG VERSION OF SOFTWARE , PLEASE CHECK"); |
radhey04ec | 0:7945527e6a18 | 696 | pc.printf("\n POSSIBLE SOLUTION \n"); |
radhey04ec | 0:7945527e6a18 | 697 | pc.printf("\n 1) REPROGRAM BOARD 2) CHECK SUPPLY VOLTAGE "); |
radhey04ec | 0:7945527e6a18 | 698 | wait(3); |
radhey04ec | 0:7945527e6a18 | 699 | } |
radhey04ec | 0:7945527e6a18 | 700 | if(error_number == 2) |
radhey04ec | 0:7945527e6a18 | 701 | { |
radhey04ec | 0:7945527e6a18 | 702 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 703 | lcd.printf(" "); |
radhey04ec | 2:fab01e10358e | 704 | lcd.locate(0,1); |
radhey04ec | 0:7945527e6a18 | 705 | lcd.printf("OVER CURRENT "); |
radhey04ec | 0:7945527e6a18 | 706 | pc.printf("\n ERROR CODE = 0X2"); |
radhey04ec | 0:7945527e6a18 | 707 | pc.printf("\n OVER CURRENT ERROR"); |
radhey04ec | 0:7945527e6a18 | 708 | pc.printf("\n POSSIBLE SOLUTION"); |
radhey04ec | 0:7945527e6a18 | 709 | pc.printf("\n TRY TO WASH BOARD AGAIN and RECHECK"); |
radhey04ec | 2:fab01e10358e | 710 | wait(10); |
radhey04ec | 2:fab01e10358e | 711 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 712 | lcd.printf(""); |
radhey04ec | 2:fab01e10358e | 713 | CURRENT(); |
radhey04ec | 2:fab01e10358e | 714 | A.release(); |
radhey04ec | 2:fab01e10358e | 715 | wait(10); |
radhey04ec | 2:fab01e10358e | 716 | |
radhey04ec | 0:7945527e6a18 | 717 | } |
radhey04ec | 1:bdc3ebd4e52b | 718 | if(error_number == 5) |
radhey04ec | 1:bdc3ebd4e52b | 719 | { |
radhey04ec | 1:bdc3ebd4e52b | 720 | pc.printf("\n ERROR NUMBER = 0X5"); |
radhey04ec | 1:bdc3ebd4e52b | 721 | pc.printf("\n RED LED DETECTION FAIL"); |
radhey04ec | 2:fab01e10358e | 722 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 723 | lcd.printf(" "); |
radhey04ec | 2:fab01e10358e | 724 | lcd.locate(0,1); |
radhey04ec | 1:bdc3ebd4e52b | 725 | lcd.printf("LED TEST FAIL"); |
radhey04ec | 1:bdc3ebd4e52b | 726 | A.release(); |
radhey04ec | 1:bdc3ebd4e52b | 727 | wait(1); |
radhey04ec | 1:bdc3ebd4e52b | 728 | pc.printf("\n POSSIBLE SOLUTION"); |
radhey04ec | 1:bdc3ebd4e52b | 729 | pc.printf("\n 1) CHECK LED MANUALLY - IF IT IS IN ON STATE PLEASE ADJUST SENSOR POSITION "); |
radhey04ec | 1:bdc3ebd4e52b | 730 | pc.printf("\n Contact to R&D DEPT. for Hardare Amendement"); |
radhey04ec | 1:bdc3ebd4e52b | 731 | pc.printf("\n 2) If LED is not working state - check polarity"); |
radhey04ec | 1:bdc3ebd4e52b | 732 | pc.printf("\n contact to HOD"); |
radhey04ec | 1:bdc3ebd4e52b | 733 | |
radhey04ec | 1:bdc3ebd4e52b | 734 | } |
radhey04ec | 2:fab01e10358e | 735 | if(error_number == 7) |
radhey04ec | 2:fab01e10358e | 736 | { |
radhey04ec | 2:fab01e10358e | 737 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 738 | lcd.printf(" "); |
radhey04ec | 2:fab01e10358e | 739 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 740 | lcd.printf("LED Curr. Outer range"); |
radhey04ec | 2:fab01e10358e | 741 | pc.printf("\n LED TAKING OUTER RANGE CURRENT \n"); |
radhey04ec | 2:fab01e10358e | 742 | A.release(); |
radhey04ec | 2:fab01e10358e | 743 | wait(2); |
radhey04ec | 2:fab01e10358e | 744 | |
radhey04ec | 2:fab01e10358e | 745 | } |
radhey04ec | 2:fab01e10358e | 746 | if(error_number == 10) |
radhey04ec | 2:fab01e10358e | 747 | { |
radhey04ec | 2:fab01e10358e | 748 | pc.printf("\n SUPPLY VOLTAGE ERROR \n"); |
radhey04ec | 2:fab01e10358e | 749 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 750 | lcd.printf(" "); |
radhey04ec | 2:fab01e10358e | 751 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 752 | lcd.printf("SUPP. VOLTAGE ERROR"); |
radhey04ec | 2:fab01e10358e | 753 | wait(5); |
radhey04ec | 2:fab01e10358e | 754 | } |
radhey04ec | 0:7945527e6a18 | 755 | |
radhey04ec | 0:7945527e6a18 | 756 | } |
radhey04ec | 0:7945527e6a18 | 757 | |
radhey04ec | 0:7945527e6a18 | 758 | //AT END OF PROCESS |
radhey04ec | 0:7945527e6a18 | 759 | TEST_FLAG = 0U; |
radhey04ec | 0:7945527e6a18 | 760 | PROCESS_FLAG = 0U; |
radhey04ec | 0:7945527e6a18 | 761 | RED_LED =1; |
radhey04ec | 0:7945527e6a18 | 762 | BUZZER = 1; |
radhey04ec | 0:7945527e6a18 | 763 | NEXT = 0; |
radhey04ec | 0:7945527e6a18 | 764 | //ERROR_FLAG =0; |
radhey04ec | 0:7945527e6a18 | 765 | wait(3); |
radhey04ec | 0:7945527e6a18 | 766 | BUZZER =0; |
radhey04ec | 0:7945527e6a18 | 767 | pc.printf("\n *******************ERROR DESCRIPTION END **************************"); |
radhey04ec | 0:7945527e6a18 | 768 | pc.printf("\n ***************************END OF TEST ****************************"); |
radhey04ec | 0:7945527e6a18 | 769 | } |
radhey04ec | 0:7945527e6a18 | 770 | |
radhey04ec | 0:7945527e6a18 | 771 | void WELCOME_SCREEN() |
radhey04ec | 0:7945527e6a18 | 772 | { |
radhey04ec | 0:7945527e6a18 | 773 | pc.printf("\n"); |
radhey04ec | 0:7945527e6a18 | 774 | pc.printf("AXV GOLBAL VALVE TESTER -- FOLLOW THE STEPS \n"); |
radhey04ec | 0:7945527e6a18 | 775 | |
radhey04ec | 0:7945527e6a18 | 776 | RED_LED = 1; |
radhey04ec | 0:7945527e6a18 | 777 | GREEN_LED = 1; |
radhey04ec | 0:7945527e6a18 | 778 | BLUE_LED =1; |
radhey04ec | 0:7945527e6a18 | 779 | BUZZER = 1; |
radhey04ec | 0:7945527e6a18 | 780 | wait(1); |
radhey04ec | 0:7945527e6a18 | 781 | BUZZER = 0; |
radhey04ec | 0:7945527e6a18 | 782 | |
radhey04ec | 0:7945527e6a18 | 783 | |
radhey04ec | 0:7945527e6a18 | 784 | //WELCOME SCREEN DATA |
radhey04ec | 0:7945527e6a18 | 785 | lcd.cls(); //clear the screen first |
radhey04ec | 0:7945527e6a18 | 786 | lcd.printf(" Welcome !!!"); |
radhey04ec | 0:7945527e6a18 | 787 | lcd.locate(0,1); |
radhey04ec | 0:7945527e6a18 | 788 | lcd.printf("GLOBAL V- TESTER"); |
radhey04ec | 0:7945527e6a18 | 789 | lcd.locate(0,2); |
radhey04ec | 0:7945527e6a18 | 790 | lcd.printf("POWERED BY : KEPL "); |
radhey04ec | 0:7945527e6a18 | 791 | lcd.locate(0,3); |
radhey04ec | 0:7945527e6a18 | 792 | lcd.printf("R_AND_D DEPARTMENT"); |
radhey04ec | 0:7945527e6a18 | 793 | wait(5); |
radhey04ec | 0:7945527e6a18 | 794 | lcd.cls(); |
radhey04ec | 0:7945527e6a18 | 795 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 796 | lcd.printf("Loading..."); |
radhey04ec | 0:7945527e6a18 | 797 | lcd.locate(11,0); |
radhey04ec | 0:7945527e6a18 | 798 | pc.printf("\n DATA LOADING ....."); |
radhey04ec | 0:7945527e6a18 | 799 | pc.printf("\n Veryfying...."); |
radhey04ec | 0:7945527e6a18 | 800 | wait_ms(500); |
radhey04ec | 0:7945527e6a18 | 801 | lcd.printf("."); |
radhey04ec | 0:7945527e6a18 | 802 | lcd.locate(12,0); |
radhey04ec | 0:7945527e6a18 | 803 | wait_ms(500); |
radhey04ec | 0:7945527e6a18 | 804 | lcd.printf("..."); |
radhey04ec | 0:7945527e6a18 | 805 | wait_ms(1000); |
radhey04ec | 0:7945527e6a18 | 806 | lcd.locate(13,0); |
radhey04ec | 0:7945527e6a18 | 807 | lcd.printf(".."); |
radhey04ec | 0:7945527e6a18 | 808 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 809 | lcd.printf("INITIALIZATION..."); |
radhey04ec | 2:fab01e10358e | 810 | wait_ms(4000); |
radhey04ec | 0:7945527e6a18 | 811 | pc.printf("\n LCD COMMUNICATION Successful \n"); |
radhey04ec | 0:7945527e6a18 | 812 | lcd.cls(); |
radhey04ec | 0:7945527e6a18 | 813 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 814 | lcd.printf("Done !!!!"); |
radhey04ec | 0:7945527e6a18 | 815 | lcd.locate(0,1); |
radhey04ec | 0:7945527e6a18 | 816 | lcd.printf("TEST MODE ON"); |
radhey04ec | 0:7945527e6a18 | 817 | lcd.locate(0,2); |
radhey04ec | 0:7945527e6a18 | 818 | lcd.printf("COUNT = 0"); |
radhey04ec | 0:7945527e6a18 | 819 | wait_ms(5000); |
radhey04ec | 0:7945527e6a18 | 820 | lcd.cls(); |
radhey04ec | 0:7945527e6a18 | 821 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 822 | BLUE_LED = 1; |
radhey04ec | 0:7945527e6a18 | 823 | BUZZER = 1; |
radhey04ec | 0:7945527e6a18 | 824 | wait_ms(250); |
radhey04ec | 0:7945527e6a18 | 825 | BUZZER = 0; |
radhey04ec | 0:7945527e6a18 | 826 | pc.printf("\n SOFTWARE CHECKED & READY TO USE \n"); |
radhey04ec | 0:7945527e6a18 | 827 | pc.printf("\n ESD PROTECTION REQUIRE"); |
radhey04ec | 0:7945527e6a18 | 828 | pc.printf("\n KEEP YOUR EYES ON TERMINAL OR ON LCD"); |
radhey04ec | 0:7945527e6a18 | 829 | pc.printf("\n LED VISUAL AND BUZZER SOUND INDICATION HELPS YOU !!!"); |
radhey04ec | 0:7945527e6a18 | 830 | lcd.printf("AXV -T"); |
radhey04ec | 0:7945527e6a18 | 831 | lcd.locate(10,0); |
radhey04ec | 0:7945527e6a18 | 832 | lcd.printf("Count %u",PCB_COUNTER); |
radhey04ec | 0:7945527e6a18 | 833 | |
radhey04ec | 0:7945527e6a18 | 834 | } |
radhey04ec | 0:7945527e6a18 | 835 | |
radhey04ec | 0:7945527e6a18 | 836 | void NEW_TEST_UPDATE_LCD() |
radhey04ec | 0:7945527e6a18 | 837 | { |
radhey04ec | 0:7945527e6a18 | 838 | GREEN_LED = 1; |
radhey04ec | 0:7945527e6a18 | 839 | BLUE_LED = 1; |
radhey04ec | 0:7945527e6a18 | 840 | lcd.cls(); |
radhey04ec | 0:7945527e6a18 | 841 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 842 | lcd.printf("TESTING ON..."); |
radhey04ec | 0:7945527e6a18 | 843 | pc.printf("\n \n \n"); |
radhey04ec | 0:7945527e6a18 | 844 | pc.printf("\n NEW TEST START"); |
radhey04ec | 0:7945527e6a18 | 845 | wait(8); //8 SECOND |
radhey04ec | 0:7945527e6a18 | 846 | lcd.locate(0,1); |
radhey04ec | 2:fab01e10358e | 847 | lcd.printf("TEST SETUP ON"); |
radhey04ec | 0:7945527e6a18 | 848 | pc.printf("\n BOARD SCANNING..."); |
radhey04ec | 0:7945527e6a18 | 849 | wait(8); |
radhey04ec | 0:7945527e6a18 | 850 | lcd.locate(0,2); |
radhey04ec | 2:fab01e10358e | 851 | lcd.printf("MAKING CONNECTION"); |
radhey04ec | 0:7945527e6a18 | 852 | pc.printf("\n COMMUNICATION ESTABLISHMENT \n"); |
radhey04ec | 0:7945527e6a18 | 853 | wait(5); |
radhey04ec | 2:fab01e10358e | 854 | lcd.locate(0,3); |
radhey04ec | 2:fab01e10358e | 855 | lcd.printf("READY FOR TESTING"); |
radhey04ec | 0:7945527e6a18 | 856 | wait(5); |
radhey04ec | 0:7945527e6a18 | 857 | lcd.cls(); |
radhey04ec | 0:7945527e6a18 | 858 | lcd.locate(0,0); |
radhey04ec | 0:7945527e6a18 | 859 | lcd.printf("TEST MODE N 0%u",PCB_COUNTER); |
radhey04ec | 0:7945527e6a18 | 860 | pc.printf("TEST MODE ON - COUNT = %u",PCB_COUNTER); |
radhey04ec | 0:7945527e6a18 | 861 | A.release(); |
radhey04ec | 0:7945527e6a18 | 862 | wait(0.5); |
radhey04ec | 0:7945527e6a18 | 863 | |
radhey04ec | 0:7945527e6a18 | 864 | } |
radhey04ec | 0:7945527e6a18 | 865 | |
radhey04ec | 0:7945527e6a18 | 866 | /*Below Function is part of ISR ;so do not write big code inside it |
radhey04ec | 0:7945527e6a18 | 867 | If possible than only set and reset flag only |
radhey04ec | 0:7945527e6a18 | 868 | Because while servicing Interrupt OS can not schedule or switch other thread or Task |
radhey04ec | 0:7945527e6a18 | 869 | In future during updation of version please consider RTOS Management Rule |
radhey04ec | 0:7945527e6a18 | 870 | or contact Reserach & development team : JAYDEEP SHAH |
radhey04ec | 0:7945527e6a18 | 871 | */ |
radhey04ec | 0:7945527e6a18 | 872 | |
radhey04ec | 0:7945527e6a18 | 873 | void TEST_PROCESS() //This Function is connected with ISR Of Push_button |
radhey04ec | 0:7945527e6a18 | 874 | { |
radhey04ec | 0:7945527e6a18 | 875 | if(TEST_FLAG == 0U && PROCESS_FLAG == 0U) |
radhey04ec | 0:7945527e6a18 | 876 | { |
radhey04ec | 0:7945527e6a18 | 877 | TEST_FLAG = 1U; |
radhey04ec | 0:7945527e6a18 | 878 | } |
radhey04ec | 0:7945527e6a18 | 879 | else |
radhey04ec | 0:7945527e6a18 | 880 | { |
radhey04ec | 0:7945527e6a18 | 881 | TEST_FLAG = 0U; |
radhey04ec | 0:7945527e6a18 | 882 | |
radhey04ec | 0:7945527e6a18 | 883 | } |
radhey04ec | 0:7945527e6a18 | 884 | |
radhey04ec | 0:7945527e6a18 | 885 | } |
radhey04ec | 0:7945527e6a18 | 886 | void CURRENT() |
radhey04ec | 0:7945527e6a18 | 887 | { |
radhey04ec | 0:7945527e6a18 | 888 | for(int i =0;i <10 ; i++) //Array to make result smoother |
radhey04ec | 0:7945527e6a18 | 889 | { |
radhey04ec | 0:7945527e6a18 | 890 | AARAY[i] = ANG.read(); //Read the data |
radhey04ec | 0:7945527e6a18 | 891 | ThisThread::sleep_for(20); //Thread sleep for make ADC ready for next result |
radhey04ec | 0:7945527e6a18 | 892 | SUM = SUM + AARAY[i]; //Store result |
radhey04ec | 0:7945527e6a18 | 893 | } |
radhey04ec | 0:7945527e6a18 | 894 | float value = (SUM /10); //Finding Average value |
radhey04ec | 0:7945527e6a18 | 895 | |
radhey04ec | 0:7945527e6a18 | 896 | current = (((((((value)) * 3.3)-0.28)/200)/0.6)*1000); //Finding current |
radhey04ec | 0:7945527e6a18 | 897 | current = current + 2.5; // 2.5 is offset (when current is < 50 mA) |
radhey04ec | 0:7945527e6a18 | 898 | |
radhey04ec | 0:7945527e6a18 | 899 | //pc.printf("\n Current (mA) = %f",current); //Print data on Serial console -- I used CoolTerm |
radhey04ec | 0:7945527e6a18 | 900 | |
radhey04ec | 0:7945527e6a18 | 901 | SUM = 0; //At the end sum must be zero |
radhey04ec | 0:7945527e6a18 | 902 | //A.release(); |
radhey04ec | 0:7945527e6a18 | 903 | |
radhey04ec | 0:7945527e6a18 | 904 | } |
radhey04ec | 0:7945527e6a18 | 905 | |
radhey04ec | 0:7945527e6a18 | 906 | void BUFFER_CLEAR() |
radhey04ec | 0:7945527e6a18 | 907 | { |
radhey04ec | 0:7945527e6a18 | 908 | RxInterrupt(); // To clear serial buffer |
radhey04ec | 0:7945527e6a18 | 909 | i = 0U; |
radhey04ec | 0:7945527e6a18 | 910 | bufferReadingIndex = 0U; |
radhey04ec | 0:7945527e6a18 | 911 | for(int k =0; k<50 ; k++) // ****************CLEAR 50 BYTES BUFFER |
radhey04ec | 0:7945527e6a18 | 912 | { |
radhey04ec | 0:7945527e6a18 | 913 | rxBuffer[k] = ' '; |
radhey04ec | 0:7945527e6a18 | 914 | } |
radhey04ec | 0:7945527e6a18 | 915 | } |