Car tachometer with LCD display on PIC16F628. Digital tachometer based on PIC16F628 microcontroller. Do-it-yourself digital tachometer diagram on pic

The car tachometer described below combines the high accuracy of readings inherent in digital meters with the convenience of reading engine speed values ​​​​on an analogue scale, which is most optimal for an on-board device.

The tachometer is designed for installation in cars with a four-cylinder gasoline engine and a contactless ignition system with a sensor Hall. You can also use the device to work together with a contact ignition system if you change its input circuit.

The tachometer displays readings in two forms - digital with a resolution of 30 minutes (more precisely 29.8 minutes) and in the form of a line of vertical strokes, and its length varies in proportion to the measured value. The number of elements in the line is 32, which is quite enough to estimate the value of the parameter.

The device diagram is shown in Fig. 1. The basis of the device is the DD1 microcontroller. The display uses a Russified liquid crystal module HG1 with backlight. If you were unable to purchase a Russified indicator, you will have to use the English equivalents of the words.

Picture 1.

The supply voltage is stabilized by a DA1 microcircuit stabilizer. Unit VT1R5R6 is a current stabilizer for the display backlight LEDs, which prevents the brightness from changing when the voltage in the vehicle's electrical system changes. Voltage divider R3R4 is used to set the desired contrast of the display image.

Ignition pulses from the Hall sensor through the VD3 diode are supplied to the RB0 input of the DD1 microcontroller, causing an interrupt, which reads the value of the TMR1 timer, then it is reset to zero and begins a new countdown of the time between pulses. To convert the duration t of the interval between ignition pulses into rotational speed, it is necessary to perform a division operation using the formula:

N=K/t, where N is the engine crankshaft rotation speed in min-1; K is a constant depending on the frequency of counting pulses of the TMR1 timer and the number of engine cylinders.

However, even at an absolutely stable crankshaft speed, the measured duration of the interval between Hall sensor pulses will not be the same. This is due to the precision of manufacturing the slots on the breaker cylinder, as well as the discreteness of the response time to pulses. To increase the accuracy of measurements and reduce the flickering of tachometer readings caused by these reasons, averaging of calculations is provided for every four ignition pulses, i.e., for two full revolutions of the crankshaft.

After the final calculation of the shaft speed, the readings are displayed on the first line. To prevent timer TMR1 from overflowing. at a rotation speed of less than 450 min-1, calculation and display are prohibited. Then the length of the ruler is calculated, depicting the measured value in quasi-analog form. The “zero” of the ruler scale is set at a shaft rotation speed of 750 min-1, and the end of the scale corresponds to a frequency of 5720 min-1.

It should be noted that the resolution of the device does not remain constant, changing within small limits, depending on the time of determining the moment of interruption relative to the real moment of the ignition pulse. In order to eliminate the constant flickering of the last digit on the display, it is programmed to be equal to zero, which corresponds to a slight additional measurement error.

An additional function has been introduced into the tachometer - displaying the position of the carburetor air damper. People often forget to press down the button for this damper after the engine has already warmed up, and further operation of the engine with the damper not fully open leads to an over-richness of the fuel mixture and increased gasoline consumption.

To perform this function, it is necessary to install a microswitch on the carburetor that opens its contacts when the air damper is fully opened. One of the contacts should be connected to the car body, and the second should be connected to the “Drottle” input. Since carburetors may vary, the design of this unit has been omitted.

While the microswitch contacts are closed, in the first line of the display the words “TACHOMETER” and “DAMPER” alternately change with a second interval, while the tachometer readings are constantly present. And only when the air damper is fully open, the inscription “DAMPER” does not appear.

The device is assembled on a printed circuit board made of foil fiberglass laminate 1.5 mm thick. The LCD module is located on the printed side of the board (the board and module are the same in width and length), all other parts are on the reverse side. The board in the case is mounted on four threaded (M2.5) racks. The module is attached to the same racks through four spacer bushings 5 ​​mm high and connected to the board with thin flexible conductors. Connector X1 for connecting the tachometer to external circuits is any small-sized four-pin connector, it is connected to the board with pieces of mounting wire. All resistors in the tachometer are MLT. Capacitors C1, C7 - K50-16; the rest are of any type, for example KM-6. Diodes and transistor - of the specified types with any letter index.

The body is glued together from transparent polystyrene sheet about 1 mm thick (a CD case was used as a blank) and painted with nitro paint in aerosol packaging. The window under the display is sealed with a piece of adhesive tape before painting.

The housing is made in such a way and the device is mounted in the car so that the plane of the indicator is slightly tilted back from the position transverse to the view - while the contrast of the image on the display is maximum. Therefore, it is convenient to place the tachometer above the dashboard, near the windshield. In this case, by the way, if you turn the device with the display towards the glass, it will be convenient to monitor the engine shaft rotation speed while working in the engine compartment.

