Fast avr schematic. Schematic of a set-top box for restoring FUSE-bits in AVR microcontrollers

The design was based on the development and application manuals of the Mikroelektronika debug boards. The EasyAVR boards produced by this company (and not only ones) attract beginners to master microcontroller technology with the quality of workmanship and a variety of components installed on them. In fact, half of them become unnecessary after testing five or six training programs in action. Judge for yourself, there are many LEDs and buttons on the board, connected to each line of each port. But the experimenter needs them only until he learns to control signal levels and blink indicators, and this happens very quickly. There are only four LEDs and a switch on my board, enough for a start ...

I named the developed board FastAVR. With dimensions of 98x127 mm and single-sided printed wiring, it is quite suitable for making at home. Microcircuits are used only in DIP cases installed in the panel, which makes it easy to replace them during experiments. The microcontroller can be clocked both from a quartz resonator and from a clock generator with a frequency divider installed on the board.A connector is provided for connecting a standard STK-200 programmer with selective power supply to it and with the ability to connect a JTAG adapter If necessary, you can program a microcontroller designed for operation in another device.

The board contains the most necessary peripherals for prototyping the debugged designs: a two-digit seven-element LED indicator, a character LCD, RS-232, SPI, PS / 2 interfaces (for connecting a standard computer keyboard or mouse), an EEPROM chip, and a beeper. It is possible to connect most of these devices to any pins of any ports of the microcontroller in arbitrary combinations. All ports are also available for connecting devices located outside the board. Devices on the board, including a crystal oscillator and LED indicators, can also be connected to devices outside of it. All these connections do not require soldering and are performed by setting jumpers between the pin contacts on the board or between them and external devices.

Initially, a debug board was conceived with a cheap ATmega8 microcontroller, which has almost all the capabilities inherent in its family (AVR) .However, I decided not to save money and use a microcontroller of the same family in a DIP package with the maximum possible number of pins (40) - ATmega16 or ATmega32. They have the same pin layout, and any one can be installed on the described board. A large number of pins allows you to connect more different peripheral devices that may be required when debugging a program. Since microcontrollers of the AVR family are software compatible, a program debugged on a more powerful one is not difficult, as a rule, to be transferred to a less powerful one. Considering, of course, their differences.

Many different programs can be debugged on the same copy of the microcontroller installed on the debug board. The software (FLASH) memory of modern microcontrollers allows so many reprogramming cycles that when making numerous changes to the program in the course of its debugging, you can not think about the possible exhaustion of the resource Even when the first signs of this appear (some memory cells are not programmed the first time), the microcontroller that has worked your own on a debug board, do not throw away. It can be programmed for the last time and sent "for permanent work" in one of the previously debugged structures.

The diagram of the main node of the FastAVR board is shown in Fig. 1. All connection of the periphery to the ports of the DD2 microcontroller is made through double-row 16-pin pin headers XP1-XP4. The even pins of each of them are connected to the pins of the microcontroller ports, and the odd ones to those on the board peripherals... When assembling a breadboard for debugging, it is convenient to connect adjacent pins with ordinary jumpers, and those located at a distance, in another block or even on another board, with jumpers made of pieces of flexible insulated wire, equipped at both ends with sockets from connectors (Fig. 2). Heat-shrinkable tubes are put on the nests.


In the process of debugging, it is convenient to connect control and measuring devices to the same pins: an oscilloscope, a frequency meter, a test signal generator. Placing the pins in a row in ascending order of the port bit number makes it easier to find the right one and significantly reduces the risk of confusion. This solution, in my opinion, is much more convenient than the use in most industrial debug boards for external connections of ten-pin, double-row IDC-10 connectors. Their only advantage is the presence of a key that ensures correct docking with the mating connector. And when you connect a single wire or probe of a measuring device, you have to count the contacts every time, remembering the order in which they correspond to the outputs of the microcontroller.

If the jumpers S2-S4 are removed, and S5 and S6 are installed, a quartz resonator ZQ1 is connected to the internal clock generator of the microcontroller, the frequency of which can be chosen any required for the problem being solved. There is also a 16 MHz G1 integrated crystal oscillator on the board. The triggers of the DD1 chip divide its frequency by two and four. By removing the jumpers S5, S6 and setting one of the jumpers S2-S4, you can send pulses with a frequency of 4, 8 or 16 MHz to the clock input of the microcontroller (pin 13). This will ensure that the microcontroller operates in any configuration in which the internal RC clock is turned off.

Clocking from an external generator can also be useful for restoring the operability of the microcontroller, the configuration of which is programmed by mistake. You can read about this in.

Although the microcontroller contains its own non-volatile data memory, it often turns out to be insufficient for the task at hand. The problem can be solved by connecting an external memory chip of the required size to the microcontroller. On the FastAVR board, this is done according to the diagram shown in Fig. 3 Chip DS1 series 24C or 24LC - re-programmable non-volatile memory with I2C interface. The inputs of AO-A2 are connected in such a way that the least significant bit of its slave address on the interface bus is 1, and the two following it are zero.

