First, the circuit principle
The circuit is shown in figure 1, which consists of detection sensor, single chip microcomputer circuit and digital display circuit.
The detection sensor consists of a permanent magnet and a switch-type Hall integrated circuit UGN3020. UGN3020 consists of Hall element, amplifier, shaping circuit and open collector output circuit. Its function is to convert magnetic signals into electrical signals. Fig. 2a is an internal block diagram thereof. Hall element H is a magnetic sensitive element. When the intensity of the magnetic field perpendicular to the Hall element changes, the voltage at both ends will change. After amplification and shaping, a pulse electric signal can be output at the foot ③. Its operating characteristics are shown in fig. 2b. Due to a certain hysteresis effect, the switch can be guaranteed to have no jitter. B tap is the magnetic field intensity of the working point "on" and Brp is the magnetic field intensity of the releasing point "off". The permanent magnet is fixed on the spokes of the wheel, and UGN3020 is fixed on the front fork of the wheel. The working principle of the detection sensor is that every time the wheel rotates, the magnet passes through UGN3020 once, and its foot ③ outputs a pulse signal. The pulse signal output by UGN3020 is used as the external interrupt signal of AT89C205 1 and input from P3.2 port. Single chip microcomputer measures the number and pulse period of pulse signals. Calculate the mileage according to the number of pulse signals, calculate the speed according to the period of pulse signals and send it to the digital tube for display. S 1 is used to switch between mileage and speed display, and the initial state shows the speed.
Digital tubes DS 1-DS3, VT 1-VT3. R4-R 13, etc. Form a display circuit, using * * * positive digital tube. P3.3-P3.5 is the dynamic scanning bit driver of digital tube. PLO-P 1.6 is used for digital segment code output.
Second, the program design
The program is written in C language and consists of main program, external interrupt service program, interrupt service program, delay subroutine and other modules. The main program mainly completes program initialization and keyboard processing, the external interrupt service program consists of measurement, calculation, reading and other parts, and the TO interrupt service program consists of timing, dynamic scanning display, bicycle parking judgment and other parts.
The pulse signal input from P3.2 port is used as the interrupt request signal of external interrupt 0, and the edge trigger mode is adopted. When measuring the speed, because the frequency of wheel rotation pulse signal is very low, it is not suitable for counting, so the method of measuring pulse period is adopted, the timing signal is controlled by the pulse signal system, the pulse period is calculated from the timing number, and the running speed of the bicycle can be obtained by dividing the circumference of the wheel by the period. When measuring the mileage, multiply the number of pulse signals by the circumference of the wheel to get the mileage. It should be noted that the period and number of pulse signals are measured at the same time, and only the button switch S 1 is needed to switch the display.
The program in this paper is written for a bicycle with a wheel diameter of 26 inches. For bicycles of other specifications, just rewrite the programs spm= 14904 (constant 1)In and spm=207 (constant 2)xc. In order to avoid using floating-point numbers, the length of remote calculation results is 100 meters. When reading data, add the decimal point to the third place and convert it into kilometers. For the convenience of readers, the attached table lists the corresponding values of wheel diameter, wheel circumference and program constant of various specifications for reference.
The interrupt timing time of the timer TO is 5ms, and the timing variable n is 1 for each interrupt, so the unit of n is 5 ms. For example, if the value of n of bicycle wheel is 100, the corresponding time is 0.5s, so the speed of bicycle is 14.9km/li. If the value of n reaches 1000, that is, there is still no external interruption for 5 seconds, it means that the bicycle is not moving forward, N is also cleared, and the speed is displayed as 0. The reading is displayed with three digits, one digit at a time when TO is interrupted, and the data can be refreshed once after three interruptions, that is, ms can refresh the data once.
Three. installation and trial run
The installation and debugging of the sensor is the key. Installed at the front wheel, a small permanent magnet is fixed on the spokes of the wheel, and UGN3020 is fixed on the front fork after moisture-proof sealing, so that the magnet passes in front of it when the wheel rotates, and the interval between them is as small as possible. When installing, make the S pole of the magnet face the front of UGN3020. The method to determine the polarity of the magnet is to put the two poles of the magnet close to the front of UGN3020 respectively, and the correct installation position is ③ when the level of the foot changes from high to low. After the sensor is installed, the wheel should be rotated, and the ③ pin of UGN3020 should have a pulse signal output, otherwise the distance between them is too large, and the distance should be shortened until the ③ pin rotates. Generally, the interval is about 5 mm. If the interval is less than 5 mm, there is still no pulse signal output, indicating that the magnetic field strength of the magnet is too small and should be replaced.
After debugging, install the odometer on the handlebar, turn on the power and ride the bike. At this time, the digital tube shows the speed. If you want to display the mileage, just press S 1, and if you want to return to the displayed speed, just press SI again.