For those who want to install the tachometer directly on the instrument panel, in place of one of the plugs, firstly, they will not need to make a housing, and secondly, they will have to purchase another display - AC162AYILY-H, from the same Atmel company. In the passport of this display, the viewing angle is designated as “12 o’clock” (for AC162AYJLY-H - “6 o’clock”), which indicates maximum contrast when viewed from above.

class="eliadunit">

In addition to those indicated, similar modules produced by other companies are also suitable; the interface of these indicators is similar. If the display backlight is not needed or the purchased device does not have it, transistor VT1 and resistors R5 and R6 can be omitted.

When installing a tachometer in a car, the “Input” contact of connector X1 must be connected directly to the middle terminal of the breaker connector using a shielded wire, the braid of which is connected only on one side to the “Common” contact of connector X1 of the device. If the air damper position indication is not needed, the “Damper” contact of the connector is left free. Power is supplied to the device from the vehicle circuit where voltage appears when the ignition is turned on.

This tachometer circuit on a microcontroller serves to measure the number of revolutions of virtually any internal combustion engine. The indication is made on a four-digit LED indicator, the measurement accuracy is 50 rpm.

Description of the tachometer operation on the PIC16F628 microcontroller

After applying the supply voltage, the digital tachometer immediately begins to verify the number of revolutions. The “SELECT” button selects one of nine speed measurement modes, depending on the type of vehicle sensor.

The first press of “SELECT” will display the current value of the number of pulses that the sensor produces per revolution of the flywheel. Initially set to 2 pulses per revolution. Accordingly, the indicator will display P-2.0. Each subsequent press of “SELECT” will cycle through all available values ​​(0.5; 1; 2; 3; 4; 5; 6; 7; 8 pulses/revolution)

Upon completion of the selection of the required pulse value, after approximately 5 seconds the tachometer will remember it in the memory of the PIC16F628 microcontroller and enter the operating mode for measuring revolutions. The next time you turn on the tachometer, it is no longer necessary to set the pulses again.

For accurate operation of the digital tachometer, it is necessary to pay attention to the design of the input circuit. For each individual ignition system (depending on the car brand), it may be necessary to adjust the ratings so that the tachometer does not react to higher harmonics, and reacts firmly to the main one.

In the updated firmware version (tacho_univ_new), a 2-second indicator test function has been added to identify their possible malfunction.

The tachometer is designed to measure the speed of almost any engine. Starting from a moped 1-cylinder two-stroke engine and ending with a 16-cylinder 4-stroke engine. Indication on a 4-digit digital indicator, measurement accuracy 50
rpm.

After turning on the power, the tachometer immediately begins to measure revolutions. The first press of the button will cause an indication of the set number of pulses per 1 revolution (by default 2 pulses per 1 revolution, which corresponds to a 4-stroke 4-cylinder engine). The display will show P-2.0. Pressing the button again will cause a search of all permissible values ​​- from 0.5 to 8 pulses per 1 revolution. It may seem a little strange - 0.5 pulses, but this just means that 1 pulse will be in 2 revolutions. After setting the required number of pulses, after about 5 seconds, the device will record the changes in the non-volatile EEPROM memory (i.e., when you turn on the power again, you do not need to set the number of pulses again), and switch to the speed measurement mode with the newly set number of pulses.

Printed circuit board with two parts

Photo from lawyer

Good afternoon.
I present for your consideration a diagram of a simple digital tachometer on AVR ATtiny2313, KR514ID2, and an optocoupler designed by me.
Let me make a reservation right away: there are many similar schemes on the Internet. Each implementation has its own pros and cons. Perhaps my option will be more suitable for someone.

I'll probably start with those. tasks.
Task: you need to make a digital tachometer to control the speed of the electric motor of the machine.
Introductory conditions: There is a ready-made reference disk with 20 holes from a laser printer. There are many optocouplers available from broken printers. Average (working) speeds are 4,000-5,000 rpm. The error of the displayed results should not exceed ± 100 revolutions.

Limitation: the power supply for the control unit is 36V (the tachometer will be installed in the same housing with the control unit - more on that below).

A small lyrical digression. This is my friend's machine. The machine is equipped with a PIK-8 electric motor, the speed of which is controlled according to a modified diagram found on the Internet. At the request of a friend, a simple tachometer for the machine was developed.

Initially, it was planned to use ATMega16 in the circuit, but after considering the conditions, it was decided to limit ourselves to ATtiny2313, operating from an internal (RC) oscillator at a frequency of 4 MHz.

General scheme as follows:

