Digital scale frequency meter on pic16f628a. Frequency counter on PIC16F628. Do-it-yourself radio engineering, electronics and circuits. Let's start assembling

  • 28.09.2014

    This receiver operates in the range of 64-75 MHz and has a real sensitivity of 6 µV, output power 4 W, AF range - 70...10000 Hz, THD no more than 1%. With these parameters, the receiver has dimensions of 60*70*25 mm. The receiving path is assembled on KS1066ХА1 (К174ХА42) according to the standard scheme. The antenna is a wire about a meter long, the signal is from...

  • 29.09.2014

    The circuit is made on two TVA1208 microcircuits. It is based on the transceiver circuit printed in L,1, but this path works with intermediate frequency 500 kHz, which, of course, somewhat reduces its characteristics, but allows the use of a ready-made electromechanical filter configured at the factory. TVA1208 microcircuits are designed to work in the second IF3 path of televisions. In them...

  • 20.09.2014

    Classification of magnetic materials Magnetic materials are most widely used in electrical engineering; without them, electrical machines, transformers, and electrical measuring instruments are currently unthinkable. Depending on the application, magnetic materials are subject to different, sometimes contradictory, requirements. Based on their application, magnetic materials are classified into two large groups: soft magnetic hard magnetic Let's briefly consider their characteristics. ...

  • 10.12.2017

    The figure shows a circuit of a simple, highly sensitive acoustic switch that controls a load using a relay. The circuit uses an electret microphone; when using an ECM microphone, it is necessary to use a resistor R1 with a resistance of 2.2 kOhm to 10 kOhm. The first two transistors represent a pre-microphone amplifier, R4 C7 in the circuit eliminates the instability of the amplifier. ...

This article describes how to connect a liquid crystal display with a character generator to a microcontroller. The methods and circuits discussed here are suitable for connecting LCDs with built-in controllers HD44780 (Hitachi), KS0070, KS0066 (Samsung), LC7985 (Sanyo), SED1278 (Epson) or other similar ones. These, or compatible with them, controllers are used in most currently produced character-synthesizing LCDs, for example, in such as ACM0802, ACM1601, ACM1602, ACM1604, ACM2002, ACM2004, ACM2402, ACM4002, ACM4004 from Displaytronic, MT-10S1, MT- 16S2D from MELT, DV-0802, DV-16100, DV-16110, DV-16120, DV-16210, DV-16230, DV-16235, DV-16236, DV-16244, DV-16252, DV-16257, DV- 16275, DV-16276, DV-20100, DV-20200, DV-20210, DV-20211, DV-20220, DV-24200, DV-40200 from Data Vision, AC082A, AC161, AC162, AC164, AC202, AD202, AC204 , AC242, AD242, AC402 from Ampire.

At all, this task comes down to organizing data exchange between the connected controller and the built-in LCD controller, because the matrix itself is controlled by the built-in controller. In the future, when we talk about connecting to the LCD, it should be understood that we're talking about about connecting to the built-in controller. The LCD controllers listed above have similar interfaces, command sets and memory allocation, although the size of the built-in ROM memory, the sequence of initialization commands, command execution time and some other parameters may differ slightly.

So, first, let's understand how the LCD works.

1) Interface .

Typically the LCD has 14 or 16 pins, the purpose of which is presented in Table 1:

TABLE 1

contact number Name description
1 Vss GND - common wire (ground)
2 Vdd Power supply - +5V power supply
3 Vo contrast
4 R.S. Register select - register selection
5 R/W Read/write - read/write
6 E Enable - turn on/off transmission
7 DB0 Data bit 0
8 DB1 Data bit 1
9 DB2 Data bit 2
10 DB3 Data bit 3
11 DB4 Data bit 4
12 DB5 Data bit 5
13 DB6 Data bit 6
14 DB7 Data bit 7
15 BL+ backlight power supply
16 BL- common backlight wire

Thus, the interface has eight information lines: DB7..DB0 and three control lines: RS, R/W, E.

The RS line determines which register of the LCD controller we want to access, that is, what information we are transmitting - data or commands.

The R/W line determines the direction of data transfer - writing to the LCD or reading from the LCD.

Line E turns on (when the line is high) or turns off (when the line is low) the transmission of information generated on the remaining interface lines.

