A simple revolution counter - Designs of simple complexity - Schemes for beginners. Amateur radio circuits on meters Electricity meter on a microcontroller

A simple revolution counter - Designs of simple complexity - Schemes for beginners.  Amateur radio circuits on meters Electricity meter on a microcontroller
A simple revolution counter - Designs of simple complexity - Schemes for beginners. Amateur radio circuits on meters Electricity meter on a microcontroller

COUNTER ON THE MICROCONTROLLER

Many technical and automation devices still have mechanical counters installed. They count the number of visitors, products on the conveyor, turns of wire in winding machines, and so on. If it fails, it is not easy to find such a mechanical meter, and it is impossible to repair it due to the lack of spare parts. I propose to replace the mechanical counter with an electronic one using a PIC16F628A microcontroller.

An electronic counter turns out to be too complex if it is built on microcircuits of the K176, K561 series. especially if a reverse account is needed. But you can build a counter on just one chip - the universal PIC16F628A microcontroller, which includes a variety of peripheral devices and is capable of solving a wide range of problems.

So recently a person asked me to make a multi-digit pulse counter. I decided against LED indicators because they take up a lot of space and consume a lot of energy. Therefore, I implemented the circuit on LCD. The counter on the microcontroller can measure input pulses of up to 15 digits. The first two digits are separated by a dot. EEPROM was not used because there was no need to remember the meter state. There is also a countdown function - reverse. Schematic diagram of a simple counter on a microcontroller:

The counter is assembled on two printed circuit boards made of foil fiberglass. The drawing is shown in the figure.

One of the boards has an LCD indicator, the other has 4 buttons, a controller and other parts of the meter, with the exception of the power supply. You can download the boards and the counter circuit in Lay format, as well as the microcontroller firmware on the forum. Material provided by Samopalkin.

2006

To calculate the electrical energy consumed over a certain period of time, it is necessary to integrate the instantaneous values ​​of active power over time. For a sinusoidal signal, power is equal to the product of voltage and current in the network at a given time. Any electric energy meter works on this principle.

2006

Installing and connecting an electric meter is not difficult. The panel with the meter must be installed on four rollers (at the corners of the panel) in the room, near the place where the electrical wiring from the common apartment meter passes

2012

This device monitors household electrical usage and records readings on an SD memory card. Simple analog amplifiers amplify the signal from voltage and current sensors, and based on the data received, the ATmega168 microcontroller calculates power consumption. Voltage and current are measured at 9615Hz, so readings should be accurate even on non-sinusoidal loads such as computers or fluorescent lamps.

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 the input of a counter, 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 use switch S1 to turn on the power to the pulse shaper circuit. 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.

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 direction of counting 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 of 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.

Like flip-flops, counters do not necessarily need to be assembled manually from logical elements - today’s industry produces a wide variety of counters already assembled in microcircuit packages. In this article, I will not dwell on each counter chip separately (this is not necessary, and it will take too much time), but will simply briefly outline what you can count on when solving certain problems in digital circuitry. For those who are interested in specific types of counter chips, I can send them to my far from complete reference book on TTL and CMOS chips.

So, based on the experience gained in the previous conversation, we found out one of the main parameters of the counter - bit depth. In order for the counter to count up to 16 (including zero - this is also a number), we needed 4 digits. Adding each subsequent digit will exactly double the counter's capabilities. Thus, a five-bit counter can count up to 32, and a six-bit counter can count up to 64. For computer technology, the optimal bit depth is a multiple of four. This is not a golden rule, but still most counters, decoders, buffers, etc. are built four (up to 16) or eight-bit (up to 256).

But since digital circuitry is not limited to computers alone, counters with very different counting coefficients are often required: 3, 10, 12, 6, etc. For example, to build circuits for minute counters, we need a 60 counter, and it is easy to obtain by connecting a 10 counter and a 6 counter in series. We may also need a larger capacity. For these cases, for example, the CMOS series has a ready-made 14-bit counter (K564IE16), which consists of 14 D-flip-flops connected in series and each output except the 2nd and 3rd is connected to a separate pin. Apply pulses to the input, count and read, if necessary, the counter readings in binary numbers:

K564IE16

To facilitate the construction of counters of the required capacity, some microcircuits may contain several separate counters. Let's take a look at K155IE2 - BCD counter(in Russian – “counter up to 10, displaying information in binary code”):

The microcircuit contains 4 D-flip-flops, and 1 flip-flop (single-digit counter - divider by 2) is assembled separately - has its own input (14) and its own output (12). The remaining 3 flip-flops are assembled in such a way that they divide the input frequency by 5. For them, the input is pin 1, outputs 9, 8,11. If we need a counter up to 10, then we simply connect pins 1 and 12, apply counting pulses to pin 14, and from pins 12, 9, 8, 11 we remove the binary code, which will increase to 10, after which the counters will be reset and the cycle will repeat. The K155IE2 composite counter is no exception. A similar composition has, for example, K155IE4 (counter up to 2+6) or K155IE5 (counter up to 2+8):

Almost all counters have inputs for forced reset to “0”, and some have inputs for setting them to the maximum value. And finally, I just have to say that some counters can count both back and forth! These are so-called reversible counters, which can switch for counting both to increase (+1) and decrease (-1). So he can, for example, BCD up/down counter K155IE6:

When pulses are applied to input +1, the counter will count forward, pulses at input -1 will decrease the counter readings. If, as the readings increase, the counter overflows (pulse 11), then before returning to zero, it will output a “transfer” signal to pin 12, which can be applied to the next counter to increase the capacity. Pin 13 has the same purpose, but a pulse will appear on it when the count passes through zero when counting in the opposite direction.

Please note that in addition to reset inputs, the K155IE6 microcircuit has inputs for writing an arbitrary number to it (pins 15, 1, 10, 9). To do this, it is enough to set any number 0 - 10 in binary notation at these inputs and apply a write pulse to input C.