DIY LAN tester on AVR
The problem of testing a freshly laid LAN is always relevant. Once I got into my hands a piece of iron called "Rapport II", which, generally speaking, is a tester for CCTV systems, but it knows how to ring a twisted pair too. The piece of iron had already died a long time ago, but the impression remained: when testing the twisted pair cable, it showed not just the polarity reversal and the pin-out, but the exact crimping circuit! For example, for a crossover, it looked like 1 → 3, 2 → 6, 3 → 1, and so on.
But to pay about 800 non-Russian rubles for a device in which I really will use only one function? Dismiss How does it work, maybe it’s easier to do it yourself? Google in hand, and ... sheer disappointment. The search output consists of 80% of the flashing LEDs on the shift register / AVR / PIC / your own version, and 20% of the thoughtful discussions of forum gurus on the topics "buy% cool_game_name_for_100499.99_green green and don’t worry." Therefore, I want to offer the habrasociety my solution to this problem in the style of DIY. Who is interested - I ask for a cut (carefully, a certain number of photos!).
Determining the exact cable crimping pattern is mandatory.
All information is displayed by the tester. No blinking LEDs on the counterpart. Suppose that the counterpart is in the hands of a monkey, and not even a circus one, and only thanks to the latest technologies the monkey was trained to use a hammer drill and cross the cable in outlets. Or, to put it a little more scientifically: the counterpart is completely passive.
Principle of work: the response part is a set of resistances of various ratings. Let's measure them. Knowing their ratings and the wiring of the mating part, we can find out exactly how the cable is cross-connected. Below is a diagram of the device (all illustrations are clickable). Specific resistance values were selected more likely taking into account the presence in the store than consciously, although it turned out to be a piece of the Fibonacci series. Fig. 1. Tester circuit Fig. 2. Scheme of the mate
The heart of the circuit is the ATMega16 microcontroller. Why exactly him? The “AVR vs PIC” dispute is a typical holivar, so I’ll say simply: let AVR be my arbitrariness. And from their entire Mega16 line, the cheapest crystal has 8 ADCs on board. I frankly did not want to complicate the circuit with analog signal switches. An important plus: this model can be bought even in my castle, where for the whole city there is one store of electronic components with prices of 150-500% from Moscow.
Port A of the microcontroller is the ADC inputs, on port B we have ISP and a couple of utility functions, we use port C for generating test signals, well, port D for communicating with the user via an HD44780-compatible display.
We feed the circuit from a Krona battery through the LP2950, DA1 stabilizer according to the circuit. Why not a PWM, but an ordinary linear stabilizer, albeit a low-dropout? The current consumption is low, on one battery I did all the testing and debugging of the circuit, I launched a couple of real objects with fifty ports - until I ran out of power. But high-frequency interference, which is the satellite of any PWM, can reduce the accuracy of the ADC. To complicate the scheme, again, I do not want to. Why LP2950? He was in the store.
We protect the input circuits with the help of suppressors VD1.1 - VD1.8, I took 1,5KE6,8CA. Of course, they will not save them from getting into 220V, but they can completely repay 60V from any telephone line.
The VD2 - R4 chain is used to detect battery discharge. 5.1V drops on the zener diode, Thus, when the battery voltage drops below 6V, a log appears on PB2. 0. Here the mind would need a Schmitt trigger, but could not be found.
Information is output using an HD44780-compatible display, I came across WH-1604A-YYH-CT #. The connection diagram is typical and does not require explanation. It is worth saying only about the nominal resistance R5, which sets the brightness of the backlight. The larger the rating, the longer the battery will live - the rest of the circuit consumes less than 5 mA, the main consumer is the display backlight. But if you overdo it, you will not see anything on the screen in the dark. I stopped at 100 ohms.
To write the program, I used the AVR Studio 4 environment, C language. Below I will describe the operation algorithm, but I will not show the code, and there are reasons for this. Firstly, he is somewhat terrible (a picture of a horse vomiting a rainbow). Secondly, since this is DIY, it’s not a sin to implement the algorithms described below to write yourself - what kind of DIY is this? Well, and thirdly, if you do not want to write, then a compiled .hex is present in applications. I don’t see any sense in
describing standard procedures such as working with ADCs , implementing exchanges with an HD44780-compatible display, and the like. Everything has long been said before me.
The work of the tester is divided into several stages, which are repeated cyclically.
For each of the 8 lines, do the following. We apply + 5V to it from port C, keeping all other lines of the port in a high-impedance state, and measure the voltage on the remaining lines. If there are near-zero values on all lines, the studied line is broken. If + 5V also appeared on one of the lines, this is a short circuit. Normally, we will see some intermediate values.
So we got to the most interesting. Having eliminated all the obviously faulty lines (broken and shorted wires), we proceed to measure the resistances of the remaining lines (let their number N, 0 <= N <= 8). We introduce the notation:
R xy is the resistance between the lines x and y.
R x is the nominal value of the resistance connected to line x.
It is clear that R xy = R x + R y
Measuring the resistance between the lines, we get a system of linear equations. Comparing the obtained values of R 1 ... R N with the reference, we find out the crossover scheme.
Resistance is easy to calculate. Let's set line X to high, line Y to low, and leave the other lines of port C in Hi-Z. In the circuit (see Fig. 3), the voltage drop at the known resistance formed by the parallel connection of R1.Y and R2.Y according to the circuit is U 1 , and on the unknown R xy drops (U 2 - U 1 ). Therefore, R xy = (R 1 || R 2 ) * (U 2 - U 1 ) / U 1 . Fig. 3. The principle of measuring resistance
If N <3 - we are powerless. We can make only one measurement of the resistance between them, while we have 2 unknowns - the resistance connected to each of them. A system in which the number of equations is less than the number of unknowns has an infinite number of solutions. We have to show the user question marks on these lines - they seem to be working, but it is not possible to find out the cross-connection scheme.
For N = 3, we have only one possible option. Having measured all the available resistances R 12 , R 13 , R 23 , we get the system:
R 1 + R 2 = R 12
R 1 + R 3 = R 13
R 2+ R 3 = R 23
It is easy to show that:
R 1 = 1/2 * (R 12 + R 13 - R 23 )
R 2 = R 12 - R 1
R 3 = R 13 - R 1 .
When used on lshih values of N, we can make the system of equations in many ways, by performing the measurements of various resistances the R the xy . At first glance, there is no difference how to choose which resistance to measure. However, the devil dwells in small things. Using N = 8 as an example, I’ll explain what I mean. In the first implementation of the algorithm, I took measurements like this:
R1 + R 2 = R 12
R 1 + R 3 = R 13
...
R 1 + R 8 = R 18
R 2 + R 3 = R 23
Adding the first two equations and subtracting the last one, we get the same 2R 1 = R 12 + R 13 - R 23 , and all other resistances will be found from equations 1 - 7, where R 1 is already known.
The problem lies in the fact that for some types of crossover the value of R 1It turned out to be large (15 kOhm and above), and the error in measuring resistance increases with its increase. As a result, it turned out that small resistances with a nominal value of 1-2 kOhm relative to R 1 were measured with an error of 70-80%! Obviously, to ensure good accuracy, we should design the system so that in place of R 1 there is another unknown, the minimum of all. To do this, we will have to perform all possible measurements (it’s good that there are not so many, in the worst case 28). In fact, we got an 8 x 8 matrix symmetrical about the main diagonal (it is clear that R xy = R yx ). We choose the minimum from all the results, let it be R ij = R i + R j. In row i we find R ik such that R ik > R ij , but less than the other elements of the row. We get:
R i + R j = R ij
R i + R k = R ik
R j + R k = R jk
We solve and find the least among R i , R j , R k (suppose it turned out to be R i ). the remaining unknowns R x are found from R x = R ix - R i .
Smart and expensive glands measure the distance to the cliff point using TDR . Difficult, expensive, cool. Our capabilities are much more modest, and it is not often necessary to know the position of the cliff to centimeters - usually understanding in the style of “right next to me”, “on that end”, “in the middle where the wall was recently hollowed” is more than enough. So - measuring the cable capacity.
We translate all the lines of port C, except the one that is connected in the core where there is a break, in Hi-Z. We submit to the + 5V core, charging it. We measure the voltage on it, this will be our initial U 0 . We translate all the lines in Hi-Z. The discharge of the cable begins through the resistor R2.X with a resistance of 1 MΩ. After waiting 1 ms, we measure the voltage on this line U.
Do not forget that the circuit on the board, connector, etc. also have their own capacity, so the device must be calibrated on a pair of pieces of cable of different lengths. I succeeded at a zero length of 1710 pF, and the cable capacity was 35 pF / m. The practice of using showed that even if it is lying, it’s not very much, 10 percent. The situation is like “where did you get the contact, in the cabinet on the patch panel or in a power outlet? ”is decided instantly.
I use it. Satisfied. Those who want to repeat my path can find here an archive with a printed circuit board in DipTrace format, a circuit in sPlan format, MK firmware, and also a file with an example of the command line for avreal, in which you can see fuse-bits.
Attention! At birth, the author of the article was cut out an artistic feeling that the future engineer did not need. For connoisseurs of unfilled horizons, composition, and any other white balance, please stop reading at this point and proceed immediately to comments, in order to avoid serious mental trauma. The beginning of the process. Printed circuit board. Made using LUT , tin - plated with Rose alloy . Ready board. We drill, solder, and rinse with alcohol (whose hand is raised - with ethyl, I personally washed with isopropyl). After debugging, varnish to protect against corrosion. The board is installed in the case
, the display is fixed, a train of cheerful colors is soldered to it. I cut a hole for the display with a dremel using a miniature cutting disc, however, there are other methods . It remains to close the lid. Test: factory direct patch cord, 0.5 m. The power button is located under the index finger on top of the case. Test: a piece of cable 10 m long, crimped on one side. Test: homemade crossover, 10 m. Upd. At the request of habrazhitelov still spread the source. You can take it here .
But to pay about 800 non-Russian rubles for a device in which I really will use only one function? Dismiss How does it work, maybe it’s easier to do it yourself? Google in hand, and ... sheer disappointment. The search output consists of 80% of the flashing LEDs on the shift register / AVR / PIC / your own version, and 20% of the thoughtful discussions of forum gurus on the topics "buy% cool_game_name_for_100499.99_green green and don’t worry." Therefore, I want to offer the habrasociety my solution to this problem in the style of DIY. Who is interested - I ask for a cut (carefully, a certain number of photos!).
Introductory
Determining the exact cable crimping pattern is mandatory.
All information is displayed by the tester. No blinking LEDs on the counterpart. Suppose that the counterpart is in the hands of a monkey, and not even a circus one, and only thanks to the latest technologies the monkey was trained to use a hammer drill and cross the cable in outlets. Or, to put it a little more scientifically: the counterpart is completely passive.
Hardware
Principle of work: the response part is a set of resistances of various ratings. Let's measure them. Knowing their ratings and the wiring of the mating part, we can find out exactly how the cable is cross-connected. Below is a diagram of the device (all illustrations are clickable). Specific resistance values were selected more likely taking into account the presence in the store than consciously, although it turned out to be a piece of the Fibonacci series. Fig. 1. Tester circuit Fig. 2. Scheme of the mate
The heart of the circuit is the ATMega16 microcontroller. Why exactly him? The “AVR vs PIC” dispute is a typical holivar, so I’ll say simply: let AVR be my arbitrariness. And from their entire Mega16 line, the cheapest crystal has 8 ADCs on board. I frankly did not want to complicate the circuit with analog signal switches. An important plus: this model can be bought even in my castle, where for the whole city there is one store of electronic components with prices of 150-500% from Moscow.
Port A of the microcontroller is the ADC inputs, on port B we have ISP and a couple of utility functions, we use port C for generating test signals, well, port D for communicating with the user via an HD44780-compatible display.
We feed the circuit from a Krona battery through the LP2950, DA1 stabilizer according to the circuit. Why not a PWM, but an ordinary linear stabilizer, albeit a low-dropout? The current consumption is low, on one battery I did all the testing and debugging of the circuit, I launched a couple of real objects with fifty ports - until I ran out of power. But high-frequency interference, which is the satellite of any PWM, can reduce the accuracy of the ADC. To complicate the scheme, again, I do not want to. Why LP2950? He was in the store.
We protect the input circuits with the help of suppressors VD1.1 - VD1.8, I took 1,5KE6,8CA. Of course, they will not save them from getting into 220V, but they can completely repay 60V from any telephone line.
The VD2 - R4 chain is used to detect battery discharge. 5.1V drops on the zener diode, Thus, when the battery voltage drops below 6V, a log appears on PB2. 0. Here the mind would need a Schmitt trigger, but could not be found.
Information is output using an HD44780-compatible display, I came across WH-1604A-YYH-CT #. The connection diagram is typical and does not require explanation. It is worth saying only about the nominal resistance R5, which sets the brightness of the backlight. The larger the rating, the longer the battery will live - the rest of the circuit consumes less than 5 mA, the main consumer is the display backlight. But if you overdo it, you will not see anything on the screen in the dark. I stopped at 100 ohms.
Software part
To write the program, I used the AVR Studio 4 environment, C language. Below I will describe the operation algorithm, but I will not show the code, and there are reasons for this. Firstly, he is somewhat terrible (a picture of a horse vomiting a rainbow). Secondly, since this is DIY, it’s not a sin to implement the algorithms described below to write yourself - what kind of DIY is this? Well, and thirdly, if you do not want to write, then a compiled .hex is present in applications. I don’t see any sense in
describing standard procedures such as working with ADCs , implementing exchanges with an HD44780-compatible display, and the like. Everything has long been said before me.
The work of the tester is divided into several stages, which are repeated cyclically.
Stage 1. Initial checks
- check if any active equipment is connected to the line. We transfer all control lines (port C, I remind you) to Hi-Z state, measure the voltage on all lines. They should be near-zero. Otherwise, we understand that on the other side of the wire, anything is connected, but not our counterpart, and it does not make sense to continue further. But it makes sense to inform the user that "there is voltage on the line!".
- check the signal level on PB2. If there is 0, then the battery is low. We will report the problem to the user, if everything is OK - go ahead.
Stage 2. Checking the integrity of the lines and the presence of short circuits
For each of the 8 lines, do the following. We apply + 5V to it from port C, keeping all other lines of the port in a high-impedance state, and measure the voltage on the remaining lines. If there are near-zero values on all lines, the studied line is broken. If + 5V also appeared on one of the lines, this is a short circuit. Normally, we will see some intermediate values.
Stage 3. Clarification of the crossover pattern
So we got to the most interesting. Having eliminated all the obviously faulty lines (broken and shorted wires), we proceed to measure the resistances of the remaining lines (let their number N, 0 <= N <= 8). We introduce the notation:
R xy is the resistance between the lines x and y.
R x is the nominal value of the resistance connected to line x.
It is clear that R xy = R x + R y
Measuring the resistance between the lines, we get a system of linear equations. Comparing the obtained values of R 1 ... R N with the reference, we find out the crossover scheme.
Resistance is easy to calculate. Let's set line X to high, line Y to low, and leave the other lines of port C in Hi-Z. In the circuit (see Fig. 3), the voltage drop at the known resistance formed by the parallel connection of R1.Y and R2.Y according to the circuit is U 1 , and on the unknown R xy drops (U 2 - U 1 ). Therefore, R xy = (R 1 || R 2 ) * (U 2 - U 1 ) / U 1 . Fig. 3. The principle of measuring resistance
If N <3 - we are powerless. We can make only one measurement of the resistance between them, while we have 2 unknowns - the resistance connected to each of them. A system in which the number of equations is less than the number of unknowns has an infinite number of solutions. We have to show the user question marks on these lines - they seem to be working, but it is not possible to find out the cross-connection scheme.
For N = 3, we have only one possible option. Having measured all the available resistances R 12 , R 13 , R 23 , we get the system:
R 1 + R 2 = R 12
R 1 + R 3 = R 13
R 2+ R 3 = R 23
It is easy to show that:
R 1 = 1/2 * (R 12 + R 13 - R 23 )
R 2 = R 12 - R 1
R 3 = R 13 - R 1 .
When used on lshih values of N, we can make the system of equations in many ways, by performing the measurements of various resistances the R the xy . At first glance, there is no difference how to choose which resistance to measure. However, the devil dwells in small things. Using N = 8 as an example, I’ll explain what I mean. In the first implementation of the algorithm, I took measurements like this:
R1 + R 2 = R 12
R 1 + R 3 = R 13
...
R 1 + R 8 = R 18
R 2 + R 3 = R 23
Adding the first two equations and subtracting the last one, we get the same 2R 1 = R 12 + R 13 - R 23 , and all other resistances will be found from equations 1 - 7, where R 1 is already known.
The problem lies in the fact that for some types of crossover the value of R 1It turned out to be large (15 kOhm and above), and the error in measuring resistance increases with its increase. As a result, it turned out that small resistances with a nominal value of 1-2 kOhm relative to R 1 were measured with an error of 70-80%! Obviously, to ensure good accuracy, we should design the system so that in place of R 1 there is another unknown, the minimum of all. To do this, we will have to perform all possible measurements (it’s good that there are not so many, in the worst case 28). In fact, we got an 8 x 8 matrix symmetrical about the main diagonal (it is clear that R xy = R yx ). We choose the minimum from all the results, let it be R ij = R i + R j. In row i we find R ik such that R ik > R ij , but less than the other elements of the row. We get:
R i + R j = R ij
R i + R k = R ik
R j + R k = R jk
We solve and find the least among R i , R j , R k (suppose it turned out to be R i ). the remaining unknowns R x are found from R x = R ix - R i .
Stage 4. Determination of the clipping point, if any
Smart and expensive glands measure the distance to the cliff point using TDR . Difficult, expensive, cool. Our capabilities are much more modest, and it is not often necessary to know the position of the cliff to centimeters - usually understanding in the style of “right next to me”, “on that end”, “in the middle where the wall was recently hollowed” is more than enough. So - measuring the cable capacity.
We translate all the lines of port C, except the one that is connected in the core where there is a break, in Hi-Z. We submit to the + 5V core, charging it. We measure the voltage on it, this will be our initial U 0 . We translate all the lines in Hi-Z. The discharge of the cable begins through the resistor R2.X with a resistance of 1 MΩ. After waiting 1 ms, we measure the voltage on this line U.
Do not forget that the circuit on the board, connector, etc. also have their own capacity, so the device must be calibrated on a pair of pieces of cable of different lengths. I succeeded at a zero length of 1710 pF, and the cable capacity was 35 pF / m. The practice of using showed that even if it is lying, it’s not very much, 10 percent. The situation is like “where did you get the contact, in the cabinet on the patch panel or in a power outlet? ”is decided instantly.
Total
I use it. Satisfied. Those who want to repeat my path can find here an archive with a printed circuit board in DipTrace format, a circuit in sPlan format, MK firmware, and also a file with an example of the command line for avreal, in which you can see fuse-bits.
Process photo
Attention! At birth, the author of the article was cut out an artistic feeling that the future engineer did not need. For connoisseurs of unfilled horizons, composition, and any other white balance, please stop reading at this point and proceed immediately to comments, in order to avoid serious mental trauma. The beginning of the process. Printed circuit board. Made using LUT , tin - plated with Rose alloy . Ready board. We drill, solder, and rinse with alcohol (whose hand is raised - with ethyl, I personally washed with isopropyl). After debugging, varnish to protect against corrosion. The board is installed in the case
, the display is fixed, a train of cheerful colors is soldered to it. I cut a hole for the display with a dremel using a miniature cutting disc, however, there are other methods . It remains to close the lid. Test: factory direct patch cord, 0.5 m. The power button is located under the index finger on top of the case. Test: a piece of cable 10 m long, crimped on one side. Test: homemade crossover, 10 m. Upd. At the request of habrazhitelov still spread the source. You can take it here .