In fig. 4 shows a diagram of the control and indication nodes available on the FastAVR board. The SA1 quadruple DIP switch is connected to the microcontroller port pins using jumpers. Resistors R4-R7 will protect these pins if they are accidentally programmed as outputs against overload when the breakers are closed. DR1 assembly resistors maintain a high logic level at the microcontroller inputs when the SA1.1-SA1.4 switches are open. The fifth "extra" resistor in the assembly can also be used to supply this level to any circuit.
Four signal LEDs HL1-HL4 light up at high logic levels at the outputs to which they are connected, and do not light up at low logic levels. Resistors R8-R11 limit the current.

Commutators of common electrodes of a two-digit seven-element LED indicator HG1, assembled on transistors VT1-VT4. can control indicators both with common anodes (for example, DA56-11) and with common cathodes of elements (for example, DC56-11). You just need to ensure the required polarity of the programmed control pulses applied to the resistors R12-R21. Such indicators are easy to find in out-of-date cash registers and computer system units. By removing the jumper S7, you can turn off the H element (decimal point) of the least significant digit of the HG1 indicator.

The XP5 connector is used to connect common character LCDs with built-in controllers to the FastAVR board. This is actually a double-row 34-pin IDC-34MS connector, but only 14 of the 17 pins in one row are used. Their numbers shown in the diagram do not correspond to the standard ones for this connector, but coincide with the pin numbers of the most common LCDs. The presence of such a connector allows you to use a standard computer 34-wire flat cable for communication with the indicator, designed to connect a floppy disk drive with motherboard... A 14-pin pin header is inserted into the holes of the LCD interface contact pads and soldered to them. One connector is put on it flat cable, and the second is inserted into the XP5 connector. LIH 1 contacts are connected to the outputs of the microcontroller ports in accordance with the LCD switching circuit in the device being debugged. The board with the connected indicator is shown in Fig. five.

The described method of connecting the LCD is relatively complicated, but it is convenient because the indicators different types that have the same pinout can be quickly changed without risking confusing the order of connecting their pins with the ports of the microcontroller. Trimmer resistor R23 serves as a contrast control.

Sound signaling device HA1 is an electromagnetic emitter with a resistance of 80 Ohm, found on the computer motherboard. The VD1 diode suppresses self-induction voltage surges arising on the indicator winding when it is supplied with a pulse voltage. You should not reduce the resistance of the resistor R22 in order to increase the volume of the sound. This will overload the microcontroller output.

A little advice. Do not forget at the end of the program generation procedure sound signal issue a command setting low level at the PD7 output of the microcontroller. If the level is left high here, the current through the HA1 emitter will continue to flow in the pauses between signals, which will lead to an overall increase in the power consumption of the microcontroller.

Scheme external interfaces the debug board is shown in Fig. 6. You can connect to the XS1 connector computer keyboard or "mouse", and connect the XS2 connector to the COM port of the computer. The DA1 microcircuit, included according to a typical scheme, matches the levels of the RS-232 and microcontroller signals. Jumpers S8-S10 are thin sections of printed conductors limited by contact pads, which can be cut if it becomes necessary to use not only information, but also control signals of the RS-232 interface in the device being debugged.
Chokes L1-L5 suppress high frequency noise. These are small ferrite tubes put on the wires. These are easy to find on computer boards.

To load the program codes into the microcontroller installed on the FastAVR board, the XP6 connector is connected to the programmer. When working with it, it is recommended to remove the S1 jumper (see Fig. 1), thereby disabling the microcontroller's initial setup circuit on the board. If the programmer has its own power supply, the S11 jumper must be removed. When installed, the programmer is powered by the development board.

I used a programmer similar to the STK-200. Its diagram and drawing of the printed circuit board can be found in Fig. 8 and 9 c. This programmer has only one KR1564AP5 (74HC244AN) microcircuit, connect it to the LPT port of the computer. There is no need to install a quartz resonator in the programmer, it is available on the debug board. When working with this programmer and the PonyProg program on a computer with a Core2Duo + processor, 1965 chipset and an operating Windows system XP SP3 had no problems.

The diagram of the power supply unit of the debug board is shown in Fig. 7. To pin 3 of XP7 connector from external source it is possible to supply a stabilized voltage of +5 V. Jumpers S12, S13 must be removed. If there is a 9 ... 16 V constant voltage source, its positive terminal is connected to pin 2 of the same connector and jumpers S12, S13 are installed. In this case, an external stabilized voltage of +5 V is not required, it is obtained using an integral stabilizer DA2.

When the HG1 LED is not used and no external devices that draw high current are connected to the board, the DA2 body temperature is low. If, despite the presence of a heat sink, the stabilizer gets very hot, it is recommended to switch to power supply from an external sufficiently powerful voltage source 5 V. The presence of a supply voltage is signaled by the HL5 LED.