The interface works as follows: first, the information that needs to be transmitted is generated on the interface lines DB7...DB0, RS, R/W, then for a while (>500 ns for f 0 = 270 kHz) a high level is applied to line E (at this time the LCD reads the information) , after which the signal E is transferred again to the state low level. f 0 is the frequency at which the LCD controller operates. In general, LCD controllers can operate at different frequencies (they have pins for connecting an external resonator), but usually an internal oscillator at 270 kHz is used.

After receiving each piece of information, the LCD controller requires some time to process it, so it is impossible to transmit information in a row. After each sending, you need to wait a while for the LCD controller to become free. Usually the datasheet indicates which command takes how long to execute. Also, the LCD controller provides the ability to report external device about your status (BUSY/READY). That is, when transmitting data, you can either analyze the state of the LCD controller and send the next portion of data as soon as the LCD controller is free, or simply wait a time longer than the time it takes to complete the operation on the datasheet, and then send the next portion of data.

To reduce the number of wires from the LCD to an external device, you can use not 8, but 4 information signals (DB7...DB4). All LCD controllers under consideration allow this possibility. In this case, the data is transmitted in two stages (except for the first initialization command): 1) control bits and the most significant nibble of the parcel are transmitted 2) control bits and the least significant nibble of the parcel are transmitted.

The first thing you need to do after turning on the LCD is initialization. Initialization consists of sending several commands in a certain sequence. The number of initialization commands may vary slightly among different controllers, but still the basic set of commands for eight- and four-bit interfaces, suitable for most controllers, is given below.

During initialization, it is better not to analyze the BUSY flag, but to stupidly wait for the allotted time before sending the next command, since the flag does not start to be set immediately, but after some command (see datasheet).

Initialization for eight-bit interface (f 0 =270 kHz)

1) power on

2) pause >30 ms

R.S. R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 1 1 N F X X

4) pause >39 µs

5) DISPLAY ON/OFF CONTROL

R.S. R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 0 0 1 D C B

6) pause >39 µs

7) DISPLAY CLEAR

R.S. R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 0 0 0 0 0 1

8) Pause >1.53 ms

9) ENTRY MODE SET

R.S. R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 0 0 0 1 I/D SH

Initialization for four-bit interface (f 0 =270 kHz)

1) power on

2) pause >30 ms

R.S. R/W DB7 DB6 DB5 DB4
0 0 0 0 1 0
0 0 0 0 1 0
0 0 N F X X

N=0 - single line display, N=1 - two line display

F=0 - 5x8 font, F=1 - 5x11 font

4) pause >39 µs

5) DISPLAY ON/OFF CONTROL

R.S. R/W DB7 DB6 DB5 DB4
0 0 0 0 0 0
0 0 1 D C B

D=0 - display off, D=1 - display on

C=0 - cursor disabled, C=1 - cursor enabled

B=0 - flicker off, B=1 - flicker on

6) pause >39 µs

7) DISPLAY CLEAR

R.S. R/W DB7 DB6 DB5 DB4
0 0 0 0 0 0
0 0 0 0 0 1

8) Pause >1.53 ms

9) ENTRY MODE SET

R.S. R/W DB7 DB6 DB5 DB4
0 0 0 0 0 0
0 0 0 1 I/D SH

I/D=0—decreasing the pointer during a memory operation, I/D=1—increasing the pointer during a memory operation

SH=0 - display shift disabled, SH=1 - display shift enabled

2) Memory

The LCD has 2 types of memory: DDRAM, CGRAM (CGROM).

DDRAM - display data RAM (display memory) - what is recorded in this memory is directly displayed on the display. This memory has the following address space and corresponding display (for 24x2 display):

First line

Display position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
DDRAM address 00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0Ah 0Bh 0Ch 0Dh 0Eh 0Fh 10h 11h 12h 13h 14h 15h 16h 17h

Second line

Display position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
DDRAM address 40h 41h 42h 43h 44h 45h 46h 47h 48h 49h 4Ah 4Bh 4Ch 4Dh 4Eh 4Fh 50h 51h 52h 53h 54h 55h 56h 57h

That is, what is written to DDRAM at address, for example, 42h, will be displayed in the third position on the second line of the display. For other display sizes, the available DDRAM address space will be different (usually the first 40h addresses are the first row, the second 40h addresses are the second row, etc.)

