Stairs.  Entry group.  Materials.  Doors.  Locks.  Design

Stairs. Entry group. Materials. Doors. Locks. Design

» Pulse counter with memory on a microcontroller. A simple revolution counter - Designs of simple complexity - Circuits for beginners Do-it-yourself digital revolution counter

Pulse counter with memory on a microcontroller. A simple revolution counter - Designs of simple complexity - Circuits for beginners Do-it-yourself digital revolution counter

Pulse counter is a serial digital device that provides storage of a word of information and the execution of a counting micro-operation on it, which consists in changing the value of a number in the counter to 1. Essentially, the counter is a set of triggers connected in a certain way. The main parameter of the counter is the counting module. This is the maximum number of single signals that can be counted by the counter. Counters are designated by ST (from the English counter).

Pulse counters are classified

● by count modulo:
. BCD;
. binary;
. with an arbitrary constant counting module;
. with variable counting module;
. in the direction of the account:
. summative;
. subtractive;
. reversible;
● by the method of forming internal connections:
. with sequential transfer;
. with parallel transfer;
. with combined transfer;
. ring.

Summing pulse counter

Consider a summing counter (Fig. 3.67, A). Such a counter is built on four JK flip-flops, which, if there is a logical signal “1” at both inputs, switch when negative voltage drops appear at the synchronization inputs.

Timing diagrams illustrating the operation of the counter are shown in Fig. 3.67, b. Ksi denotes the counting modulus (pulse counting coefficient). The state of the left trigger corresponds to the least significant digit of the binary number, and the right one corresponds to the most significant digit. In the initial state, all flip-flops are set to logical zeros. Each trigger changes its state only at the moment when it is affected by a negative voltage drop.

Thus, this counter implements the summation of input pulses. From the timing diagrams it can be seen that the frequency of each subsequent pulse is two times less than the previous one, that is, each trigger divides the frequency of the input signal by two, which is used in frequency dividers.

Three-bit subtractor counter with serial carry

Let's consider a three-bit subtracting counter with sequential carry, the circuit and timing diagrams of which are shown in Fig. 3.68.
(xtypo_quote)The counter uses three JK flip-flops, each of which operates in T-flip-flop mode (flip-flop with a counting input).(/xtypo_quote)

Logic 1s are applied to the inputs J and K of each flip-flop, therefore, upon the arrival of the falling edge of the pulse supplied to its synchronization input C, each flip-flop changes the previous state. Initially, the signals at the outputs of all flip-flops are equal to 1. This corresponds to storing the binary number 111 or the decimal number 7 in the counter. After the end of the first pulse F, the first flip-flop changes state: the signal Q 1 becomes equal to 0, a ¯ Q 1 − 1.

The remaining triggers do not change their state. After the end of the second synchronization pulse, the first trigger changes its state again, moving to state 1, (Q x = 0). This ensures a change in the state of the second trigger (the second trigger changes state with some delay relative to the end of the second synchronization pulse, since its overturning requires time corresponding to the time of operation of itself and the first trigger).

After the first pulse F, the counter stores the state 11O. Further changes in the counter state occur in the same way as described above. After state 000, the counter goes back to state 111.

Three-digit self-stopping subtracting counter with serial carry

Consider a three-bit self-stopping subtractive counter with sequential carry (Fig. 3.69).

After the counter transitions to state 000, a logical 0 signal appears at the outputs of all flip-flops, which is fed through an OR logic element to the inputs J and K of the first flip-flop, after which this flip-flop exits the T-flip-flop mode and stops responding to F pulses.

Three-bit up/down counter with serial carry

Consider a three-bit up/down counter with sequential carry (Fig. 3.70).

In subtraction mode, the input signals must be applied to the Tv input. In this case, a logical 0 signal is supplied to the T c input. Let all flip-flops be in state 111. When the first signal arrives at the T c input, a logical 1 appears at the T input of the first flip-flop, and it changes its state. After this, a logical 1 signal appears at its inverse input. When a second pulse arrives at input T, a logical 1 will appear at the input of the second trigger, so the second trigger will change its state (the first trigger will also change its state upon arrival of the second pulse). Further changes in state occur in a similar way. In addition mode, the counter operates similarly to a 4-bit adding counter. In this case, the signal is supplied to the T c input. A logical 0 is applied to the T input.
As an example, consider microcircuits of reversing counters (Fig: 3.71) with parallel transfer of the 155 series (TTL):
● IE6 – binary decimal up/down counter;
● IE7 – binary up/down counter.

