Test program for testing ADC channels, and 2004 LED display functions of W7500ECO-based LINAC MO monitor board

Dependencies:   TextLCD WIZnetInterface mbed

Fork of TCP_LED_Control-WIZwiki-W7500 by Kiyong Lee

Committer:
mahengjie
Date:
Thu Dec 07 21:25:43 2017 +0000
Revision:
13:871176c55b12
Parent:
12:aee11a1d7f14
For testing ADC, 2004 LED display function of Wizwiki_W7500ECO based LINAC MO monitor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mahengjie 13:871176c55b12 1 // Test of ADC, and LED/LCD control of LINAC MO Monitor
mahengjie 13:871176c55b12 2 // Hengjie Ma
mahengjie 13:871176c55b12 3 // BNL, NSLS-II, RF
mahengjie 13:871176c55b12 4 // Nov. 2, 2017
mahengjie 13:871176c55b12 5 //
justinkim 8:f837e0d255e8 6 #include "mbed.h"
mahengjie 13:871176c55b12 7 #include "TextLCD.h"
mahengjie 13:871176c55b12 8 #include <stdio.h>
mahengjie 13:871176c55b12 9
mahengjie 13:871176c55b12 10 // Analog signal input channel gain scalling
mahengjie 13:871176c55b12 11 #define AIN_cal_CL1 1.0; // RFIN_500M
mahengjie 13:871176c55b12 12 #define AIN_cal_CL2 1.0; // SPB_500M
mahengjie 13:871176c55b12 13 #define AIN_cal_CL3 1.0; // GUN_500M
mahengjie 13:871176c55b12 14 #define AIN_cal_CL4 1.0; // PB_3G
mahengjie 13:871176c55b12 15 #define AIN_cal_CL5 1.0; // K1_3G
mahengjie 13:871176c55b12 16 #define AIN_cal_CL6 1.0; // K2_3G
mahengjie 13:871176c55b12 17 #define AIN_cal_OP1 1.0; // K3_3G
mahengjie 13:871176c55b12 18 #define AIN_cal_OP2 1.0; // 5V_OK
mahengjie 13:871176c55b12 19 #define AIN_cal_OP3 1.0; // 15V_OK
mahengjie 13:871176c55b12 20 #define AIN_cal_OP4 1.0; // AIN3_SPARE
mahengjie 13:871176c55b12 21 #define AIN_cal_OP5 1.0; // AIN6_SPARE
mahengjie 13:871176c55b12 22 #define AIN_cal_OP6 1.0; // AIN7_SPARE
mahengjie 13:871176c55b12 23
mahengjie 13:871176c55b12 24 const char * msg[] = {
mahengjie 13:871176c55b12 25 "RFIN500M ",
mahengjie 13:871176c55b12 26 "SPB500M ",
mahengjie 13:871176c55b12 27 "GUN500M ",
mahengjie 13:871176c55b12 28 "PB_3G ",
mahengjie 13:871176c55b12 29 "K1_3G ",
mahengjie 13:871176c55b12 30 "K2_3G ",
mahengjie 13:871176c55b12 31 "K3_3G ",
mahengjie 13:871176c55b12 32 "5V_OK ",
mahengjie 13:871176c55b12 33 "15V_OK ",
mahengjie 13:871176c55b12 34 "AIN3_xxx ",
mahengjie 13:871176c55b12 35 "AIN6_xxx ",
mahengjie 13:871176c55b12 36 "AIN7_xxx "
mahengjie 13:871176c55b12 37 };
mahengjie 13:871176c55b12 38
mahengjie 13:871176c55b12 39 char trailer[16] = "me too !!!"; // test string
hjjeon 9:a63ff95c354b 40
mahengjie 13:871176c55b12 41 // I/O pin assignment
mahengjie 13:871176c55b12 42 DigitalOut myled(LED1); // on-board blue LED, an idiot light for TCP sanity check
mahengjie 13:871176c55b12 43 // Primary group of analog inputs
mahengjie 13:871176c55b12 44 AnalogIn AIN0(P30); // AIN0, RFIN_500M/K3_3G
mahengjie 13:871176c55b12 45 AnalogIn AIN1(P29); // AIN1, SPB_500M/5V_OK
mahengjie 13:871176c55b12 46 AnalogIn AIN2(P28); // AIN2, GUN_500M/15V_OK
mahengjie 13:871176c55b12 47 AnalogIn AIN3(P27); // AIN3, PB_3G/AIN3_SPARE
mahengjie 13:871176c55b12 48 AnalogIn AIN6(P26); // AIN6, K1_3G/AIN6_SPARE
mahengjie 13:871176c55b12 49 AnalogIn AIN7(P25); // AIN7, K2_3G/AIN7_SPARE
mahengjie 13:871176c55b12 50 DigitalOut MUX_CTL(P11); // PA11,
mahengjie 13:871176c55b12 51
mahengjie 13:871176c55b12 52 // TextLCD lcd(P9, P10, P5,P6, P7, P8, TextLCD::LCD20x4D, NC, NC, TextLCD::US2066_3V3); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=US2066
mahengjie 13:871176c55b12 53 TextLCD lcd(P9, P10, P5,P8, P7, P6, TextLCD::LCD20x4D, NC, NC, TextLCD::US2066_3V3); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=US2066
mahengjie 13:871176c55b12 54 float meas[12];
mahengjie 13:871176c55b12 55 int idx, row, col;
hjjeon 9:a63ff95c354b 56
mahengjie 13:871176c55b12 57 void adc()
mahengjie 13:871176c55b12 58 {
mahengjie 13:871176c55b12 59 // Update data
mahengjie 13:871176c55b12 60 MUX_CTL = 0; // group 1
mahengjie 13:871176c55b12 61 meas[0] = AIN0.read() * AIN_cal_CL1;
mahengjie 13:871176c55b12 62 meas[1] = AIN1.read() * AIN_cal_CL2;
mahengjie 13:871176c55b12 63 meas[2] = AIN2.read() * AIN_cal_CL3;
mahengjie 13:871176c55b12 64 meas[3] = AIN3.read() * AIN_cal_CL4;
mahengjie 13:871176c55b12 65 meas[4] = AIN6.read() * AIN_cal_CL5;
mahengjie 13:871176c55b12 66 meas[5] = AIN7.read() * AIN_cal_CL6;
mahengjie 13:871176c55b12 67 MUX_CTL = 1; // group 2
mahengjie 13:871176c55b12 68 meas[6] = AIN0.read() * AIN_cal_OP1;
mahengjie 13:871176c55b12 69 meas[7] = AIN1.read() * AIN_cal_OP2;
mahengjie 13:871176c55b12 70 meas[8] = AIN2.read() * AIN_cal_OP3;
mahengjie 13:871176c55b12 71 meas[9] = AIN3.read() * AIN_cal_OP4;
mahengjie 13:871176c55b12 72 meas[10] = AIN6.read() * AIN_cal_OP5;
mahengjie 13:871176c55b12 73 meas[11] = AIN7.read() * AIN_cal_OP6;
mahengjie 13:871176c55b12 74 }
kzl108 12:aee11a1d7f14 75
mahengjie 13:871176c55b12 76 void display()
mahengjie 13:871176c55b12 77 {
mahengjie 13:871176c55b12 78 // update 20x4 LED/LCD display, rolling
mahengjie 13:871176c55b12 79 lcd.cls();
mahengjie 13:871176c55b12 80 for ( idx = 0; idx < 12; idx++)
mahengjie 13:871176c55b12 81 {
mahengjie 13:871176c55b12 82 // lcd.locate(col,row);
mahengjie 13:871176c55b12 83 printf("%s %.2f V \r\n", msg[idx], meas[idx]); // serial console
mahengjie 13:871176c55b12 84 lcd.printf("%s %.2f V \r\n",msg[idx], meas[idx]); // LCD/LED
mahengjie 13:871176c55b12 85 wait(0.1); // per line
mahengjie 13:871176c55b12 86 if (row < 3)
mahengjie 13:871176c55b12 87 {
mahengjie 13:871176c55b12 88 row = row + 1;
mahengjie 13:871176c55b12 89 lcd.locate(col,row);
mahengjie 13:871176c55b12 90 }
mahengjie 13:871176c55b12 91 else
mahengjie 13:871176c55b12 92 {
mahengjie 13:871176c55b12 93 row = 0;
mahengjie 13:871176c55b12 94 wait(1.0); // pause after each frame of 4 lines
mahengjie 13:871176c55b12 95 lcd.cls();
mahengjie 13:871176c55b12 96 }
mahengjie 13:871176c55b12 97 }
mahengjie 13:871176c55b12 98 // wait(1.0); // every 4-screen, 12-line total, refresh
mahengjie 13:871176c55b12 99 }
kzl108 12:aee11a1d7f14 100
hjjeon 11:0da8667a9201 101 int main (void)
justinkim 8:f837e0d255e8 102 {
mahengjie 13:871176c55b12 103 row = 0;
mahengjie 13:871176c55b12 104 col = 0;
mahengjie 13:871176c55b12 105 printf("Test of ADC and LCD .....\r\n");
mahengjie 13:871176c55b12 106 while(true)
hjjeon 11:0da8667a9201 107 {
mahengjie 13:871176c55b12 108 // get new data
mahengjie 13:871176c55b12 109 adc();
mahengjie 13:871176c55b12 110 // display on serial terminal and LCD
mahengjie 13:871176c55b12 111 display();
mahengjie 13:871176c55b12 112 }
mahengjie 13:871176c55b12 113 }
kzl108 12:aee11a1d7f14 114
kzl108 12:aee11a1d7f14 115