CGRAM (CGROM) - character generator RAM (ROM) - character generator memory. The character generator memory is divided into CGRAM - available for writing/reading, you can upload 8 of your own characters here and CGROM - available for read-only, pre-installed fonts. Different LCDs may have different fonts stitched into them; you need to look this up on the dock, or you can determine it yourself by organizing the display of all stitched characters sequentially on the display.

When accessing the first sixteen characters of the character generator, the CGRAM is accessed; when accessing characters with numbers higher than the sixteenth, the CGROM is accessed. Moreover, there are only 8 user characters, so the first eight characters of the character generator point to the same areas of CGRAM as the second eight characters.

Sometimes, not all characters starting from the seventeenth may be stitched into CGROM, but, for example, starting from number 21h, and when accessing characters from 10h to 21h, all sorts of garbage is displayed on the display. It depends on the firmware.

To display a character on the screen, you must perform the following steps:

1) set the cursor with the command “set DDRAM address” to the position where we would like to display the symbol (information bits indicate the DDRAM address corresponding to the selected position)

SET DDRAM ADDRESS (AC6...AC0 - address of the cursor position to be set in the display memory)

R.S. R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0

2) display the symbol on the screen with the command “write data to RAM”, while the information bits indicate the number of the symbol output from CGRAM/CGROM.

WRITE DATA TO RAM (A7..A0 - number of the character output from the character generator memory)

R.S. R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
1 0 A7 A6 A5 A4 A3 A2 A1 A0

A complete list of commands for working with the LCD and their execution time can be found by downloading the datasheet to any of the LCD controllers under consideration (they all have the same sets of commands).

Having dealt with the operation of the LCD, let’s return to the issue of connecting it to the microcontroller. Let's take the PIC16F628A controller as an example. Below are examples of connection diagrams for eight-bit and four-bit interfaces. The backlight connection is not shown in the diagrams, since the polarity of the backlight connection is sometimes determined by jumpers on the LCD board.

That's it! In order for the circuits to work, all that remains is to upload a program into the microcontroller that implements data exchange with the LCD indicator.

Example of a finished device (8-bit interface, LCD - PM1623):

Examples of programs and ready-made firmware:

Download printed circuit board (AutoCAD2000i) This board is designed to use SMD components. If you use other components, the board will have to be redesigned.

  • 28.09.2014

    This receiver operates in the range of 64-75 MHz and has a real sensitivity of 6 μV, output power of 4 W, AF range - 70...10000 Hz, THD no more than 1%. With these parameters, the receiver has dimensions of 60*70*25 mm. The receiving path is assembled on KS1066ХА1 (К174ХА42) according to the standard scheme. The antenna is a wire about a meter long, the signal is from...

  • 29.09.2014

    The circuit is made on two TVA1208 microcircuits. It is based on a transceiver circuit printed in L.1, but this path operates with an intermediate frequency of 500 kHz, which, of course, somewhat reduces its characteristics, but allows the use of a ready-made electromechanical filter configured at the factory. TVA1208 microcircuits are designed to work in the second IF3 path of televisions. In them...

  • 20.09.2014

    Classification of magnetic materials Magnetic materials are most widely used in electrical engineering; without them, electrical machines, transformers, and electrical measuring instruments are currently unthinkable. Depending on the application, magnetic materials are subject to different, sometimes contradictory, requirements. Based on their application, magnetic materials are classified into two large groups: soft magnetic and hard magnetic. Let us briefly consider their characteristics. ...

  • 10.12.2017

    The figure shows a circuit of a simple, highly sensitive acoustic switch that controls a load using a relay. The circuit uses an electret microphone; when using an ECM microphone, it is necessary to use a resistor R1 with a resistance of 2.2 kOhm to 10 kOhm. The first two transistors represent a pre-microphone amplifier, R4 C7 in the circuit eliminates the instability of the amplifier. ...

One of the radio amateur's assistant devices should be a frequency meter. With its help, it is easy to detect a generator malfunction, measure and adjust the frequency. Generators are very common in circuits. These are receivers and transmitters, clocks and frequency meters, metal detectors and various automatic lighting effects...

It is especially convenient to use a frequency meter to adjust the frequency, for example, when adjusting radio stations, receivers, or setting up a metal detector.