The counting direction is determined by which pin (5 or 4) the pulses are sent to. Inputs 1, 9, 10, 15 are informational, and input 11 is used for pre-recording. These 5 inputs allow pre-recording to the counter (preset). To do this, you need to submit the appropriate data to the information inputs, and then apply a low-level write pulse to input 11, and the counter will remember the number. Input 14 is the O setting input when a high voltage level is applied. To build counters of larger capacity, forward and reverse transfer outputs are used (pins 12 and 13, respectively). From pin 12 the signal should be fed to the forward counting input of the next stage, and from pin 13 to the downward counting input.

-20 dB wrote:
Why not approach the matter with little bloodshed? If there is something like the above-mentioned IZhTS5-4/8, with separate segment outputs?

In the stash of unused K176IE4 from Soviet times, there was a lot left (a counter/divider by 10 with a seven-segment decoder and a transfer output, used to form units of minutes and hours in an electronic watch, an incomplete analogue - CD4026 - what is the incompleteness, haven’t looked... yet) in classic switching on for LCD control. 4 pcs - 2 per channel, + 2 pcs. 176(561)LE5 or LA7 - one for single pulse shapers (contact bounce suppressors), the second - for forming a meander to “illuminate” the LCD indicator?

Of course, the solution on MP is more beautiful, but on garbage it’s cheaper, and can only be solved on the knee... With MP programming, for example, I have a hard time (unless someone hands me a ready-made dump) - it’s easier for me with hardware.


Well, I'm willing to bet here. Let's do the math. For starters, the cost:
1. PIC12LF629 (SOIC-8) - 40 rub. (~$1.15)
2. Display from Motorola S200/S205/T190/T191 - about 90 rubles (~$2.57) In addition, the resolution is 98x64 - draw and write what you want.
3. Bulk (SMD shortcuts, buttons, SMD capacitors, etc.) at a glance - about 50 rubles. (~$1.42)

Total: ~180rub (~$5)

The case, the battery (I would choose the Lo-Pol battery from the same C200 motor scooter - compact, capacious, inexpensive (relatively)) - we don’t count it, since both are needed in both options.

Now your option:

1. LCI5-4/8 - about 50 rubles (~$1.42)
2. K176IE4 (CD4026) - 15 rubles (~0.42$)x4=60 rubles (~1.68$)
3. K176LA7 - 5 rubles (~0.14$)x4=20 rubles (~0.56$)
4. Bulk (SMD shortcuts, buttons, SMD capacitors, etc.) at a glance - about 50 rubles. (~$1.42)

Total: ~180rub (~$5)

What's the benefit?

Now let’s estimate the performance characteristics and functionality:

The version with MK will have consumption maximum 20mA, while in your version, I think 1.5...2 times more. In addition, in your version - the complexity (relative) of a printed circuit board on 7 cases + multi-legged ILC5-4/8 (probably double-sided), the inability to upgrade the device (add or change functionality) without getting into the circuit (only at the software level), the lack of possibility organize memory for measurements (counting), power supply of at least 5V (with less you will not swing the LCI), weight and dimensions. There are many more arguments that can be given. Now the option with MK. I already wrote about the current consumption - 20mA max. + the possibility of a sleep mode (consumption - 1...5 mA (mainly LCD)), the complexity of the board for one 8-leg microcircuit and a 5-pin connector for a Motorola LCD is ridiculous even to say. Flexibility (you can do something like this programmatically, without changing the circuit or board - it will make your hair stand on end), the information content of the 98x64 graphic display cannot be compared with the 4.5 digits of a 7-segment LCI. power supply - 3...3.5V (you can even use a CR2032 tablet, but Li-Pol from a mabyl is still better). The ability to organize multi-cell memory for the measurement results (counts) of the device - again, only at the software level without interfering with the circuit and board. And finally - the dimensions and weight cannot be compared with your option. The argument “I don’t know how to program” will not be accepted - whoever wants to will find a way out. Until yesterday, I did not know how to work with the display from the Motorola S205 mobile phone. Now I can. A day has passed. Because I NEED it. In the end, you are right - you can ask someone.)) That's something like this. And it’s not a matter of beauty, but the fact that discrete logic is hopelessly outdated both morally and technically as the main element of circuit design. What required dozens of cases with wild total consumption, complexity of PP and huge dimensions can now be assembled with a 28-40 foot MK easily and naturally - believe me. Now there is even much more information on MK than on discrete logic - and this is quite understandable.

Everyone knows why a microcalculator exists, but it turns out that in addition to mathematical calculations, it is capable of much more. Please note that if you press the “1” button, then “+” and then press “=”, then with each press of the “=” button the number on the display will increase by one. Why not a digital counter?

