Design of electric bicycle speed and odometer based on ST1101 infrared photoelectric sensor

Publisher:神秘行者Latest update time:2015-08-17 Source: eefocusKeywords:ST1101 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
      The speed and mileage meter design introduced in this article is based on a single-chip microcomputer and a photoelectric sensor. The sensor converts different speeds into pulse signals of different frequencies and inputs them into the single-chip microcomputer for control and calculation, and then uses an LED module for display, so that the speed and mileage data of the electric bicycle can be displayed intuitively to the user. 



    System Overview 



    This system consists of a signal preprocessing circuit, a single-chip microcomputer AT89C2051, a systematic LED display module, a serial port data storage circuit and system software. The signal preprocessing circuit includes signal amplification, waveform transformation and waveform shaping. The purpose of amplifying the signal to be measured is to reduce the amplitude requirement of the signal to be measured; the waveform conversion and waveform shaping circuit are used to convert the amplified signal into a TTL signal that can be connected to the single-chip microcomputer; the internal timer T1 can control the pulse input pin T0 through the setting of the single-chip microcomputer, so that the number of pulses detected per unit time added to the T0 pin can be accurately calculated; the speed display in the design uses an LED module, and the mileage converted by speed uses the I2C bus and is stored through E2PROM, which not only saves the port lines and peripheral devices of the required single-chip microcomputer, but also simplifies the software programming of the display part. The principle block diagram of the system is shown in Figure 1. 





System block diagram




                                                 Figure 1 System block diagram 



    Working principle 



    This design can display the measured speed and accumulated mileage in real time. It mainly measures the frequency of the pulse signal input from the sensor to the single-chip microcomputer (the sensor converts different vehicle speeds into pulse signals of different frequencies) in real time. Considering the influence of signal attenuation, interference, etc., the signal should be amplified and shaped before it is sent to the single-chip microcomputer, and then the speed and mileage are calculated by the single-chip microcomputer. The obtained data is then stored in the serial port data storage, and the measured speed and mileage are alternately displayed by the LED display module. The mileage algorithm of this design is an approximate algorithm (assuming that the bicycle is moving at a constant speed within a certain period of time, the product of the average speed and time is the mileage). 



    When designing, the speed measurement accuracy and system response time should be considered comprehensively. This design uses the measurement pulse frequency to calculate the speed, so it has a higher speed measurement accuracy. The ideal state of the bicycle is taken when calculating the mileage. In practice, the error is controlled within a few meters, which is not very large relative to the entire mileage. In order to ensure the real-time performance of the system, the system's speed conversion module and display data conversion BCD code module both use fast algorithms. In addition, the versatility and efficiency of other submodules should be guaranteed as much as possible during programming. The speed and mileage values ​​of this design are displayed in 6 digits and include two decimal places. 



    Hardware Design of the System 



    1 Pulse Generator 



    Pulse Generator This design uses the ST1101 infrared photoelectric sensor for non-contact detection. When an object is blocked between the infrared photoelectric light-emitting diode and the highly sensitive phototransistor, the sensor will output a low level, and when there is no object blocking the middle, the output is a high level, thus forming a pulse. The system extends an aluminum plate at the axis of the rear wheel of the bicycle in a direction parallel to the rotating section of the wheel, digs out several circular vias at the edge of the aluminum plate, and places the detection part of the sensor at the center of the circular hole. Whenever the aluminum plate rotates with the rear wheel, the sensor will output several pulses. These pulses are shaped into a TTL level that can be recognized by the microcontroller through a series of waveforms, and the instantaneous rotation speed of the wheel can be calculated. The number of circular holes in the aluminum plate determines the accuracy of the measurement. The more holes there are, the higher the accuracy. In this way, as many pulses as possible can be obtained per unit time, thus avoiding the large error caused by the car stopping between the vias or before the next via because the distance between the two vias is too large. 



    This design uses 11 vias in the design of the aluminum plate vias, leaving 10 equal spacings. This makes it easier to calculate the speed mileage in future software designs. The hardware structure diagram of the pulse generator is shown in Figure 2. 





