The wires we contact daily, such as USB, HDMI, VGA and network cables, generally need to be tested for continuity and wire sequence in the production process. The products with Overmolding process also need to be tested for short circuit. The corresponding connector also needs to be tested. Manufacturers usually buy Cable testers to test. As the cable tester is a general testing equipment, the unit price is relatively high and the volume is relatively large. If it is used to measure USB, network cable and connector, it is a little overqualified; It's not very convenient to use. If designed by ourselves, the cost will be lower; Especially for connector process detection, it is easier to be embedded in the automatic machine, which makes up for the lack of PLC sampling flexibility, reduces the input / output points of the required PLC and reduces the purchase cost of PLC. Here is how to design this test fixture.
How to design test fixture? Since the function of wire and connector is to connect. Then we use it as a data transmission path, which is connected to the receiving and transmitting I/O ports respectively, and use it to transmit data. Compare the transmitted data with the received data. If it is consistent with the wiring, the tested sample is OK, otherwise, it is NG. Is the principle simple? Understand the test principle, we can do it.
The following network cable test is an example to explain how to design and make this kind of fixture. First, a network cable tester is designed and manufactured. If you want to use it in the process, you should not only test the quality of the network cable, but also find out where the problem is, so as to provide a basis for process improvement. Doing this requires both hardware and software, that is, both hardware system design and software programming. We also need to design the chassis and so on. This is not the scope to be discussed here, so we won't explain it.
one hardware design This is a simple test fixture. Its hardware part is very simple, as shown in the following figure:
Four 1.5V batteries are used for series power supply, and a 1N4001 diode is connected in series on the main power supply circuit. The diode has two functions: reducing voltage and preventing the reverse polarity of the power supply from damaging the components. The power switch adopts 2-position toggle switch, and the power indication uses LED. Two 648 8P8C network cable sockets or RJ45 with cable can be used, as shown in the figure below:
Connect with P1 and P2 ports respectively according to the schematic diagram, and the corresponding relationship of Pin: bit0-1, bit1-2,... bit7-8.
There are two connection methods of network cable, one is direct interconnection method, and the other is cross interconnection method. The practice of cross line is: 568A standard is adopted at one end and 568 standard is adopted at the other end B Standard. The practice of parallel (straight through) line is: both ends are 568A standard or 568B standard. 568B straight through is generally used. 568A standard: White Green 1, green 2, White Orange 3, blue 4, white blue 5, orange 6, White Brown 7, Brown 8.
568B standard: White Orange 1, orange 2, White green 3, Blue 4, white blue 5, Green 6, white brown 7, Brown 8.
The wire number of crystal head is shown in the figure below:
The test fixture we make must be able to measure the line reading of two connection methods. Two button switches are designed in the above schematic diagram, one for mode selection and one for selection confirmation. A buzzer driving circuit is designed in the schematic diagram, and the buzzer sound is used as the key tone. In addition, there are two LED driving circuits to drive the NG/OK indicator. LCD1602 interface in the schematic diagram is connected to LCD1602 display screen. Display the test details with LCD1602.
two software design
one Clarify the design objectives (or tasks) the function definition must be made before software design. Without design objectives, it is impossible to write programs. This is generally defined by the demand side, and the designer designs hardware and software according to this definition; Or it shall be defined by the designer and confirmed by the employer. Now let's do the function and definition. 1) 2. Post Since the system self-test circuit is not designed in the schematic diagram, the user can only judge whether there is a problem in the system through output. After startup, the buzzer will sound twice, the NG indicator light (red light connected to P3.2) and the OK indicator light (green light connected to P3.3) will be on for 2 seconds and then go out. 2) Boot interface The first line of LCD1602 displays: P_ T Mode. It is the abbreviation of Pass Through Mode, which means through test mode. Second display Y_KeyL N_KeyR. Press the left key to confirm the use of the current test mode, and press the right key to switch to another test mode. 3) Mode switching If you press the left key in the boot interface, you will enter Pass Through Mode. If you press the right key, the first line displays Cross Mode, i.e. cross line test mode. If you press the right key again, the first line displays: P_ T Mode. Press the left key to enter the test mode displayed before. 4) Test interface When idle, the first line shows the test mode (P_T Mode or Cross Mode), the second line displays No Test. Because the test time is very short, the interface under test is not done. The test result shows that if the test result is OK, the first line displays OK 12345678, otherwise NG 12345678. The second line displays the corresponding connection line number. If there is no connection, a space will be displayed. When NG, the NG light is on, the OK light is not on, and the buzzer sounds for a long time. When OK, the OK light is on, the NG light is not on, and the buzzer does not sound. After entering the test interface, no longer respond to the key.
2. Software design According to the above design requirements, the program can be roughly divided into the following parts: Port definition, initialization program, test program, test status and result display program. Next step by step to complete this procedure.
2.1 Network Cable Test.uvproj Create a new Network Cable Tester folder and copy all files and folders under the C51 Template folder created in the previous tutorial to this folder, which can save the time of configuring Proj (if you are not a novice, you can create it from scratch). Create three new files and store them in the User folder as myport.h, main. H and main. C. myport.h is used for port definition. The code after completion is as follows:
/*myport.h Designed by Bill Liu Version 0.0 Modified last by Bill Liu on 11/21/2021 */ #ifndef __MYPORT_H_ #define __MYPORT_H_ #include "stc15w4k.h" #define LCD_DATAPINS P0 #define PORT_IN P1 #define PORT_IN P2 sbit LCD_RS = P4^1; sbit LCD_RW = P4^2; sbit LCD_EA = P4^4; sbit LED_NG = P3^2; //NG LED control_bit sbit LED_OK = P3^3; //OK LED control_bit sbit BTN_L = P3^4; //left button input_bit sbit BTN_R = P3^5; //right button input_bit sbit BUZZER = P4^5; //buzzer control_bit #endif
It goes without saying that main.h is the header file of main.c. main.h contains the required library function header file, defines the system clock (required by the delay program), and defines the variables and functions required by main.c. After completion, it is as follows:
/*main.h Designed by Bill Liu Version 0.0 Modified last by Bill Liu on 11/21/2021 */ #ifndef __MAIN_H_ #define __MAIN_H_ #include "mtype.h" #include "stcio.h" #include "lcd.h" #include "delay.h" const FSYSCLOCK FSCLK = F30MHz; //define system clock frequency 30MHz, FSYSCLOCK was defineed in mtype.h ui8 testRes = 2; //test result, 0--NG, 1--OK, 2, No Test BOOL modeFlag = 0; //test result, 0--PT mode, 1--Cross mode ui8 tem = 0; ui8 tem1 = 0; ui8 mstr1[17]=" ";//space for clraring text ui8 mstr2[9] = "12345678"; ui8 mstr3[17] = ""; void SoundBuzzerx10ms(ui8 x); void LED_NgOn(); void LED_NgOff(); void LED_OkOn(); void LED_OkOff(); void PT_Test(); void Cross_Test(); void DispalyResult(); #endif
The included library function header and it have been mentioned in the previous tutorial. You can copy it from the tutorial or download it from the CSDN website. After the header file is included, you need to add the. c file of the library function to Proj, otherwise an error will occur during compilation. Move the mouse cursor over Lib and click the right mouse button.
Click Add Existing Files to Group 'Lib' in the pop-up menu
Check delay.c,mtype.c,stcio.c, lcd.c
Click the Add button in the lower right corner, and then click Close to Close the dialog box and return to the programming interface.
Click + in front of Lib to expand and see that delay.c,mtype.c,stcio.c and lcd.c have been added, as follows:
Here's how to change the Proj name and set the generated compiled file name. You can see that the Proj name is C51 Template
How to change the Proj name to Network Cable Test? Exit Keil and directly rename C51 Template.uvproj under Proj folder to Network Cable Test.uvproj.
Start Keil again, open Network Cable Test.uvproj, and the Proj name will be changed as follows:
Click Options for Target
In the pop-up dialog box, click the Output button
Change the C51 Template in the input box after Name ofExecute to Network Cable Tester
Compile the program and get the following results:
It can be seen that the generated hex file name also becomes Network Cable Tester.
2.2 function code implementation The implementation of main.c is the most important part of the whole program. How to implement it is explained in a little detail below. main.c without function implementation is as follows:
/*main.c Designed by Bill Liu Version 0.0 Modified last by Bill Liu on 11/21/2021 */ #include "main.h" void main() { while(1) { } }
It is preferred to implement some functions defined in main.h. first copy the defined functions into main.c, remove the semicolon, add the curly brackets of the function body, and complete some function codes, as follows:
/*main.c Designed by Bill Liu Version 0.0 Modified last by Bill Liu on 11/21/2021 */ #include "main.h" void main() { while(1) { } } //*********************************************** void SoundBuzzerx10ms(ui8 x) { BUZZER = 0; Delay10xms(x, FSCLK); BUZZER = 1; } //End of SundBuzzerx10ms(ui8 x) //*********************************************** void LED_NgOn() { LED_NG = 0; } //End of LED_NgOn() //*********************************************** void LED_NgOff() { LED_NG = 1; } //End of LED_NgOff() //********************************************* void LED_OkOn() { LED_OK = 0; } //End of LED_OkOn() //********************************************* void LED_OkOff() { LED_OK = 1; } //End of LED_OkOff() //********************************************* void PT_Test() { } //End of PT_Test() //******************************************** void Cross_Test() { } //End of Cross_Test() //******************************************** void DispalyResult() { switch(testRes) { case 0: //No test LCD1602_DisplayString(0, 0, mstr1, 0);//clear line1 LCD1602_DisplayString(4, 0, "P_T Mode", 0); LCD1602_DisplayString(0, 1, mstr1, 0);//clear line2 LCD1602_DisplayString(4, 1, "No Test", 0); LED_NgOff(); LED_OkOff(); BUZZER = 1; break; case 1: //OK LCD1602_DisplayString(0, 0, mstr1, 0);//clear line1 LCD1602_DisplayString(0, 0, "OK", 0); LCD1602_DisplayString(4, 0, mstr2, 0); LCD1602_DisplayString(0, 1, mstr1, 0);//clear line2 LCD1602_DisplayString(4, 1, mstr3, 0); LED_NgOff(); LED_OkOn(); BUZZER = 1; break; case 2://NG LCD1602_DisplayString(0, 0, mstr1, 0);//clear line1 LCD1602_DisplayString(0, 0, "NG", 0); LCD1602_DisplayString(4, 0, mstr2, 0); LCD1602_DisplayString(0, 1, mstr1, 0);//clear line2 LCD1602_DisplayString(4, 1, mstr3, 0); LED_NgOn(); LED_OkOff(); BUZZER = 0; //sound buzzer break; } } //End of DispalyResult()
Add the initialization code to the main function as follows:
Add the response key code in the main function, as follows:
At this point, the main function code is completed. Next, complete PT_Test() function. PT_ The test() function is relatively simple. It outputs a data from the output port. If the data received at the input port is equal to the data at the output port, the test result is OK. If the input data does not change, it means that the cable is not connected and there is no test, otherwise it is NG. If it is NG, you need to query the bad Pin. Displays the results. Due to the requirements of function definition, after entering the test state, it does not respond to the key. Therefore, the above code needs to be put into an endless loop. The code after completion is as follows:
//********************************************* void PT_Test() { ui8 i,j; while(!modeFlag) { testRes = 1; PORT_OUT = 0x00; PORT_IN = 0xFF; Delayxms(2,FSCLK); if(PORT_IN== 0xFF) testRes = 2; else { for(i = 0; i < 8; i++) { PORT_OUT = ~(1 << i); //PORT_IN = 0xFF; Delayxms(2,FSCLK); if(PORT_IN== PORT_OUT) mstr3[i] = mstr2[i]; else if(PORT_IN== 0xFF) { testRes = 0; mstr3[i] = ' '; } else { testRes = 0; j = 0; tem = ~PORT_IN; while((tem >> j) != 1) { j++; } mstr3[i] = mstr2[j]; } } } //display result if(tem1 != testRes) //avoid frequently refresh { DispalyResult(); tem1 = testRes; } } } //End of PT_Test()
Cross_ The test() function is relatively troublesome. Since the two connectors of the cable are a and B respectively, the corresponding relationship is as follows:
The code needs to deal with the intersection of lines. The completed code is as follows:
//******************************************** void Cross_Test() { ui8 i,j; while(modeFlag) { testRes = 1; PORT_OUT = 0x00; PORT_IN = 0xFF; Delayxms(2,FSCLK); if(PORT_IN== 0xFF) testRes = 2; else { for(i = 0; i < 8; i++) { PORT_OUT = ~(1 << i); Delayxms(2,FSCLK); if(PORT_IN== PORT_OUT) mstr3[i] = mstr2[i]; else if(PORT_IN== 0xFF) { testRes = 0; mstr3[i] = ' '; } else { j = 0; tem = ~PORT_IN; while((tem >> j) != 1) { j++; } mstr3[i] = mstr2[j]; } } if(testRes==1) { if(strcmp(mstr3, "36145278")) testRes = 0; } } //display result if(tem1 != testRes) //avoid frequently refresh { DispalyResult(); tem1 = testRes; } } } //End of Cross_Test()
The program compilation results are as follows:
Here, all the software and hardware design is completed. The code of the program has been uploaded to CSDN, and the file name is Network Cable Tester Code.rar. To view, search for downloads.