If two wires are soldered to the “=” button, they can be used as a counter input, for example, a turns counter for a winding machine. And after all, the counter can also be reversible; to do this, you must first dial a number on the display, for example, the number of turns of the coil, and then press the “-” button and the “1” button. Now, each time you press “=” the number will decrease by one.

However, a sensor is needed. The simplest option is a reed switch (Fig. 1). We connect the reed switch with wires parallel to the “=” button, the reed switch itself stands on the stationary part of the winding machine, and we fix the magnet on the movable one, so that during one revolution of the coil the magnet passes near the reed switch once, causing it to close.

That's all. You need to wind the coil, do “1+” and then with each turn, that is, with each turn the display readings will increase by one. You need to unwind the coil - enter the number of turns of the coil on the microcalculator display, and make “-1”, then with each revolution of unwinding the coil, the display readings will decrease by one.

Fig.1. Connection diagram of the reed switch to the calculator.

And, suppose you need to measure a large distance, for example, the length of a road, the size of a plot of land, the length of a route. We take a regular bicycle. That's right - we attach a non-metallic bracket with a reed switch to the fork, and we attach the magnet to one of the spokes of the bicycle wheel. Then, we measure the circumference of the wheel, and express it in meters, for example, the circumference of the wheel is 1.45 meters, so we dial “1.45+”, after which with each revolution of the wheel the display readings will increase by 1.45 meters, and as a result, the display will show the distance traveled by the bike in meters.

If you have a faulty Chinese quartz alarm clock (usually their mechanism is not very durable, but the electronic board is very reliable), you can take a board from it and, according to the circuit shown in Figure 2, make a stopwatch out of it and a calculator.

Power is supplied to the alarm clock board through a parametric stabilizer on the HL1 LED (the LED must have a direct voltage of 1.4-1.7V, for example, red AL307) and resistor R2.

The pulses are generated from the control pulses of the stepper motor of the clock mechanism (the coils must be disconnected, the board is used independently). These pulses travel through diodes VD1 and VD2 to the base of transistor VT1. The alarm board supply voltage is only 1.6V, while the pulse levels at the outputs for the stepper motor are even lower.

For the circuit to work properly, diodes with a low level of forward voltage, such as VAT85, or germanium are required.

These pulses arrive at the transistor switch at VT1 and VT2. The collector circuit VT2 includes the winding of a low-power relay K1, the contacts of which are connected in parallel to the “=” button of the microcalculator. When there is +5V power, the contacts of relay K1 will close at a frequency of 1 Hz.

To start the stopwatch, you must first perform the “1+” action, then turn on the power to the pulse shaper circuit using switch S1. Now, with every second, the display readings will increase by one.

To stop counting, simply turn off the power to the pulse shaper using switch S1.

In order to have a count for reduction, you must first enter the initial number of seconds on the microcalculator display, and then do the “-1” action and turn on the power to the pulse shaper with switch S1. Now, with every second, the display readings will decrease by one, and from them it will be possible to judge how much time is left until a certain event.

Fig.2. Scheme for turning a Chinese hanger into a stopwatch.

Fig.3. Circuit diagram of an IR beam intersection counter using a calculator.

If you use an infrared photo sensor that works at the intersection of the beam, you can adapt the microcalculator to count some objects, for example, boxes moving along a conveyor belt, or by installing the sensor in the aisle, count people entering the room.

A schematic diagram of an IR reflection sensor for working with a microcalculator is shown in Figure 3.

The IR signal generator is made on an A1 chip of type “555” (integrated timer). It is a pulse generator with a frequency of 38 kHz, at the output of which an infrared LED is switched on. The generation frequency depends on the C1-R1 circuit; when setting up by selecting resistor R1, you need to set the frequency at the output of the microcircuit (pin 3) to close to 38 kHz. The HL1 LED is placed on one side of the passage, putting an opaque tube on it, which must be precisely aimed at the photodetector.

The photodetector is made on the HF1 chip - this is a standard integrated photodetector of the TSOP4838 type for remote control systems for TVs and other home appliances. When a beam from HL1 hits this photodetector, its output is zero. In the absence of a beam - one.

Thus, there is nothing between HL1 and HF1 - the contacts of relay K1 are open, and at the moment of the passage of any object, the relay contacts are closed. If you perform the “1+” action on the microcalculator, then with each passage of an object between HL1 and HF1, the microcalculator display readings will increase by one, and from them you can judge how many boxes were shipped or how many people entered.

Kryukov M.B. RK-2016-01.