Pulse source hardware structure diagram


                                Figure 2 Pulse source hardware structure diagram (left is the front view, right is the side view) 



    2 Signal preprocessing circuit 



    The signal preprocessing circuit is shown in Figure 3. The signal preprocessing circuit of the system consists of a two-stage circuit. The first stage is a zero-bias amplifier composed of a switching transistor. The use of a switching transistor can ensure that the amplifier has a good high-frequency response. When the input signal is zero or negative voltage, the transistor is cut off and the circuit outputs a high level; when the input signal is a positive voltage, the transistor is turned on. At this time, the output voltage decreases as the input voltage rises, which enables the speed odometer to measure the frequency of any square wave signal and the frequency of the sine wave signal. Since the amplification function of the amplifier reduces the amplitude requirement of the signal to be measured, the system can measure any sine wave and pulse signal greater than 0.5V. The second stage of the preprocessing circuit uses an inverter DM74LS14 with a Schmitt trigger to convert the single-phase pulse generated by the amplifier into a square wave signal compatible with the COMS level (as shown in Figure 4), and at the same time, the output signal is added to the P3.4 port of the microcontroller. [page]




 


Signal preprocessing circuit diagram




                                               Figure 3 Signal preprocessing circuit diagram 



Schmitt trigger pulse shaping




                                              Figure 4 Pulse shaping by Schmitt trigger 



    Using the positive feedback effect in the state transition process of Schmitt trigger, a periodic signal with slow edge change can be transformed into a rectangular pulse signal with steep edge. As long as the amplitude of the input signal is greater than VT+, a rectangular pulse signal of the same frequency can be obtained at the output end of the Schmitt trigger. 

    The rectangular pulse obtained from the sensor often undergoes waveform distortion after transmission. When the capacitance on the transmission line is large, the rising edge of the waveform will be significantly deteriorated; when the transmission line is long and the impedance of the receiving end does not match the impedance of the transmission line, oscillation will occur on the rising and falling edges of the waveform; when other pulse signals are superimposed on the rectangular pulse signal through the distributed capacitance between the wires or the common power line, additional noise will appear on the signal. Regardless of which of the above situations occurs, a relatively ideal rectangular pulse waveform can be obtained by shaping with a Schmitt inverting trigger. As long as the VT+ and VT- of the Schmitt trigger are set appropriately, a satisfactory shaping effect can be achieved. 



     Application of OM AT24C02AT24C02 



    is a CMOS 2048-bit serial E2PROM, organized internally into 256×8 bits. The AT24C02 features a serial interface and software protocol that allows it to work on a simple two-wire bus. 



    As shown in Figure 5, in this design, the SDA end of the chip AT24C02 is connected to the P3.7 port of the microcontroller, and the SCL end is connected to the P3.5 port of the microcontroller. Because there is only one device on this I2C bus, the address of AT24C02 is set to 000, that is, A0, A1, and A2 are all grounded. The mileage data calculated by the microcontroller is transmitted to the AT24C02 through SDA and SCL. The microcontroller first sends a write signal to the AT24C02, and when confirmed, it extracts data from the data storage unit inside the microcontroller and then transmits data to the internal address of the AT24C02. When displaying mileage, the microcontroller first sends a read signal to AT24C02, and then after confirmation, the microcontroller reads data from the address inside AT24C02 to the read unit byte of the microcontroller for display. 







AT24C02 and single chip microcomputer interface circuit diagram




                                             Figure 5 Interface circuit between AT24C02 and single-chip microcomputer Figure 



    4 Display part 



    The display module of this design includes MC14511BCP, CD4076, 74LS138 and 6 LED display tubes. MC14511 is a "three-in-one" device that integrates three functions of latch, decoding and driving. The function of the latch is to avoid the phenomenon of skipping during the counting process, which is convenient for observation and recording. The decoder is used to convert the BCD code into a 7-segment code, and then it passes through a large current inverter to drive the common cathode LED digital tube. The decoder is a non-sequential circuit, and its output state is independent of the clock and only depends on the input BCD code. 



    The function of 74LS138 is equivalent to the function of bit selection. When the inputs of C, B, and A are "000, 001, 010, 011, 100, 101" respectively, different MC14511 are selected respectively, so that different numbers and decimal points are displayed on different bits. CD4076 is a CMOS 4-bit three-state output D register. Y6 and Y7 of 74LS138 are used to control the operation of its CP, so that CD4076 can control the decimal point display. Figure 6 is the display module block diagram. 



 


Display module block diagram
 

Figure 6 is the block diagram of the display module 



    . Figure 7 is the circuit of the system display part. In the system, Y0~Y5 of 74LS138 is used to select MC14511 to drive the LED display, and Y6 and Y7 are used to control the CP of CD40756, so as to achieve the display of the decimal point by Q1~Q4 of CD4076. The other CD4076 only uses its Q1 and Q2. The corresponding characters in the figure indicate that their pins are connected. [page]

 