I purchased one of these simple sets inexpensively on the website Chinese store here: GEARBEST.com

Set contains:

  • 1 x PCB board ( PCB);
  • 1 x microcontroller PIC16F628A;
  • 9 x 1 kOhm resistor;
  • 2 x 10 kOhm resistor;
  • 1 x 100 kOhm resistor;
  • 4 x diodes;
  • 3 x transistors S9014, 7550, S9018;
  • 4 x capacitors;
  • 1 x variable capacitor;
  • 1 x button;
  • 1 x DC connector;
  • 1 x 20MHz quartz;
  • 5 x digital indicators.

Description of the frequency meter

  • Range of measured frequencies: from 1 Hz to 50 MHz;
  • Allows you to measure the frequencies of quartz resonators;
  • Accuracy resolution 5 (for example 0.0050 kHz; 4.5765 MHz; 11.059 MHz);
  • Automatic switching of frequency measurement ranges;
  • Energy saving mode (if there is no change in frequency readings, the display automatically turns off and short time turns on;
  • For power you can use the USB interface or external source power supply from 5 to 9 V;
  • Current consumption in standby mode - 11 mA

The circuit contains a small number of elements. Installation is simple - all components are soldered according to the labels on the printed circuit board.

Small radio components, connectors, etc. Packed in small snap bags. The indicators, microcircuit and its socket are inserted into foam plastic to prevent damage to the legs.

Schematic diagram of the frequency meter

Voltage at microcontroller pins

(measured with a multimeter)

Generator for testing quartz

Let's start assembling

Pour the contents of the package onto the table. Inside there is a printed circuit board, resistors, capacitors, diodes, transistors, connectors, a microcircuit with a socket and indicators.

Well, here’s a view of the entire set completely unfolded.

Now you can move on to the actual assembly of this constructor, and at the same time try to figure out how difficult it is.

I started the assembly by installing passive elements: resistors, capacitors and connectors. When installing resistors, you should learn a little about their color coding from the previous article. The fact is that the resistors are very small, and with such sizes the color marking is very difficult to read (the smaller the area of ​​​​the painted area, the more difficult it is to determine the color) and therefore I would also advise you to simply measure the resistance of the resistors using a multimeter. And we will know the result and for one thing its serviceability.

Capacitors are marked in the same way as resistors.
The first two digits are the number, the third digit is the number of zeros after the number.
The resulting result is equal to the capacitance in picofarads.
But there are capacitors on this board that do not fall under this marking; these are values ​​of 1, 3 and 22 pF.
They are marked simply by indicating the capacitance since the capacitance is less than 100 pF, i.e. less than three digits.

Resistors and ceramic capacitors can be soldered in either direction - there is no polarity here.

I bent the leads of the resistors and capacitors so that the component would not fall out, bit off the excess, and then soldered it with a soldering iron.

Let's take a little look at such a component as a tuning capacitor. This is a capacitor whose capacitance can be changed within small limits (usually 10-50pF). This element is also non-polar, but sometimes it matters how you solder it. The capacitor contains a screwdriver slot (like the head of a small screw) that has an electrical connection to one of the terminals. To reduce the influence of the screwdriver on the circuit parameters, it is necessary to solder it so that the pin connected to the slot is connected to the common bus of the board.

Connectors - the hard part in terms of soldering. It is difficult not because of the accuracy or small size of the component, but on the contrary, sometimes the soldering area is difficult to warm up and is poorly maintained. Therefore, the connector legs need to be additionally cleaned and tinned.

Now we solder in a quartz resonator, it is made for a frequency of 20 MHz, it also has no polarity, but it is better to place a dielectric washer under it or glue a piece of tape, since its body is metal and it lies on the tracks. The board was covered with a protective mask, but I’m somehow used to making some kind of backing in such cases, for safety.

The duration of soldering each leg should not exceed 2 seconds! Between soldering the legs, at least 3 seconds must pass for cooling.

Well, that's all!

Now all that remains is to wash off the remaining rosin with a brush and alcohol.

It's more beautiful now :)

All that remains is to correctly insert the microcircuit into its “crib” and connect power to the circuit.

Food must be within from 5 to 9 V - constant stabilized without ripple.(There is not a single power supply capacitor in the circuit.)

Don’t forget that the microcircuit has a key at the end - it is located at pin No. 1! You should not rely on the inscription of the name of the microcircuit - it can be written upside down.

When the power is connected and there is no signal at the input, the 0 .

First of all, I found a bunch of quartz and started checking. It should be noted that the quartz frequency, for example 32.768 kHz, cannot be measured, because measurement is limited to a range of 1 MHz.

You can measure, for example, 48 MHz, but you should keep in mind that it will be measured harmonic vibrations crystal oscillator. So 48 MHz will measure the fundamental frequency of 16 MHz.

Using a trimming capacitor, you can adjust the frequency meter readings based on the reference generator or compare them with the factory frequency meter.

The frequency meter programming mode allows you to subtract the four main programmed IF frequencies of 455 kHz; 3.9990 MHz; 4.1943 MHz; 4.4336 MHz; 10,700 Hz, as well as any natural frequency.

Programming algorithm table

To enter programming mode ( Prog) you need to press and hold the button for 1-2 seconds.

Then press the button and scroll through the menu one by one:

« Quit» — « Exit": interrupts the programming mode without saving anything.

« Add» — « Addition": saving the measured frequency and in the future this frequency will be added to the measured frequencies.

« Sub» — « Subtraction": saving the measured frequency and in the future it will be subtracted from the measured frequencies.

« Zero«- « Zero»—resets all previously programmed values.

« table» — « Table": in this table you can select the main programmed frequencies 455 kHz; 3.9990 MHz; 4.1943 MHz; 4.4336 MHz; 10,700 Hz. After selecting an entry (long press), you will return to the “Main Menu” and select the “ Add» — « add" or " Sub» — « reduce«.

« PSave» / « NoPSV": Enables/disables power saving mode. The display turns off if there is no change in frequency for a while.

If the readings are very different, then a preset may be enabled. To disable it, enter programming mode and then press the button to select “Zero” and hold until it starts flashing, then release it.

An interesting educational constructor. Even a novice radio amateur can assemble a frequency meter.

High-quality printed circuit board, durable protective coating, low number of parts thanks to a programmable microcontroller.

I was pleasantly surprised by the designer, I consider it a good basis both for gaining experience in assembling and setting up an electronic device, and in working with a device that is quite important for a radio amateur - a frequency meter.

Refinement of the frequency meter

Attention! In conclusion, I would like to note that the input signal being measured is supplied directly to the input of the microcircuit, therefore, for better sensitivity and, most importantly, protection of the microcircuit, you need to add a signal limiting amplifier at the input.

You can solder one of the ones suggested below.

Resistance R6 on the top and R9 on the bottom circuit is selected depending on the supply voltage and is installed at its left pin of 5 V. When supplying 5 V, the resistance can be omitted.

...or simple, on one transistor:

Resistance ratings are indicated for a 5V power supply. If you power the amplifier with a different voltage, then select the value of R2.3 so that half of the power is at the collector of the transistor.

Diagram of a similar frequency meter with an amplifier input stage.

Second revision.To increase the measured frequency ceiling, you can assemble a frequency divider to the frequency meter. For example, the diagrams below:



Schematic diagram of the frequency meter

The PIC16F628A microcontroller is used to do all the work without any additional chips. The 16F628A has 16 I/O pins, two of which are used for the crystal oscillator, one is for signal input and the other can only be used for input, giving us only 12 useful I/O pins. The solution is to install a transistor that opens when all other numbers are turned off.

The 7 segment LED display used here is a common cathode type BC56-12SRWA. When all the signals are on high level, transistor Q1 opens and switches on the first digit. The current for each segment is about 7 mA.

The entire frequency meter circuit consumes a current of about 30 mA on average. The microcontroller uses its internal 4 MHz oscillator to clock the CPU. And an external quartz oscillator with a frequency of 32768 Hz is needed to set 1 second time interval. Tmr0 is used to count the input signal at pin RA4.

The input signal will need 5 volts square wave. The frequency meter itself can measure up to 1 megahertz, which is more than enough for amateur projects. This is done for convenience, since the meter can reach readings of 999999 Hz - and there is no need to switch anything. We measure at least 11 hertz, at least 139.622 kilohertz.

In general, if anyone wants to repeat this project themselves, here are the . The board in the archive is slightly different from the one in the photo; some optimizations were later made. And the program code is open - it can be optimized if you know how.