Diodes VD2 and VD3 protect against reverse polarity of the power supply connection. Chokes (ferrite tubes) L6 and L7 suppress high frequency noise. The contacts ХТ12-Х17 (+5 V) and ХТ18-ХТ22 (common) installed in different places of the board allow supplying various external devices with a voltage of 5 V. In addition, it is convenient to connect the common wire of measuring devices to the contacts ХТ18-ХТ22.

A drawing of the printed circuit board is shown in Fig. 8. It is one-sided made of foil-clad fiberglass with a thickness of 1.5 mm. Please note that the two insulated wire jumpers shown in dashed lines are installed on the side of the printed conductors. The rest are made of wire without insulation and are placed on the side of the parts. For the DA1, DD1, DD2, DS1 microcircuits and the HG1 LED indicator, panels are installed on the board, which allows you to quickly replace these elements if necessary. In the absence of ferrite tubes, jumpers can be installed instead of chokes L1-L7.

Next to the XS1 connector, there is a seat for another of the same connector, designated XSV. Although its pins are not connected anywhere, this allows you to easily install the dual socket MDN-6F removed from the computer motherboard here. XS2 connector - DB-9F female.

Pin blocks ХР1 -ХР4, pins ХТ1 -ХТ22 and designed for installation of jumpers S1 - S7, S11-S13 are made of double-row connectors of the PLD series or single-row connectors of the PLS series. To get the required number of contacts, segments of the corresponding length are separated from them, or segments with missing contacts are added.

Please note that there are free contact pads next to the contact pads for the XT4-XT11 pins. This allows a double-row pin block to be installed here, which is not subject to "loosening" during frequent re-connections. The XP5 connector (IDC-34MS) was mentioned earlier. XP6 connector (for the programmer) - ten-pin of the same series (IDC-10MS). The XP7's 3-pin power connector is removed from the motherboard where it was used to connect the fan. This eliminated the problem of finding the mating part of the connector needed to connect to the power supply board.

In the lower (according to the drawing) part of the board there is a rectangular field filled with contact pads - a reserve for placing all kinds of additional elements that may be required during the debugging process. On the board I made, here was installed, for example, a variable resistor with a nominal value of 22 kOhm. A voltage of +5 V was applied to it, and the adjustable voltage removed from the engine was used to check the ADC of the microcontroller.

The RS-232 interface is very convenient to use for debugging, supplementing the program being debugged with a module that sends the necessary information through the USART of the microcontroller. Having launched the terminal program on the computer, with the COM port of which the XS2 connector of the debug board is connected, you can observe the received messages on the screen.


I used the Terminal v1.9b program which can be found on the internet using any search engine... The window of this program with examples of messages received from the device being debugged and transmitted to it is shown in Fig. 9. For normal display of Russian text, by clicking on the "Set font" button, select in the window that opens the font - Arial, style - normal size - 8, character set - Cyrillic.

Sprint Layout 5.0 PCB file and examples of programs that demonstrate the operation of the nodes on the board:

LITERATURE
1 Baranov V. Restoring the configuration of AVR microcontrollers. - Radio. 2009, no. 11, p. 26-29.

S. BORISOV, Uzlovaya, Tula region.
"Radio" No. 8-9 2010

Quite often, it becomes necessary to use the control of any device (be it an incandescent light bulb, engine, heating element or a simple LED) by means of PWM.

Probably to explain what it is and what is the beauty of PWM control is not necessary, there is already a lot of information on the Internet, and I’m unlikely to be able to chew on this topic better. Therefore, let's get down to business right away, namely, we will launch PWM on Attiny2313 using Bascom-AVR tools.

Shim in microcontrollers AVR works on timers-counters, in Tiny2313 there are only 2 such timers: an 8-bit Timer0 counting up to 255 and a 16-bit Timer1 capable of counting up to 65535. Each timer controls two PWM channels, so in total 4 channels can be implemented in hardware PWM.

Information about the number of PWM channels and the bit width of each channel can be found on the datasheet pages on the microcontroller.

So, on board the Attiny2313 there are two 8-bit PWM channels powered by Timer0 and two more channels controlled by the Timer1 timer have a programmable bit width from 8 to 10 bits. In the datasheet, these legs are signed as follows:

To configure Timer1 to generate PWM in Bascom, just write the following line:

Config Timer1 = Pwm, Pwm = 8, Compare A Pwm = Clear Up, Compare B Pwm = Clear Down, Prescale = 64

Pwm = 8 PWM bit width is selected, for Timer1, as it was written above, it can also be Pwm = 9 or Pwm = 10.

Compare A / B Pwm = Clear Up / Clear Down here we configure the active state for each PWM channel (A and B).

Prescale = 64 - the already familiar timer configuration line, which is responsible for the pre-division of the timer overflow frequency, in this case the divider will set the PWM frequency. We can change at our discretion Prescale = 1 | 8 | 64 | 256 | 1024