As you can see, nothing complicated. To convert binary code into seven-segment, I used the KR514ID2 decoder, this gives three advantages at once.

  • Firstly, it saves space in the ATtiny2313 memory by reducing the working code (since the procedure for software conversion of binary code to seven-segment is not included in the firmware as it is unnecessary).
  • Secondly: reducing the load on the ATtiny2313 outputs, because the LEDs are “illuminated” by KR514ID2 (when the number 8 is displayed, the maximum consumption will be 20-30 mA (typical for one LED) * 7 = 140-210 mA, which is “a lot” for the ATtini2313 with its full nameplate maximum (loaded) consumption of 200 mA).
  • Thirdly, the number of “busy” legs of the microcontroller has been reduced, which gives us the opportunity in the future (if necessary) to upgrade the circuit by adding new capabilities.

Assembling the device implemented on a breadboard. To do this, a circuit board from a non-working microwave oven lying in the bins was disassembled. The digital LED indicator, key transistors (VT1-VT4) and limiting resistors (R1 - R12) were taken as a kit and transferred to the new board. The entire device is assembled, if the necessary components are available, with smoke breaks in half an hour. Paying attention: for the KR514ID2 microcircuit, the positive power leg is 14, and the negative one is 6 (marked in the diagram). Instead of KR514ID2, you can use any other binary code decoder into a seven-segment one powered by 5V. I took what was at hand.
The “h” and “i” pins of the digital LED indicator are responsible for two points in the center between the numbers; they are not connected as unnecessary.
After assembly and firmware, provided there are no installation errors, the device starts working immediately after switching on and does not require configuration.

If it is necessary to make changes to the tachometer firmware, an ISP connector is provided on the board.

In the diagram, pull-up resistor R12, rated 30 kOhm, was selected experimentally for a specific optocoupler. As practice shows, it may differ for different optocouplers, but the average value of 30 kOhm should ensure stable operation for most printer optocouplers. According to the ATtiny2313 documentation, the value of the internal pull-up resistor ranges from 20 to 50 kOhm, depending on the implementation of a specific batch of microcontrollers (page 177 of the ATtiny2313 passport), which is not entirely suitable. If anyone wants to repeat the circuit, they can first turn on the internal pull-up resistor, perhaps it will work for you, for your optocoupler and your MK. It didn't work for me for my set.

This is what a typical optocoupler from a printer looks like.

The optocoupler LED is powered through a 1K limiting resistor, which I placed directly on the board with the optocoupler.
To filter voltage ripples, there are two capacitors in the circuit, an electrolytic one of 220 µF x 25V (which was on hand) and a ceramic one of 0.1 µF (the general circuit for connecting the microcontroller is taken from the ATtiny2313 data sheet).

To protect it from dust and dirt, the tachometer board is coated with a thick layer of automotive varnish.

Replacement of components.
You can use any four-digit LED indicator, either two double or four single. At worst, assemble the indicator on separate LEDs.

Instead of KR514ID2, you can use KR514ID1 (which contains current-limiting resistors inside), or 564ID5, K155PP5, K155ID9 (when the legs of one segment are connected in parallel), or any other binary to seven-segment converter (with appropriate changes in the connection of the microcircuit pins).

Provided the installation is correctly transferred to the ATMega8/ATMega16 MK, this firmware will work as on the ATtiny2313, but you need to correct the code (change the names of the constants) and recompile. Comparisons have not been made for other AVR MCUs.

Transistors VT1-VT4 - any low-current ones, operating in switch mode.

Principle of operation is based on counting the number of pulses received from an optocoupler in one second and recalculating them to display the number of revolutions per minute. For this purpose, an internal counter Timer/Counter1 is used, operating in the mode of counting pulses arriving at input T1 (pin PD5 pin 9 MK). To ensure stable operation, software debounce mode is enabled. Seconds are counted by Timer/Counter0 plus one variable.

Calculation of revolutions, which I would like to focus on, occurs according to the following formula:
M = (N / 20) *60,
where M is the estimated revolutions per minute (60 seconds), N is the number of pulses from the optocoupler per second, 20 is the number of holes in the reference disk.
In total, simplifying the formula we get:
M = N*3.
But! The ATtiny2313 microcontroller does not have a hardware multiplication function. Therefore, summation with offset was applied.
For those who do not know the essence of the method:
The number 3 can be expanded as
3 = 2+1 = 2 1 + 2 0 .
If we take our number N, shift it to the left by 1 byte and add another N shifted to the left by 0 bytes, we get our number N multiplied by 3.
In the firmware, the code on the AVR ASM for a two-byte multiplication operation looks like this:

