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
Revision 13:871176c55b12, committed 2017-12-07
- Comitter:
- mahengjie
- Date:
- Thu Dec 07 21:25:43 2017 +0000
- Parent:
- 12:aee11a1d7f14
- Commit message:
- For testing ADC, 2004 LED display function of Wizwiki_W7500ECO based LINAC MO monitor
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Thu Dec 07 21:25:43 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/V8/code/TextLCD/#8d296e48e6a7
--- a/WIZnetInterface.lib Mon Jul 20 07:54:18 2015 +0000 +++ b/WIZnetInterface.lib Thu Dec 07 21:25:43 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#24a9f2df2145 +http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#c91884bd2713
--- a/main.cpp Mon Jul 20 07:54:18 2015 +0000 +++ b/main.cpp Thu Dec 07 21:25:43 2017 +0000 @@ -1,111 +1,115 @@ +// Test of ADC, and LED/LCD control of LINAC MO Monitor +// Hengjie Ma +// BNL, NSLS-II, RF +// Nov. 2, 2017 +// #include "mbed.h" -#include "EthernetInterface.h" +#include "TextLCD.h" +#include <stdio.h> + +// Analog signal input channel gain scalling +#define AIN_cal_CL1 1.0; // RFIN_500M +#define AIN_cal_CL2 1.0; // SPB_500M +#define AIN_cal_CL3 1.0; // GUN_500M +#define AIN_cal_CL4 1.0; // PB_3G +#define AIN_cal_CL5 1.0; // K1_3G +#define AIN_cal_CL6 1.0; // K2_3G +#define AIN_cal_OP1 1.0; // K3_3G +#define AIN_cal_OP2 1.0; // 5V_OK +#define AIN_cal_OP3 1.0; // 15V_OK +#define AIN_cal_OP4 1.0; // AIN3_SPARE +#define AIN_cal_OP5 1.0; // AIN6_SPARE +#define AIN_cal_OP6 1.0; // AIN7_SPARE + +const char * msg[] = { + "RFIN500M ", + "SPB500M ", + "GUN500M ", + "PB_3G ", + "K1_3G ", + "K2_3G ", + "K3_3G ", + "5V_OK ", + "15V_OK ", + "AIN3_xxx ", + "AIN6_xxx ", + "AIN7_xxx " +}; + +char trailer[16] = "me too !!!"; // test string -#define ECHO_SERVER_PORT 7 +// I/O pin assignment +DigitalOut myled(LED1); // on-board blue LED, an idiot light for TCP sanity check +// Primary group of analog inputs +AnalogIn AIN0(P30); // AIN0, RFIN_500M/K3_3G +AnalogIn AIN1(P29); // AIN1, SPB_500M/5V_OK +AnalogIn AIN2(P28); // AIN2, GUN_500M/15V_OK +AnalogIn AIN3(P27); // AIN3, PB_3G/AIN3_SPARE +AnalogIn AIN6(P26); // AIN6, K1_3G/AIN6_SPARE +AnalogIn AIN7(P25); // AIN7, K2_3G/AIN7_SPARE +DigitalOut MUX_CTL(P11); // PA11, + +// 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 +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 +float meas[12]; +int idx, row, col; -DigitalOut myled(LED1); +void adc() +{ + // Update data + MUX_CTL = 0; // group 1 + meas[0] = AIN0.read() * AIN_cal_CL1; + meas[1] = AIN1.read() * AIN_cal_CL2; + meas[2] = AIN2.read() * AIN_cal_CL3; + meas[3] = AIN3.read() * AIN_cal_CL4; + meas[4] = AIN6.read() * AIN_cal_CL5; + meas[5] = AIN7.read() * AIN_cal_CL6; + MUX_CTL = 1; // group 2 + meas[6] = AIN0.read() * AIN_cal_OP1; + meas[7] = AIN1.read() * AIN_cal_OP2; + meas[8] = AIN2.read() * AIN_cal_OP3; + meas[9] = AIN3.read() * AIN_cal_OP4; + meas[10] = AIN6.read() * AIN_cal_OP5; + meas[11] = AIN7.read() * AIN_cal_OP6; +} -int compare_strings(char [], char []); +void display() +{ + // update 20x4 LED/LCD display, rolling + lcd.cls(); + for ( idx = 0; idx < 12; idx++) + { + // lcd.locate(col,row); + printf("%s %.2f V \r\n", msg[idx], meas[idx]); // serial console + lcd.printf("%s %.2f V \r\n",msg[idx], meas[idx]); // LCD/LED + wait(0.1); // per line + if (row < 3) + { + row = row + 1; + lcd.locate(col,row); + } + else + { + row = 0; + wait(1.0); // pause after each frame of 4 lines + lcd.cls(); + } + } + // wait(1.0); // every 4-screen, 12-line total, refresh +} int main (void) { - myled = 1; // LED OFF in WIZwiki-W7500 - int flag=1; - - printf("Wait a second...\r\n"); - uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x55, 0x51, 0x52}; - EthernetInterface eth; - eth.init(mac_addr); //Use DHCP - eth.connect(); - printf("Server IP Address is %s\r\n", eth.getIPAddress()); - - TCPSocketServer server; - server.bind(ECHO_SERVER_PORT); - server.listen(); - - while (true) + row = 0; + col = 0; + printf("Test of ADC and LCD .....\r\n"); + while(true) { - printf("Wait for new connection...\r\n"); - TCPSocketConnection client; - server.accept(client); - client.set_blocking(false, 15000); // Timeout after (1.5)s - - printf("Connection from: %s\r\n", client.get_address()); - char buffer[256]; - while (true) { - int n = client.receive(buffer, sizeof(buffer)); - if (n <= 0) break; - - // print received message to terminal - buffer[n] = '\0'; - printf("Received message from Client :'%s'\r\n",buffer); - - - // LED control if received message matches pre-defined command - /* - if ((buffer[0] == 'L') & (buffer[1] == '\0')) - myled = 0; // LED ON in WIZwiki-W7500 - else - myled = 1; - */ - - // LED control if received message matches pre-defined command - char command_buf[256] = {'L', 'E', 'D', '_', 'O', 'N', '\0'}; - - char string[256]; - strcpy (string, command_buf); - printf("Received command : %s\n", string); - - flag = compare_strings(buffer, command_buf); - - if (flag == 0) { - myled = 0; // LED ON in WIZwiki-W7500 - printf("LED is turned on!\r\n"); - } - else { - myled = 1; - printf("LED is turned off!\r\n"); - } + // get new data + adc(); + // display on serial terminal and LCD + display(); + } +} - // LED blink one time - //myled = 0; // LED ON in WIZwiki-W7500 - //wait(1.0); - //myled = 1; // LED OFF in WIZwiki-W7500 - - // reverse the message - char temp; - for(int f = 0, l = n-1; f<l; f++,l--){ - temp = buffer[f]; - buffer[f] = buffer[l]; - buffer[l] = temp; - } - - // print reversed message to terminal - printf("Sending message to Client: '%s'\r\n",buffer); - - // Echo received message back to client - client.send_all(buffer, n); - if (n <= 0) break; - } - - client.close(); - } - -} - -int compare_strings(char a[], char b[]) -{ - int c = 0; - - while (a[c] == b[c]) { - if (a[c] == '\0' || b[c] == '\0') - break; - c++; - } - - if (a[c] == '\0' && b[c] == '\0') - return 0; - else - return -1; -}
--- a/mbed.bld Mon Jul 20 07:54:18 2015 +0000 +++ b/mbed.bld Thu Dec 07 21:25:43 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7 \ No newline at end of file +https://mbed.org/users/mbed_official/code/mbed/builds/64910690c574 \ No newline at end of file