The duty cycle of the generated signal is determined by the value that we write to the comparison registers OCR1A and OCR1B (we have two PWM channels on one timer, here one register per channel A and B). The value of the counting register is constantly compared with the values ​​that lie in these registers (it is copied there from the timer), when they match, the leg μ switches to the active state, and the counting register continues to count to its maximum value... Having counted to the maximum, the timer starts counting in reverse direction, and reaching the moment when the values ​​of the counting register and the comparison register coincide again, a reverse switching will occur on the microcontroller's foot (see the figure below)



For us, the comparison registers OCR1A and OCR1B are just variables in which we can put some value. For example, like this:


OCR1A = 100
OCR1B = 150


For convenience, the Bascom also provides another name for these registers: PWM1A and PWM1B, so the previous lines will be equivalent to the following:


PWM1A = 100
PWM1B = 150

Now let's see how the Clear Up / Clear Down active state configuration affects what happens at the PWM output, depending on the value of the compare register.

When the output is configured as Compare A Pwm = Clear Down, the active state of the output is high and as the value of the OCR (PWM) register increases, the proportional voltage on that leg will increase. Quite the opposite, everything will happen if the output is configured as Compare A Pwm = Clear Up. All this is well illustrated in the picture below.



The values ​​that these comparison registers can take depend on what bit width of the PWM channel we have chosen. With PWM = 8 (8-bit PWM), a value from 0 to 255 is possible; at PWM = 9 from 0 to 511; with PWM = 10 from 0 to 1023. Here I think everything is clear.


Now a small example: connect the LEDs to the microcontroller as shown in the diagram (power supply is not indicated in the diagram)


And let's write a small program:


$ crystal = 4000000

Config Timer1 = Pwm, Pwm = 9, Compare A Pwm = Clear Down, Compare B Pwm = Clear Up, Prescale = 8
Config PORTB.3 = Output
Config PORTB.4 = Output

Incr Pwm1a "smoothly increase the value of the comparison register OCR1A
Incr Pwm1b "smoothly increase the value of the comparison register OCR1B

Waitms 20 "add a delay

Loop

End

After compiling and flashing the program into the controller, one of the LEDs (D1) will smoothly gain brightness, and the other (D2) will smoothly go out


If we now poke an oscilloscope at the PWM outputs, then we can see such a picture with a changing duty cycle (blue signal on OC1A, red on OC1B):


Timer0 configuration for PWM generation is practically the same, except that timer0 is an 8-bit timer, and therefore the PWM generated by this timer will always have a bit width of 8. Therefore, when configuring this timer, the PWM bit width is not indicated:

Config Timer0 = Pwm, Compare A Pwm = Clear Up, Compare B Pwm = Clear Down, Prescale = 64



Now a similar example with LEDs, but now we will generate a pwm using Timer0:


$ regfile = "attiny2313.dat"
$ crystal = 4000000

Config Timer0 = Pwm, Compare A Pwm = Clear Down, Compare B Pwm = Clear Up, Prescale = 8
Config PORTB.2 = Output
Config PORTD.5 ​​= Output

Incr Pwm0a " smoothly increase the value of the register OCR0A
Incr Pwm0b ​​" smoothly increase the value of the register OCR0B

Waitms 20 "add a delay

Loop

End

Connect the LEDs to the Timer0 PWM output, as shown in the diagram:

Everything is the same here: the first LED (D1) will gradually gain brightness, and the second (D2) will smoothly go out.


Counting the PWM Generation Frequency

If you want to know the PWM generation frequency, then this is not difficult to do. Look at the formula below:

PWM frequency = (quartz frequency / prescaler) / (count register size * 2)

For example, let's count several values:

1. Quartz frequency = 4000000 Hz, prescaler = 64, PWM width 10 bits => count register size = 1024

PWM frequency = (4000000/64) / (1024 * 2) = 122 Hz

2. Quartz frequency = 8000000 Hz, prescaler = 8, PWM width 9 bits => count register size = 512

PWM frequency = (8000000/8) / (512 * 2) = 976.56 Hz

3. The frequency of the quartz is 16000000 Hz, the prescaler = 1, the width of the PWM is 8 bits => the size of the counting register = 256

PWM frequency = (16000000/1) / (256 * 2) = 31250 Hz

The universal development board FastAVR for beginners in programming MK ATMEL was developed on the basis of an analysis of about a dozen of similar designs. The board is a reasonable compromise between the redundant functionality of most of them or the overly primitive features of others. Having some experience in working with different microprocessor systems, below I will comment on my thoughts - how this or that board node was conceived. It is up to you to agree with them or not, but maybe they will be partially useful for those mastering AVR in the future ...