Mul2bytes3:
CLR LoCalcByte //clear working registers
CLR HiCalcByte
mov LoCalcByte,LoInByte //load values ​​received from Timer/Counter1
mov HiCalcByte,HiInByte
CLC //clean household transfer
ROL LoCalcByte //shift through the carry bit
ROL HiCalcByte
CLC
ADD LoCalcByte,LoInByte //sum, taking into account the carry bit
ADC HiCalcByte,HiInByte
ret

Functionality check and accuracy measurement was carried out as follows. A cardboard disk with twenty holes was glued to the computer cooler fan. The cooler speed was monitored through the motherboard BIOS and compared with the tachometer readings. The deviation was about 20 revolutions at a frequency of 3200 revolutions/minute, which is 0.6%.

It is quite possible that the real discrepancy is less than 20 revolutions, because Motherboard measurements are rounded within 5 turns (based on personal observations for one specific board).
The upper limit of measurement is 9,999 rpm. The lower limit of measurement, theoretically from ±10 revolutions, but was not measured in practice (one pulse from an optocoupler per second gives 3 revolutions per minute, which, taking into account the error, should theoretically correctly measure speeds from 4 revolutions per minute and above, but in practice this the indicator must be at least doubled).

I will separately dwell on the issue of nutrition.
The entire circuit is powered from a 5V source, the estimated consumption of the entire device does not exceed 300 mA. But, according to the terms of the technical specifications, the tachometer must be structurally located inside the engine speed control unit, and a constant voltage of 36V is supplied to the unit from LATR. In order not to pull a separate power wire, an LM317 is installed inside the unit in the nameplate mode, in the mode of reducing the power to 5V (with limiting resistor and zener diode to protect against accidental overvoltage). It would be more logical to use a PWM controller in step-down converter mode, like the MC34063, but in our city it’s problematic to buy such things, so we used what we could find.

Photos tachometer boards and the finished device.


More photos







Unfortunately, it is currently not possible to take photographs on the machine.

After the layout of the boards and the first test assembly, the box with the device went for painting.

If your tachometer does not work immediately after switching on, with known correct installation:

1) Check the operation of the microcontroller, make sure that it is powered by an internal generator. If the circuit is assembled correctly, four zeros should be displayed on the dial.

2) Check the level of pulses from the optocoupler, if necessary, select the value of resistor R12 or replace the optocoupler connection circuit. It is possible to reverse connect the optotransistor with a pull-up to minus, with the internal pull-up resistor MK turned on or not. It is also possible to use the transistor in the switching (inverting) mode of operation.
optocoupler

  • AVR
  • Add tags

    What is it anyway tachometer? A tachometer is a device used to measure the RPM (revolutions per minute) of any rotating body. Tachometers are made on the basis of contact or non-contact ones. Non-contact optical tachometers typically use a laser or infrared beam to monitor the rotation of any body. This is done by calculating the time taken for one rotation. In this material, taken from an English site, we will show you how to make a portable digital optical tachometer using Arduino Uno. Let's consider an extended version of the device with an LCD display and a modified code.

    Tachometer circuit on a microcontroller

    Schematic parts list

    • Microcircuit - Arduino
    • Resistors - 33k, 270 ohm, 10k potentiometer
    • LED element - blue
    • IR LED and Photodiode
    • 16 x 2 LCD screen
    • 74HC595 shift register

    Here, instead of a slot sensor, an optical one is used - reflection of the beam. This way they don't have to worry about the thickness of the rotor, the number of blades won't change the reading, and it can read the drum revolutions - which the slot sensor cannot.

    So first of all you will need an IR emitting LED and a photodiode for the sensor. How to assemble it is shown in step-by-step instructions. Click on the photo to enlarge the size.

    • 1. First you need to sand the LED and photodiode to make them flat.
    • 2. Then fold the strip of paper sheet as shown in the picture. Make two such structures so that the LED and photodiode fit tightly into it. Connect them together with glue and paint them black.
    • 3. Insert LED and photodiode.
    • 4. Glue them together with superglue and solder the wires.

    Resistor values ​​may vary depending on which photodiode you are using. The potentiometer helps to reduce or increase the sensitivity of the sensor. Solder the sensor wires as shown in the figure.

    The tachometer circuit uses a 74HC595 8-bit shift register with a 16x2 LCD display. Make a small hole in the housing to fix the LED indicator.

    Solder a 270 ohm resistor onto the LED and insert it into pin 12 of the Arduino. The sensor is inserted into a cubic tube to give additional mechanical strength.

    That's it, the device is ready for calibration and programming. You can download the program from this link.

    Video of a homemade tachometer working


    High voltage security device - electric hedgehog. Today we will continue our conversations about the structures that are needed to protect our home. The device that we will now consider is intended for protecting an apartment, office, cottage and car. The device is called a high-voltage electric hedgehog!