Pulse generator on ATmega8. Function generator on a microcontroller Signal generators on microcontrollers LCD indicator

The TV signal generator probe is assembled on the basis of a microcontroller of the pic12f629 series, and in terms of its dimensions, current consumption, cost of manufacturing the device and functionality for a TV technician, it is simply irreplaceable. Supply voltage 3 volts, i.e. two AA batteries. The current consumption in generation mode is 11 milliamps, in sleep mode - only 3 microamps.

Schematic diagram of a TV signal generator

PCB drawing


This probe can generate five pictures, which is quite enough for checking and repairing the horizontal and vertical scanning of a TV, adjusting the convergence and geometric distortion of the raster, color balance, and monitoring the passage of signals through the TV circuits. When you briefly press the button, it wakes up and begins to generate the first picture; with subsequent clicks on it, the pictures switch in a circle. If you hold the button for a long time, the generator goes into sleep mode when released. It also goes into sleep mode automatically if it is turned on for more than 5 minutes.


An archive is attached to the article, which contains a diagram, a probe board, and two firmware. The video shows that the picture on my TV is slightly non-linear - this is because the TV is 12 years old, or maybe something is wrong with the video input. The proposed device is a rectangular pulse generator controlled via a serial port from a computer. It was made to solve a specific problem literally in a day and may contain errors or shortcomings, I cannot guarantee that you will earn a lot of money by selling it. But all the basic functions have been tested.
The maximum frequency produced by the generator is slightly more than 13 kHz, the minimum is less than 0.01 Hz (for a quartz oscillator frequency of 4 MHz).

Scheme.

width=710>
The drawing does not fit on the page and is therefore compressed!
To view it in full, click .

The scheme is quite simple. It is assembled on the basis of a PIC16C63A microcontroller, the signal is taken from its two pins, their state is always different. Without load, the one level differs from the supply voltage by less than 0.1 volt, the zero level is also very low. The pins are designed for currents up to 30 mA. The MAX232 chip is used to convert RS232 interface levels to TTL levels. To power the device you need a 5 volt power supply, it is not shown in the figure.

Program.

To set the parameters of the signal issued by the microcontroller, you must use a special program. The program is written for Windows OS; below is the view of its window.

The controls are designed to set the frequency of the output signal, the ratio of the lengths of the positive and negative half-cycles. It is possible to limit the number of pulses issued (1...2 23 -1). Since the program in the microcontroller does not allow outputting any frequency, after pressing the “Send” button, the nearest possible frequency value will be calculated and it will be written in the frequency field instead of the one entered from the keyboard. The fields "Duration 1" and "Duration 0" contain the duration of the signal in arbitrary units with which the program works in PIC, these are integers greater than zero and less than 2 24 . Settings are provided to select the serial port number and frequency of the quartz resonator used.

Measuring generators, in which the required frequency value is set using a keyboard, are known to readers of the magazine (see, for example, the article by Piskaev A. “Frequency meter-generator-clock” in “Radio”, 2002, No. 7, pp. 31, 32). As a rule, these devices are made on a microcontroller, the range of generated frequencies is limited to several megahertz, and obtaining an exact frequency value is impossible. The generator described in the article also contains a microcontroller, but it is used only to control a specialized microcircuit - the AD9850 frequency synthesizer. The use of this microcircuit made it possible to expand the range of generated frequencies from fractions of a hertz to 60 MHz, within which it is possible to obtain any frequency value with an accuracy of 1 Hz.

It polls the SB1-SB16 keyboard, displays information on the HG1 LCD indicator, calculates the frequency code value and transmits it via the serial interface to the DD2 synthesizer. Sound emitter HA1 serves to confirm pressing of keyboard buttons. The AD9850 (DD2) chip is used in the standard connection. Filter Z1 is turned on at the output of its DAC. After the filter, a sinusoidal signal is supplied to socket XW2 and to the input of the comparator of the DD2 chip (pin 16). From the output of the latter, a rectangular signal is supplied to socket XW1. The G1 quartz oscillator is used as a clock generator for DDS. Trimmer resistor R7 adjusts the contrast of the image on the HG1 indicator.
After resetting the microcontroller, the HG1 LCD indicator is configured for 4-bit bus exchange mode, which is necessary to reduce the number of input/output lines required for recording information.