Circuit of the system display part


                                          Figure 7 



    Software design of the circuit system  of the system display part

    1 The system software block diagram 



    is shown in Figure 8. The system software adopts a modular design method. The entire system consists of an initialization module, a frequency measurement module, a speed and mileage calculation module, a data conversion BCD code module, a speed display module, a mileage display module, a data storage and reading module, a timer interrupt service module and other functional modules. 





 

 

 

System software block diagram

 



                                                 Figure 8 System software block diagram 



    2 Data processing 



    The signal to be measured is added to the P3.4 (T0) pin of the microcontroller after the preprocessing circuit, which can provide an effective input signal for the microcontroller to measure the signal frequency. The microcontroller determines whether to start the frequency measurement program by detecting the level of the P3.4 pin. When the pin is high, the system is in a waiting state and will not start measuring the frequency until the pin is low. We can know the distance between the two vias on the circumference of the aluminum plate of the hardware. And this distance M just plays a basic data storage role for calculating speed and distance. At the same time, the N pulses detected by the microcontroller within two seconds can be known from the TL0 register. And M×N is exactly the distance S that the aluminum plate travels on the circumference within these two seconds. (At this time, it is assumed that the car is moving at a constant speed within these two seconds). The distance S divided by the time of 2s can roughly calculate the linear speed of the aluminum plate within these 2s. Then, based on the fact that the aluminum plate and the bicycle wheel maintain the same angular velocity, the relationship between the linear velocity of the aluminum plate and the linear velocity of the wheel is obtained, so as to calculate the average speed of the bicycle in these 2 seconds. 



    As for the calculation of mileage, according to the analysis of speed calculation, after obtaining the distance traveled by the aluminum plate on its circumference within 2 seconds. According to the certain proportional relationship between it and the distance traveled by the circumference of the bicycle wheel (through the algorithm with the same angular velocity of both), the distance S1 traveled by the bicycle in these two seconds can be calculated by the single-chip microcomputer. Adding this distance S1 to the original mileage in the memory can get the current total mileage. The speed and mileage data calculated by the single-chip microcomputer must be converted through BCD code before they can be output to the display module. The display of the total mileage is set to appear when the electric bicycle is started and the single-chip microcomputer is turned on and initialized, so that the user can clearly know how many kilometers his car has run. The speed display is displayed immediately after the speed mileage is calculated, reflecting real-time performance. 



    Conclusion 



    This design takes AT89C2051 as the core, and uses photoelectric sensors to detect the operation of the bicycle to realize the speed and mileage calculation of the electric bicycle, as well as the accumulation and storage of mileage. Finally, a 6-bit LED can intuitively display the speed and mileage to the user, and automatically alarm the user when the speed exceeds a certain value, thus achieving an intelligent speed odometer. 

Keywords:ST1101 Reference address:Design of electric bicycle speed and odometer based on ST1101 infrared photoelectric sensor

Previous article:Multifunctional temperature measuring instrument based on DS18DB20
Next article:Design of Intelligent Satellite Power Supply VT Curve Control System

Recommended ReadingLatest update time:2024-11-16 17:56

AT89C2051 single chip microcomputer drives stepper motor circuit and source code
  program stepper.c stepper.hex /* * STEPPER.C * sweeping stepper''s rotor cw and cww 400 steps * Copyright (c) 1999 by W.Sirichote */ #include c:\mc51\8051io.h /* include i/o header file */ #include c:\mc51\8051reg.h register unsigned char j,flag1,temp; register unsigned int cw_n,ccw_n; unsigned
[Microcontroller]
AT89C2051 single chip microcomputer drives stepper motor circuit and source code
Atmospheric temperature acquisition and recording system designed using AT89C2051 microcontroller for system coordination and control
1 Introduction The measurement of atmospheric temperature is of great significance. Generally, various thermometers are used for manual measurement, and the measurement results are recorded regularly. This method is time-consuming, labor-intensive, and very inconvenient. This article proposes a very compact atmospheri
[Microcontroller]
Atmospheric temperature acquisition and recording system designed using AT89C2051 microcontroller for system coordination and control
AT89C2051 simple sine wave, triangle wave, square wave generator
/********************************************************************                   Simple sine wave, triangle wave, square wave generator                   using keil C51, 12MHz crystal oscillator, AT89C2051  ******************************************************************/  #include "reg51.h"  #define uchar un
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号