The design is based on the developments and application notes of Microelectronics (http://www.mikroe.com/ru/). But EasyAVR boards (and not only ones) contain too many components that attract newcomers to microprocessor technology by their diversity and quality of workmanship; in fact, half of them become unnecessary after successfully compiling 5-6 examples of programs and gaining experience. Judge for yourself - why do you need a bunch of LEDs and buttons connected to each port on the board? All this is relevant until you learn how to control the pins of the port and blink the indicators, and this will happen very quickly ;-) In this case, the board has 4 LEDs and a switch, for a start it is enough ...

So, the capabilities of the debug board:

  • basic set of peripherals to support ATmega: RS-232 converter, beeper, SPI EEPROM, LCD and LED indicators, built-in clock generator + quartz, PS-2 keyboard, ADC tester, logic testers;
  • possibility of repetition at home, single-sided printed circuit board optimized for laser-ironing technology, small size;
  • the use of all components only in DIP packages - allows you to easily replace them during experiments or program the processor itself for other circuits (for example, for JTAG);
  • full functional sufficiency for creating simple prototypes of devices and their debugging;
  • connector of the standard SPI programmer STK-200 with selective power supply to the programmer, the ability external connection JTAG;
  • the ability to turn on the board in JTAG ICE mode by simple re-switching;
  • the possibility of independent switching of on-board peripherals in any combination due to the linear technology of the location of all ports of the MC;
  • the ability to easily connect any external peripherals and use 100% of the ATmega resources in the DIP-40, all ports are bit by bit accessible, moreover, all the internal peripherals of the board can be used for external devices (for example, a clock generator or LED indicators;

All this does not require board modifications or soldering. So at the initial stage of mastering MK, the capabilities of FastAVR are quite enough. Those who decide to move on, after creating their own software, will be able to independently decide what they need specifically and make a prototype of a design with their own set of peripherals. I repeat once again - the board was created to start studying the AVR MK, no more goals were pursued. The emergence of the documentation itself is associated with the interest shown by many beginners to master given type controllers or are still thinking about where to start. Naturally, you need to start with the test board ;-)

MK AVR-self-sufficient controllers, but the processor is not the whole system. "Cubes" serving it or controlled by it, in themselves, can be considered as separate blocks of future structures. By combining them on the main board all together, you can combine them to get the desired results. At first, the board was conceived based on the ATmega8, since it's cheap and has almost all the features of an AVR. However, having heeded the advice, I decided not to save money and put the microcontroller at the maximum available in a DIP package - ATmega16 or 32. The pinout of both MCUs is identical. The cost of such a solution is repaid a hundredfold by the number of I / O ports to which you can connect at least for the duration of debugging. Bottom-up compatibility for all AVR generations allows you to write and debug programs using a more powerful chip, and then compile for the target chip. A sufficient flash resource allows you not to "get hung up" on the limitations in the Mega's reprogramming capabilities, especially since you can, with enough exercise, send the MK to a working structure by flashing it for the last time (JTAG ICE is the first contender)

To manufacture the board, you will need a little non-scarce computer "junk", which is enough in the closets of any electronics engineer. Most of the components are used from old or failed motherboards IBM PC or computer technology, recently this kind of iron is increasingly becoming unusable and thrown away or lying around without use. Because With SMD small things, practically nothing can be done (sort the problem, and the time ...), I solder such devices entirely either with a construction hairdryer or on an electric stove.

The basic description of FastAVR is blockwise below:

Food. The built-in 78 (M) 05 regulator allows the board to be powered from widespread 9-12V adapters taken from other equipment, which are usually idle. In a normal connection, this is enough (Mega-16/32 + LCD + RS232 + TXO), when using an on-board 7-segment LED, or a highly voracious external periphery (complex programmer), the stabilizer is already very hot. Connecting an external stabilized voltage + 5V is possible through pin-3 X1 (a connector from the motherboard coolers is used). You must first disable the JP1-JP2 jumpers of the VCC_SEL group. X1 of this type was chosen for several reasons, the main one is that you almost always have to make an adapter to power the board from different adapters that are available or a laboratory power supply unit. Pass-through ferrite chokes (balun) FB1, FB2 filter impulse noise and high-frequency interference. The diodes VD1, VD2 are protected against "reverse polarity". Jumpers VCC_EXT and GND_EXT are installed in several places on the board. Through them, it is quite easy to remove the supply voltage and common "ground" when connecting the peripherals.

External memory is implemented on a standard I2C EEPROM 24cXXX. Although the AVR itself contains its own non-volatile memory, in many designs an external chip may be preferable due to size or resource. The switching circuit is standard, the crystal address is 0x01.

Linear LED indicators of the status of the HL2-HL5 ports are made on 4 discrete LEDs. To start experimenting with AVR, this is enough, I consider more of them not justified and rather a decoration. The LEDs turn on when writing to the log port "1", thus. port status is displayed without signal inversion, which is convenient and clear.

Connection to the LCD indicator board is made through 2 connectors, it is possible to use both 8-bit and 4-bit modes. The first of them - 34-pin X2 (from 3.5 "drives) allows you to use standard repressed cables from drives of the required length, respectively, on the indicator itself it is better to unsolder the pin jumper strip (pin block), this allows you to quickly change different indicators without fear The connection to the ports of the ABRA is carried out through the pin-block X10, thus, in addition to the LCD connection mode itself, you can flexibly select the MK leads.This design allows you to easily adapt to the free ports of the controller, even "dial" them one by one from different groups ports, which is necessary when it matches a specific prototype being debugged, or a newly designed printed circuit board turns out to be more convenient in wiring.


In many cases, the use of an LCD indicator may not be justified in terms of price, size, or reliability. For example, in the simplest charger or a timer, a 2-digit LED indicator may well work. The dual 7-segment displays of the common type that I have in my possession with a sign height of 14 mm turned out to be both with a common anode and with a common cathode (decommissioned cash registers and system blocks 486 computers). I had to use 2-stroke keys on VT1-VT4 to connect indicators of any type and, accordingly, a socket for the indicator itself, so as not to rack my brains with circuitry in the future.

All peripheral connections to the ATmega ports, as noted earlier, are made via line pin blocks X3-X6. Basically, on debugged boards, I observed the use of IDC-10 (2x5) connectors. Their only advantage in this case is the presence of a "key", so as not to confuse the loop in places when connecting. This is where the advantages of this method end and the disadvantages begin - it is even visually inconvenient to work with 8-bit ports, tk. the pins are not arranged in a row, it is impossible to connect the built-in peripherals except for a loop. The use of pin-blocks gives exactly the opposite result, in addition, through a standard jumper-jumper it is easy to control any signals from above, for example logic probe or an oscilloscope, you do not need to poke around and count on the port legs for fear of accidentally "shorting" the conclusions. Add to this the maximum cheapness and reusability of this connection, because it is much easier to replace a cable or jumper than a connector soldered to the board. Moreover, now on sale, even in our outback, you can find such mating connectors (or use from old system units), which makes it easy and quick to combine connectors (Fig):


For sound, a common beeper with a resistance of about 80 ohms from the motherboard is used. The signal is not very loud, but sufficient for monitoring (R23 is already selected at the limit). I did not install a separate key, those who wish can unsolder it in the places for prototyping, designated as TEMP. A little advice - when working with sound, do not forget to put a command at the end of the signal generation procedure, which resets the PD7 output to the log "0", otherwise, after the generation stops, there may be "1" left and the current through the speaker will continue to go, which is not good though would be for reasons of general consumption AVR.

The 4-bit DIP-switch SW4 is used to assemble the master of logical signals for ports. Here, the situation with the number is similar to LEDs. Because the avr inputs have internal connected pool-up resistances, so there is no need to set "pullups" to the power supply. On resistors R18-R21, protection against errors of accidental switching of the MK ports to the output is assembled. In board revision 1.03 and higher, the dip-switch can be replaced with jumpers if absent. Recently I needed to quickly make a JTAG ICE from the board. In this connection, in rev 1.4 introduced the resistor matrix RN1, which allows the hardware to form a ligical "1" on several controller inputs. If you do not need this, you can skip installing RN1.

The MC clock is selected by the CL_SEL pin group and can be carried out from an external crystal resonator Z1 (only JP37, JP38 are installed), an integral crystal oscillator G1 (16 MHz), or from a divider by: 2 and: 4. So in addition to quartz, the processor can be clocked at frequencies of 16, 8, 4 MHz. You can easily estimate the speed of the program being debugged, or get a standard clock frequency with a soldered special. quartz. In principle, in the absence of TXO on this frequency any other generator up to 16MHz can be used. The generator can also be useful to you when "raising" the MK due to incorrectly stitched fuses of the microcontroller, in this case the clock frequency does not matter.

A serial RS-232 to UART level converter is a constant feature of most AVR-based systems. There is no need to "reinvent the wheel" here, the standard MAX232 is enough. Only the RX-TX signals are involved, which is sufficient for most applications. It is practically possible to connect CTS-RTS for hardware flow control without reworking the board, using flexible wires on the JP31-JP32 from the track side. The circuit tested m / c Maxim MAX232, TI MAX232 and SIPEX SP3232 - put any analogs compatible in pinout.

An external matrix keyboard can be made on a separate board and connected with loops to the MK (I decided to use a mouse from the manipulators, as a rule, 2 mikriks are always working there). The debug board itself has a dual PS-2 connector block. A standard IBM PC keyboard can be connected without any hardware modifications, naturally with the appropriate software support from the AVR. The second connector is free, use at your discretion. As a rule, the keyboard is a very specific thing, depending on the prototype being debugged, so after some thought I decided not to put even the simplest buttons on the board. I'll post my board options after wiring and testing them.

The HL7 indicator is set for experiments with the built-in hardware PWM controller.

The connector for in-circuit serial programming X7 is made in accordance with STK-200. Power to the programmer can be selectively selected via JP43. In my case, the simplest programmer from PonyProg is used on the 74ALS (LS, F) 244 buffer with an LPT connection. Everything was tested on a Core2Duo + i965chipset running XP SP2, no problems arose. The programmer is powered through the connector from the debug board and is easy to use, because buffers in normal mode "go" to the Z-state and absolutely do not interfere with FastAVR operation. Connecting a JTAG adapter for in-circuit programming and real-time debugging is also possible without modifying the board through the corresponding linear pin block of port C.

It remains to mention a few more necessary elements:

The external Reset circuit, which is quite simple for the AVR. It can be turned off via JP42, although operation in conjunction with the programmer does not interfere at all. The reset input can be reprogrammed via the fuse as a standard I / O port and used for peripherals, but remember that in this case it is no longer possible to reprogram the crystal via X7.

The variable resistor R27, turned on by a potentiometer, is a voltage setting for experiments with a built-in ADC, the output from it can be fed to any of the analog inputs of the MK. A small note - pay attention, if you do not install this resistor for any reason, be sure to put a jumper (in the figure with a dotted line) for the normal passage of the common GND bus!

A little about herself printed circuit board and designs. As already noted, the board is one-sided. So far, I have checked 2 copies made using laser-ironing technology (one when printing on photographic paper from inkjet, the other based on self-adhesive), thus. if you wish, everything should work out ;-) If you think about using a photographic method, great! The jumper bars are separated taking into account the "forbidden zones" and the use of standard 16-pin loops (straps from GAME-PORT), even when connected with one extreme row. In the absence of ferrite chokes (I use from old 286 motherboards or burned monitors), you can safely put jumpers. I recommend that you put panels under all the chips so that you do not have to chip the board later. Do not forget 2 jumpers from the keys to the HL6 indicator.

And this is how the interface for checking TTL / CMOS logic looks like, as far as possible, I will try to tell you what came of it.

In general, the timer has a comparison register OCR ** and when the value in the timer matches the value of the compare register OCR ** 2 things can happen:

  • Interrupt
  • Changing the state of an external comparison pin OC **

We can now customize PWM when the counter counts to the value OCR ** voltage on the leg we have chosen OC **change from 5 to 0. When the timer counts to the end and starts counting, first we change the voltage from 0 to 5, at the output we will have rectangular pulses

There are 3 operating modesPWM

STS(reset on match) - This can be called CHIM a pulse-frequency simulated signal when the timer counts to a value OCR ** it resets and changes the value OC **to the opposite. Thus, the duty cycle PWM always the same.

This is used when you need to count the exact periods, or generate interrupts after a certain time.

Fast PWM(fast PWM) - the counter counts from 0 to 255, after which it is reset to 0.

When the timer value is the same as OCR ** the corresponding output is reset to 0, when set to zero, 1 is set.

Most often used as normal PWM.

Phase Correct PWM(PWM with precise phase) - in this mode, the counter counts from 0 to 255, and then counts back to zero. On the first match with OCR ** the output is reset to 0, on 2 matches (when the counter goes back), 1 is set.

They are used so that the phase does not go astray when the duty cycle changes.



If we want to work with the output OC1A put the bits in COM1A1 COM1A0
Generally "/" means OR. TCNT1= OCR1A for PWM on withdrawal OC1A

Timer / Counter Mode of Operation- timer / counter operating mode.

Top- TCNT1 value at which the output value is switched OC **.

TOV1 Flag Set on- at what values ​​the GIFR register bit is set

We select the mode that we need from the last table, do not look at Top. From the 2 tables, select any of the last 2 options. It remains only to arrange the necessary bits in the registers.

#define F_CPU 8000000UL #include #include int main () (DDRD = 0xFF; OCR1A = 0xC0; // Compare with this value OCR1B = 0x40; // PWM and timer settings TCCR1A | = (1<CS10 set 1, he counts with the frequency of the MK about how to set the timer frequency


Let's move on to exploring the built-in timers.
Exploring interrupts and especially timers in microcontrollers is a certain complexity due to their versatility. Today we will try to understand the terms and names.

IN microcontrollers AVR there can be from one to 4 timers, eight-bit or sixteen-bit.
Simplistically, timers are designated by the letter T, and a number from zero to three. Usually even T0 and T2 are eight-bit, and odd T1 and T3 are sixteen-bit. When programming, the simplified version is used only in comments, and the full name of the timer is written in the programs - the TCNT register. Timer symbols are shown below:

Timers

T0, T2- (TCNT0, TCNT2) 8-bit counters (even)
TCNTn- counting register of an 8-bit counter
Where; counter n-number

T1, T3- (TCNT1H and TCNT1L, TCNT3H and TCNT3L) sixteen-bit counters (odd)
TCNTny- counting register of a 16-bit counter
Where; counter n-number
y-high (H) or low (L) digit

T1 consists of two eight-bit registers TCNT1H and TCNT1L, but
T3 of two registers TCNT3H and TCNT3L... By letter H the most significant digit is indicated, and L Jr.

As timers are registers, they can be accessed at any time, read, written, zeroed, and changed.
Certain rules for writing and reading into timers TCNT1H and TCNT1L have been adopted.

1. Programs for writing and reading timer data must be atomic, ie. before reading or writing, we disable interrupts, and at the end of the process we re-enable.
2. When writing, the most significant byte H is written first and then the least significant byte L.
3. When reading, first the low byte L is read, then the high byte H.
For example:
Writing data to the counting register.
CLI; Disable interrupts OUT TCNT1H, R16; Write high byte OUT TCNT1L, R17; SEI low byte write; Allow interrupts

Reading data from the counting register
CLI; Disable interrupts IN TCNT1L, R16; Reading the low byte IN TCNT1H, R17; Reading the high byte SEI; Allow interrupts

Why are these rules? And all in order not to distort the data during the time that will be spent on the process of reading from each register.
If you use direct reading of 8-bit registers TCNT1H and TCNT1L, then you cannot be sure that these registers were read simultaneously. The following situation may occur: The counter contained the value $ 01FF, you read TCNT1H (containing the value 01 in some variable). During this time, a counting impulse came, and the contents of TCNT1L became equal to $ 00, and the value of $ 02 was written to TCNT1H.

Now you read the value of TCNT1L into another variable, you get the value $ 00 in this variable (after all, the timer / counter has already counted). The 16-bit value of these variables turned out to be $ 0100, but at the time of reading the high byte, the content of the counter was $ 01FF, and the low byte should have been read as FF. To prevent this situation, a temporary register is contained in the timer / counter block. This register is transparent, i.e. acts automatically. When reading the value of the TCNT1L register into a variable, the contents of TCNT1H go to this register. Then, when reading the high byte into a variable, the value of the temporary register is read. The temporary register is absolutely transparent for the user, but for its correct operation it is necessary to follow the above sequence of actions. Accessing registers through an additional (buffer) register is called double buffering.

Timers are associated with counting pulses, which can be external and go to a special input of the microcircuit or formed by its own generator. In turn, the frequency of its own oscillator can be synchronized by an external quartz resonator, or it can be determined by an internal RC - circuit. After that, the external frequency or the frequency of the own oscillator passes the prescaler controlled by the register CLKPR The frequency of the generator after the prescaler (prescaler) CLKPR is often called the clock signal (clock frequency) of the processor (CPU).
Frequency supplied to the timer input denoted as CLKTn This frequency corresponds to the clock signal of the processor.
One counting pulse increments the timer value by one, so the TCNT registers are counting, and called timer / counter (TC).
For the timer / counter to function properly with an external clock, the minimum time between two external clock switches must be at least one CPU clock cycle. The external clock is synchronized with the rising edge of the internal clock of the CPU. (This must be remembered when building frequency meters).
Control register for timer / counter TCNT is the register TCCR.
Interrupt mask for timer / counter TCNT serves as a register TIMSK(timer interrupt control register).
The TIMSK interrupt mask flags register is the TIFR register... Remember that these 3 registers (TCCR, TIMSK, TIFR) are almost always used when running the TCNT timer / counter.

Interrupts can be triggered by overflow of the TCNT register, comparing the value of the TCNT register with the value of special comparison registers OCR, capture - by the values ​​of special capture registers ICR and are determined by the timer / counter mode. In addition, an interrupt request can occur upon triggering Watchdog Timer WDT.

Timers / counters can operate in different modes and, accordingly, perform different functions.
The mode of operation, that is, the behavior of the timer / counter and the match signal output, is defined as the mode of operation of the register-driven signal generator WGM02; WGM01; WGM00(shorthand WGM02: 0) and the mode of outputting the coincidence signal controlled by registers COM0x1; COM0x0(shorthand COM0x1: 0). The state of the bits on which the match signal output mode depends does not affect the counting sequence, which is determined only by the state of the signal generator configuration bits.

Bits COM0x1: 0 determine whether the PWM output should be inverted or not (inverted or non-inverted PWM).
(PWM) Pulse-width modulation (PWM).
For non-PWM modes, the contents of COM0x1: 0 bits determine whether the output signal should be set to one, reset to zero, or switched to the opposite state at the moment of a match

--
Thanks for attention!
Igor Kotov, editor-in-chief of the magazine "Datagor"

You can make a step equal to one, then the changes will look like this:
plus: rcall delay; Go to delay subroutine inc temp2; Go one step and check if the result is equal to zero breq plus_1; If equal, then go to the plus_1 label rjmp Correct; Return to poll of buttons plus_1: dec temp2; subtract one rjmp Correct; Return to polling buttons minus: rcall delay; Jump to delay routine dec temp2; Go one step and check if the result is equal to zero breq minus_1; If equal, then go to the label minus_1 rjmp Correct; Return to polling buttons minus_1: inc temp2; add one rjmp Correct; Back to button poll

Due to the irrelevance of the AVRStudio 5, and the ATtiny2313 microcontroller, the series of articles will be rewritten for AtmelStudio6, and the ATmega8 and ATmega16 microcontrollers. I apologize in advance for the inconvenience.