The generator is controlled using a keyboard consisting of buttons SB1-SB16. Since all port B input lines are connected to the power supply through resistors, there is no need for external resistors to pull up ports RB4 - RB7 to the power line. Resistors R3-R6 protect the microcontroller outputs from overload when several buttons are accidentally pressed at the same time.
The required frequency is set from the keyboard. To do this, click on the buttons with the corresponding numbers, enter the desired value (in hertz) and press the “*” button. If the frequency does not exceed the maximum permissible, the message “OK” appears on the indicator for a short time and the generator goes into operating mode, and ifexceeds - message "Error". In this case, you need to press the "C" ("Reset") button and re-enter the correct value. They do the same if there is an error during the frequency input process. Pressing this button twice switches the device to operating mode with the previously set frequency value.
In operating mode, the asterisk symbol blinks in the far right area of ​​the indicator. If the current frequency value is entered from an external control unit (for example, from a computer), then to return to the frequency displayed on the indicator, just press the “*” button.
The "U" (Up - up) and "D" (Down - down) buttons allow you to stepwise change the output frequency of the generator, respectively increasing or decreasing the decimal place value by one. The required decimal place is selected by moving the cursor using the "L" (Left - left) and "R" (Right - right) buttons.
When you press the "*" button, the frequency value and cursor position are saved in the non-volatile memory of the microcontroller, so that the next time the power is turned on, the interrupted operating mode is automatically restored. Since the computing capabilities of the microcontroller are limited, the output frequency is set with an accuracy of about 1 Hz, which is sufficient for most cases. To fully realize the capabilities of the synthesizer, it can be controlled using a PC. To do this, the generator must be modified by adding a unit, the diagram of which is shown in Fig. 3. PC (or other control device) is connected to the outlet
XS1. When the logic level at the address inputs A is low, the multiplexers of the DD3 chip connect the synthesizer control inputs to the microcontroller DD1, and when the logic level is high, to an external device. Control signals are supplied through the "ENABLE" contact of the XS1 socket. Resistor R19 provides a low logic level at the address inputs of DD3 when the control device is not connected.
The generator is assembled and tested on a breadboard. If you cannot purchase a board for the SSOP housing for the DD2 chip, you can use short (10-15 mm long) pieces of tinned wire with a diameter of 0.2 mm to connect its pins to the corresponding pads. Pins 1,2,5,10,19, 24, 26, 27, 28 are connected to the common wire with one piece of longer length.
LCD indicator HG1 - 1TM1601 (16-character single-line with built-in controller). HA1 is any piezoelectric sound emitter with a built-in generator, designed for a voltage of 5 V. As a clock generator (G1), you can use a microassembly of a quartz oscillator with a frequency of up to 125 MHz; it is permissible to use a similar unit with quartz stabilization and on discrete elements.
The control program of the microcontroller depends on the frequency of the clock generator.
When programming the microcontroller, the following bit values ​​are set in the configuration word: generator type (OSC) - RC. watchdog timer (WDT) - disabled, power-on delay (PWRTE) - enabled.

Good day!

Hexadecimal representations of numbers are written in brackets.

I'm finally ready to write my next post.
Today I will try to write a pulse generator. Yes, not just by the banal switching of the state of each leg after a certain time, but “beautifully”, i.e. through interrupts. We will use the TMR0 timer overflow as an interrupt source.

We begin the debriefing

Now let's try to understand what this mysterious timer is TMR0.

And this timer simply counts the number of incoming pulses. Moreover, the source of the impulse can be either some external device or an internal generator. The selection of the pulse source is carried out by one bit of the register OPTION_REG. Namely the fifth bit, T0CS.


It also seems understandable that he is interrupted. An impulse arrived, the value in the register was incremented (increased by one). And so on until the timer overflows. The overflow is due to the controller's capacity. Our controller is already 8-bit. And in 8 bits you can store numbers in the range 0..255 inclusive (total 256). This means that an overflow will occur when the counter/timer already contains the number 255, to which the controller will try to add another one. And this is where all sorts of miracles begin. The value in the counter register will become equal to 0 (0x00), and the controller will begin processing interrupts, while raising the flag for the occurrence of this interrupt.