The counter on the microcontroller is quite simple to repeat and is assembled on the popular PIC16F628A microcontroller with an indication output on 4 seven-segment LED indicators. The counter has two control inputs: “+1” and “-1”, as well as a “Reset” button. The control of the new counter circuit is implemented in such a way that no matter how long or short the input button is pressed, counting will continue only when it is released and pressed again. The maximum number of received pulses and, accordingly, ALS readings is 9999. When controlled at the “-1” input, the counting is carried out in reverse order to the value 0000. The counter readings are saved in the controller’s memory even when the power is turned off, which will save the data in the event of random interruptions in the supply voltage.

Schematic diagram of a reverse counter on the PIC16F628A microcontroller:

Resetting the counter readings and at the same time the memory state to 0 is carried out by the “Reset” button. It should be remembered that when you first turn on the reverse counter on the microcontroller, unpredictable information may appear on the ALS indicator. But the first time you press any of the buttons, the information is normalized. Where and how this circuit can be used depends on the specific needs, for example, installed in a store or office to count people or as an indicator for a winding machine. In general, I think that this counter on a microcontroller will be useful to someone.

If someone does not have the required ALS indicator at hand, but has some other one (or even 4 separate identical indicators), I am ready to help redraw the signet and redo the firmware. In the archive on the forum there is a circuit diagram, board and firmware for indicators with a common anode and a common cathode. The printed circuit board is shown in the figure below:

There is also a new firmware version for the counter on the PIC16F628A microcontroller. at the same time, the circuit and board of the meter remained the same, but the purpose of the buttons changed: button 1 - pulse input (for example, from a reed switch), button 2 turns on the counting for subtracting input pulses, while the leftmost point on the indicator lights up, button 3 - adding pulses - The rightmost point lights up. Button 4 - reset. In this version, the counter circuit on a microcontroller can be easily applied to a winding machine. Just before winding or unwinding turns, you must first press the “+” or “-” button. The meter is powered from a stabilized source with a voltage of 5V and a current of 50mA. If necessary, it can be powered by batteries. The case depends on your tastes and capabilities. Scheme provided by Samopalkin

If you are faced with the task of implementing a pulse counter, counting tens, hundreds or thousands, then for this it is enough to use a ready-made assembly - the CD4026 microcircuit. Fortunately, the microcircuit practically eliminates all worries about wiring the microcircuit and additional matching elements. At the same time, one CD4026 counter is capable of “counting” only up to 10, that is, if we need to count up to 100, then we use 2 microcircuits, if up to 1000, then 3, etc. Well, let's say a few words about the chip itself and its functionality.

Description of operation of the CD4026 counter

Initially, we present the appearance and functional designation of the pins on the counter chip

Despite the fact that everything is in English, in principle everything here is clear! The counter readings increase by 1 unit each time a positive pulse arrives at the “clock” contact. In this case, a voltage appears at outputs a-g, which, when applied to a 7-segment indicator, will display the number of pulses.

The “reset” contact resets the counting readings when shorted to +.

The "disable clock" pin must also be connected to ground.

The “enable display” contact, in fact, contact 3 must be connected to the positive.

Contact “÷10” is actually output 5, sends a signal about the counter overflow, so that a similar counter can be connected to it and start counting for 10, 100, 1000...

The “not 2” contact takes the value LOW if and only if the counter value is 2. Otherwise, HIGH.

The operating supply voltage of the microcircuit is 3-15 V. That is, it has a built-in stabilizer. Now let’s talk about how to connect this microcircuit to the assembly, that is, about the circuit diagram.

Connection diagram for a pulse counter on a CD4026 chip

Take a look at the diagram. It counts light pulses of changes in resistance for a photoresistor. As a photoresistor, you can use, say, a 5516 photoresistor. So, due to a change in resistance, the potential at the base of the transistor also shifts. As a result, current begins to flow through the collector-emitter circuit, which means a pulse is supplied to input 1 of the microcircuit, which must be counted.
As soon as the first microcircuit counts 1 ten, then one pulse appears at pin 5 indicating the “overflow” of the counter. Ultimately, this impulse is supplied to a second microcircuit, which operates on exactly the same principle. But in this case, the microcircuit no longer counts units, but tens. If you add 3 microcircuits, then it will be hundreds, etc.

To reset to 0, just apply a plus to the legs of 15 microcircuits. The microcircuit is designed to work with a 7 segment indicator. When applied to one of the outputs of this indicator, we get the number we need. Take a look at the table...

In conclusion, I would like to say once again that the pulse counter in this case is functional and will require minimal costs and knowledge from you. What is also important is that the circuit does not need to be configured, at least the digital part. The only thing is that you may have to “play around” with resistors and a photoresistor at the input.