Looks like we've sorted it out. Now how do we make a pulse generator out of it? Yes, easier than steamed turnips. The point is that you can write a number to the TMR0 register. And it will be incremented not from scratch, but from this number. Thus, we just need to select (or calculate) what number we need to place in the TMR0 register in order to make the required pulse duration.

Here I tried to draw some semblance of a block diagram, but I downloaded a very complex program, and I didn’t have much time to deal with it. Although it turned out, as for me, quite understandable. Let's look:

Where arrows between blocks are not shown, it means they go one after another.
The code turned out to be quite small, let's take a look. Commented as much as possible:

LIST P=16F84A ; set the MK type
#include p16F84A.inc ; connect the header
__CONFIG _CP_OFF ​​& _PWRTE_ON & _WDT_OFF & _HS_OSC ; MK configuration
;----
; General purpose registers
;---
; But we won’t have them, it seems, we’ll make do with a battery
;---
;Program
;---

ORG 0x00 ; indicate the address of the main program
GOTO Main
;---
; Interrupts and subroutines
;---

ORG 0x04 ; define the interrupt vector
NOP ; calibration NOP
COMF PORTA ; inversion of all port A pins
NOP ; again calibration NOP
MOVLW.152 ; We put the delay 255-152=103 in W
MOVWF TMR0 ; In TMR0 we put the delay value
BCF INTCON,2 ; reset the interrupt flag
RETFIE ; we return back to main. program

;---
;Main loop
;---
Main BSF STATUS,5 ; Let's go to the first bank
MOVLW.0 ; Place in battery 0
MOVWF TRISA ; We mark the entire port A as output
BCF OPTION_REG,5 ; Internal clock signal for TMR0
BCF STATUS,5 ; Let's go to zero bank
BSF INTCON,GIE ; Enable interrupts
BSF INTCON,5 ; Enable TMR0 overflow interrupts
CLRF PORTA ; Logical zero on all port A
MOVLW.152 ; Send the number to the accumulator
MOVWF TMR0 ; 256-1-148=107 mts left before overflow
Loop ; Waiting for interruption
GOTO Loop
END


That’s actually all 🙂 and this is how it works.

This project is a high-quality and universal function generator, which, despite some complexity of the circuit, at least in comparison with simpler ones, has very wide functionality, which justifies the cost of its assembly. It is capable of producing 9 different waveforms and also works with pulse synchronization.

Schematic diagram of the generator on the MK

Device settings

  • Frequency range: 10 Hz - 60 kHz
  • Digital frequency adjustment in 3 different steps
  • Waveforms: Sine, Triangle, Square, Saw, H-pulse, L-pulse, Burst, Sweep, Noise
  • Output range: 15V for sine and triangle, 0-5V for other modes
  • There is an output for pulse synchronization

The device is powered from 12 volts AC, which provides a sufficiently high (over 18 V) DC voltage necessary for normal operation of the 78L15 and 79L15, which form a bipolar 15 V circuit. This is done so that the LF353 microcircuit can output the full range of signals to the load 1 kOhm.

Level controller used ALPS SRBM1L0800. The circuit should use resistors with ±1% tolerance or better. LED current limiters - 4306R series resistors. Brightness can be increased depending on the preference of the performer. The generator is assembled in a plastic case 178x154x36 mm with aluminum front and rear panels.

Many contact components are mounted on the front and rear panels (buttons, knobs, RCA connectors, LED assemblies, power connector). Printed circuit boards are attached to the housing with bolts with plastic spacers. All other elements of the generator are mounted on printed circuit boards - the power supply is separate. The left button in the middle is to change the mode, the right one is to select the mode frequency.

The generator produces various signals and operates in three modes, which are selected using the "Select" key and indicated by the three upper (in the diagram) LEDs. The rotary control changes the signal parameters according to the following table:

Immediately after setting in mode 1, sine generation occurs. However, the starting frequency is quite low and at least one click of the encoder is needed to increase it. The board has a contact for connecting the device for programming, which allows you to quickly change the functionality of the signal generator, if necessary. All project files - PIC16F870 firmware, board drawings, are located