• Direct memory access controller: circuit, logic, states and operating mode. Dynamic memory controller Questions and tasks

    Functions of the dynamic memory controller:

      Conversion of MP commands into a sequence of special signals that provide writing/reading to the dynamic memory module.

      Providing a regeneration mode for the dynamic memory module.

      Ensuring stratification of calls to dynamic memory.

    The controller manages four DRAM modules. The memory access cycle time is reduced. Total capacity of 4 modules = 1 MB * 32 bit words = 4 MB. 22 address bits are used:

    A0 A1 - used for internal use of the MP. They determine the byte used and are not issued externally.

    BE3. . . BE0 - byte enable

    A3 A2 - provide delamination

    A21 A4 - to the addressable inputs of the module

    Since the memory is built on four memory modules, the controller must generate four pairs of strobe signals.

    M0 M1 ... M3




    9 address bits must be generated by the controller and issued in parts

    The WE write signal must be generated - write enable

    DEN - data enable

    The memory module is connected directly to the processor bus.

    MP status signals:

    - signal activating the controller chip

    CLK - this signal causes all changes in the microcircuit

    Let's consider the interaction of the MP, controller and dynamic memory unit

      1. DRAM controller

      Cache memory

    Currently, a two-level cache is being organized: internal (CACHE1), external (CACH2). The cache is built on static memory - SRAM. There is a memory cache controller.

      1. Characteristics of external cache memory

      Capacity up to 512 KB

      High performance (provided by using SRAM)

      Information is stored in blocks. Block - a set of adjacent bytes (4...64 bytes). The length of a block is usually significantly longer than the length of a word.

    Types of cache:

      associative cache - associative cache

      direct mapped cache - direct mapped cache

      two way associative cache - two-channel associative cache

      1. Cache controller functions

      Physical address analysis. If fixed CACHE - read hit, the required information enters the processor from the cache. If it happened CACHE - read miss, then the information is extracted from the OP. In case of cache - entry hit, the current result is entered into the cache. In case of cache - write miss, the response of the cache controller may vary depending on the type of cache type used:

      end-to-end recording - recording is carried out in the OP.

      write-back - writing is carried out in the cache. The modified information enters the OP when unloaded from the cache.

      Snooping"eavesdropping"address buses. The cache tracks changes in memory contents initiated by the MP. All calls to the OP, with a two-level organization, go through the cache. The first access goes to the cache. If a change in the contents of the OP is initiated by another master, the cache does not know about these changes. There is a mismatch between the information stored in the OP and in the cache. To avoid this, “eavesdropping” on the address bus is used. If the controller detects that an address is being accessed, a copy of the contents of which is stored in the cache, the corresponding cache cell is declared invalid.

      Cache directory support. Support for the implementation of the principles of displaying OP information in the cache.

    Nowadays in the civilized world you will hardly find a person who has never used a computer and has no idea what it is. Therefore, instead of once again talking about all the known parts of this complex system, we will tell you about something that you do not yet know. We will discuss and give a short description of memory controllers, without which the operation of a computer would be impossible. If you want to delve into the operating system of your personal computer or laptop, then you should definitely know this. So, let's discuss today what memory controllers are.

    The task facing computer memory controllers is very important for the operation of the computer. A memory controller is a chip that is located on the motherboard or central processing unit. The main function that this tiny chip performs is to control data flows, both incoming and outgoing. The secondary function of the memory controller is to increase the potential and performance of the system, as well as the uniform and correct placement of information in memory, which is available thanks to new developments in the field of new technologies.

    The placement of the memory controller in the computer depends on certain models of motherboards and central processors. In some computers, designers place this chip on the motherboard's parallel north connection, while in other computers they are placed on the die CPU. Those systems that are designed to install a controller on the motherboard have a large number of new different physical sockets. The RAM used in computers of this type also has a new, modern design.

    The main purpose of using a memory controller in a computer is to allow the system to read and write changes to the RAM and update it every time it boots. This occurs due to the fact that the memory controller sends electrical charges, which in turn are signals to perform certain actions. Without going into technical terminology, we can state the fact that memory controllers are one of the most important parts in a computer that allows the use of RAM, and without which its operation would not be possible.

    Memory controllers come in different types. They differ in:
    - memory controllers with double data transfer rate (DDR);
    - fully buffered memory controllers (FB);
    - two-channel controllers (DC).

    The functions that different types of memory controllers can perform differ from each other. For example, dual-rate memory controllers are used to transfer data based on the speed of the memory clock increasing or decreasing. While dual channel memory uses two memory controllers in parallel with each other. This allows the computer to speed up the system by creating more channels, but despite the hassles that come with a bunch of wires, the system works quite efficiently. However, difficulties arise when creating new channels, so this type of memory controller is not flawless.

    Fully buffered memory controllers, on the other hand, differ from other types of memory controllers. This technology uses serial data transmission channels that are needed for communication with the motherboard and RAM memory circuits that are unlike other systems. The advantage of this type of controller is that fully buffered memory controllers reduce the number of wires that are used in the motherboard, which reduces the time spent on completing a task.

    As you have already seen, memory controllers are very necessary for the stable operation of a computer, and different types are used for different purposes. Prices for memory lines range from very high to very low, depending on the type and functions that a particular memory controller performs.

    Typically, an industrial controller consists of: a central processor, network interfaces, memory modules and various input/output devices.

    The PLC processor module includes the following components: a microprocessor or CPU (central processing unit), a real-time clock, storage devices and a watchdog.

    The main characteristics of the microprocessor include: clock frequency, bit depth, support for ports for various input/output devices, architecture, performance parameters at certain temperature ranges, floating point operations, power consumption level.

    The performance indicators of microprocessors with the same architecture are proportional to the clock frequency. Most controllers use microprocessors implemented on the RISC (Reduced Instruction Set Computing) architecture, which have a reduced number of instructions. In this case, the microprocessor uses a certain number of instructions of the same length and many registers. Thanks to a reduced set of instructions, it is possible to create compilers with high efficiency indicators, as well as a processor pipeline that can produce the result of executing the actions of one of the instructions in one clock cycle.

    Industrial controllers that deal with intensive mathematical data processing require a math coprocessor (an auxiliary processor that performs floating point operations) or the use of signal processors that perform mathematical operations within a single clock cycle. Thanks to signal processors, significant acceleration of convolution or fast Fourier transform operations is achieved.

    Memory capacity is characterized by the number of variables that can be processed during the operation of the PLC. Microprocessor memory access time is one of the most significant indicators that can limit performance. Because of this, memory is divided into hierarchy levels, taking into account the frequency and speed of use of the data available in it. Memory hierarchy is another significant indicator of the processor architecture, which allows us to reduce the level of possible negative impact of slow memory on the speed of the microprocessor.

    Main types of industrial controller (PLC) memory:

    • ROM – read-only memory;
    • RAM – random access memory;
    • Set of registers.

    A set of registers are the fastest memory elements, as they are used by the ALU (arithmetic logic unit) to execute the simplest processor commands. ROM is used as a storage place for information that is rarely changed - the operating system, bootloader, device drivers, or the executable module of a program. RAM directly stores data that is subject to repeated changes during the operation of the controller. For example, information about diagnostics, variables displayed on the display, tag values, intermediate calculations, data displayed on graphs. The role of ROM (ROM - Read Only Memory), as a rule, is reprogrammable electrically erasable memory (EEPROM - Electrically Erasable Programmable ROM). By the way, flash memory is essentially a type of EEPROM. Its operating principle is to store a certain charge in a capacitor, which is formed by the substrate of the MOS transistor and the floating gate. The main feature of flash memory is its absolute energy independence, i.e. ability to save data in the absence of power. Data in flash memory is updated not in individual cells, but through the use of large blocks. All ROMs have a big drawback - low performance.

    The number of cycles of entering information into flash memory is limited to only a few tens of thousands of times. Modern microprocessors use static memory (SRAM - Static Random Access Memory), dynamic memory (DRAM - Dynamic Random Access Memory), and synchronous dynamic memory (SDRAM - Synchronous DRAM) as RAM. SRAM execution occurs on flip-flops, which are capable of storing information indefinitely, provided power is available. The dynamic memory of an industrial controller stores its data on capacitors, which requires periodic recharging of the capacitors. The main disadvantage of trigger memory is the high level of cost and price-to-capacity ratio. This is due to the fact that a relatively small number of flip-flops fit on one chip. The advantages include a high level of performance, measured in gigahertz, while capacitor memory cannot overcome the bar of several hundred hertz. All types of RAM differ in that if there is no power, all the information in them is not stored. That is why some types of PLCs use battery power, which allows the system to remain operational even if the system power is briefly interrupted.

    Modular and monoblock industrial controllers use a parallel bus to exchange information with I/O modules, making polling speed significantly higher than a serial bus. Types of parallel buses: VME, PCI, ISA, CXM, ComactPCI, PC/104. A serial bus, for example RS-485, is needed to connect remote I/O modules.

    Processor core of microcontrollers:
    – arithmetic-logical device
    – memory organization

    Good afternoon, dear radio amateurs!
    Welcome to the website ““

    Today (more precisely, over the course of several articles) we will take a closer look at basis any microcontrollerprocessor core.

    Main elements:

    1. Arithmetic-logical unit

    ALU– the heart (and maybe the mind, with honor and conscience) of the microcontroller.
    Here we will not play the role of a “dismemberment maniac” and tinker with the insides of this device. Let us only understand that thanks to the ALU, all the work of the microcontroller occurs. If you ever have a desire to learn more deeply how the “heart” of a microcontroller works (and it will be nice if it appears), then in the books of wonderful authors Belov, Ryumik, Evstifeev, Revich, Baranov and many others, you will always find a detailed answer .

    2. Microcontroller memory (memory organization)

    Before looking at microcontroller memory, let's talk a little about memory in general.
    Human memory - everything is clear with it - it can be “solid” (when you are in solid memory, and sometimes also in your right mind) and, sadly, “holey”. And all information is stored in so-called “neurons” - small memory cells.
    Almost everything is the same for microcontrollers. Only if a person has the smallest cell for storing information is called a “neuron”, then the smallest memory cell for a microcontroller for storing information is called “ bit“.
    One bit can store either one logical one or one logical zero.
    Bitthe minimum unit of measurement for memory capacity in microprocessor technology.
    The next basic, or most common, unit of measurement for memory is byte.
    Bytethat's eight bits of information. One byte can only store eight zeros and ones.
    The maximum number that can be written to a byte is 255. If you operate with large numbers in the program, you should know (to know how many bytes are needed to store the number) that the maximum number that can be written to:
    – one byte = 255
    – two bytes = 65,535
    – three bytes = 16,777,215
    – four bytes – a number greater than 4 billion (if you are not in at least one hundred of Forbes magazine, then you will not need four bytes of memory to store numbers).
    Writing to and reading from memory occurs in bytes (one bit of information cannot be written or read).
    The next unit of measurement is kilobyte.
    A kilobyte contains 1024 bytes of information. (exactly 1024, not 1000 bytes).
    There are also large values ​​for measuring memory capacity (megabytes, gigabytes), but they are not yet used in microcontrollers.
    I hope that everything is clear with the units of measurement of electronic memory:

    Memory organization in a microcontroller

    AVR chips have three types of memory:
    program memory, also known as FLASH memory
    data memory, also known as RAM (random access memory), aka SRAM
    non-volatile memory, also known as EEPROM, also known as EEPROM
    In the microcontroller it is allocated three address spaces in which the above types of memory are located. In this case, the data memory (in the sense of an allocated address space) turned out to be a little deprived - it has to share its address space with memory cells in which general-purpose registers and I/O registers are stored (you will learn about them in detail in the next article). These registers do not physically belong to data memory, but are located in the same address space. If the starting addresses of program memory and non-volatile memory begin at address zero, then the starting address of data memory does not start at address zero - the general purpose registers and I/O registers take up space at address zero, and only the addresses of program memory cells follow them.
    Some types of ATiny MKs do not have data memory.

    Program memory (FLASH memory)

    Program memory is designed to store our programs in it, as well as any data we need that does not change during program execution (constants). When the microcontroller is turned off, all data in the program memory is saved.
    Program memory, of course, all microcontrollers have. The size of program memory, depending on the type of MK, varies from 1 kilobyte to 256 kilobytes.
    Program memory access Only the programmer has access to the program memory when programming the MK; the MK itself also has access to program memory, but only to read data from memory; it cannot write anything there (you never know, it might suddenly want to ruin our program). True, the Mega family of microcontrollers has the ability (with the programmer’s permission) to make changes in program memory, but that’s a different story.
    For program memory, there are two more types of memory size measurement - “ word" And " page“.
    The point is that program memory consists of cells consisting of two bytes. Such a cell is called a “word”. And this was done this way because almost all MK commands consist of two bytes, and, accordingly, to write them you need two bytes in program memory. Each MK command is one “word”. There are several commands that require 4 bytes in memory to write - two words, but such commands are found in microcontrollers that have a program memory of more than 8 kilobytes.
    Thus, programs can be written into one cell of memory:
    – any command consisting of two bytes
    – half of the command, consisting of 4 bytes
    – two constants, each of which fits into one byte, or one sixteen-bit constant. However, if you write three one-byte constants into memory, they will still occupy four bytes (two words) in memory.
    Besides, writing to program memory is carried out not only in “words”, but also in “pages” . Page size ranges from 64 to 256 bytes (the larger the program memory, the larger the “page” size). What does it mean. If you created a small program, the size of which is 11 words (22 bytes), it will still take up one page of space in the program memory, i.e. at least 64 bytes. The “extra” 42 bytes will be filled with either zeros or ones. These are the pies.
    But that's not all.
    Program memory can have three states(if I may say so):
    1. All memory is at the disposal of the programmer
    In this case, we can completely fill the entire memory with our program and data. And the program will start from memory address zero.
    2. Part of the memory is taken by the MK
    If MKs are used during operation (and I hope you remember what they are), part of the MK’s memory is taken for the needs of interrupt processing and stored in it “ interrupt vectors“.
    What is it?
    When we allow the MK to process interrupts, it, starting from memory address zero, takes part of the cells to store in them the addresses that the MK needs to go to to execute the interrupt subroutine. For each interrupt, the MK allocates two bytes of memory (one word) in which the addresses of interrupt handling routines are stored. These addresses, which indicate where the subroutine for processing a particular interrupt is located in memory, are called “ interrupt vectors“. And the entire memory area in which “interrupt vectors” are stored is called interrupt vector table. The number of occupied memory cells for interrupts depends directly on the number of possible interrupts of a given microcontroller (from several to several dozen). All interrupts are located at the beginning of the program memory, from address zero, and have a clear sequence. The reset interrupt vector is always located at address zero. When we turn on the device, or reset it with a button, the reset interrupt is triggered. The MK reads from the zero address (from the cell) the address that indicates where the beginning of our program is located in memory, and by going to this address it begins to execute the program. The program itself in this case will be located in program memory immediately behind the interrupt table.
    3. The MK takes another part of the program memory (more precisely, it does not take it, but allocates an area at the end of the memory in which the programmer places a special program - the “loader”).
    This is possible in MKs of the “MEGA” family, which have the ability to allow the MK to make changes to program memory. What does it mean.
    Some MKs have the ability self-program. In the practice of amateurs, this possibility of MK is used extremely rarely. The ability to reprogram (self-program) is needed mainly in cases of industrial production of a device on a microcontroller, for which a software update can then be released. We will not consider this possibility, at least for now. We just need to know that in microcontrollers that support self-programming, the program memory is divided into two parts :
    - top – application section, where our program and interrupt vectors are located
    - lower – bootloader section (Boot Loader Section- in English), where the programmer places his loader program. The size of the bootloader section depends on the total size of the MK program memory, and can range from 128 bytes to 4096 bytes. If we do not use the ability to self-program the MK, then this section is given to our program and data.
    Well, program memory is called FLASH memory because it is made using the so-called Flash technology (like the familiar computer “flash drives” to all of us).
    The program memory allows 10 thousand reprogramming cycles.

    Data memory (Static RAM, SRAM)

    Random Access Memory, it's the same data memory type SRAM, is designed to store various data obtained as a result of the program.
    When the microcontroller is turned off, all data stored in it is lost.
    Data memory found in almost all microcontrollers (absent in the simplest MKs of the Tiny family).
    In all MKs of the Mega family (and part of the MKs of the Tiny family), the amount of built-in data memory ranges from 128 bytes to 8 kilobytes, and almost all of it is at our complete disposal. He only takes a little MK for himself to organize a stack (we’ll find out what this is later). Some MKs provide for the connection of external memory (it can be of any type - FLASH, SRAM, EEPROM) with a capacity of up to 64 kilobytes. If external memory is connected to such MKs, it becomes, as it were, a continuation of the data memory.
    Writing to and reading from data memory occurs byte by byte, and unlike program memory, it is not divided into pages and words.

    Non-volatile memory (EEPROM)

    Non-volatile memory also refers to data memory, but unlike the latter it has several features. It is designed to store data and constants that must be preserved in the absence of power.
    All microcontrollers have EEPROM.
    When the microcontroller's power is turned off, all data stored in non-volatile memory is saved (that's why it is called non-volatile).
    Non-volatile memory capacity, depending on the type of MK, ranges from 64 bytes to 4 kilobytes.
    Writing and reading information into memory is done byte by byte. However, in older models of the MEGA family, non-volatile memory, like program memory, has a page record. The page size is small, only 4 bytes. In practice, this feature does not matter - both writing and reading are carried out byte-by-byte anyway.
    Number of write and erase cycles memory reaches 100,000.
    The main feature of EEPROM is that when writing data to it, it becomes very “slow” - writing one byte can last from 2 to 4 milliseconds (this is a very low speed), and it can happen, for example, that during writing some - interruption, in which case the data recording process will be ruined.
    In addition, it is not recommended to write data to non-volatile memory from address zero (I don’t remember the source of this information, but I definitely remember that I read it somewhere) - data may be damaged during operation of the MK. Sometimes programmers step back a few bytes from the beginning of the memory, and only start writing data in the next cells.

    Sometimes when developing a device there is a need to save some data into non-volatile memory. In such cases, the internal EEPROM of the microcontroller is usually used. If it is not enough, then, as a rule, external EEPROM chips from the 24lxx series are used. Microcircuits in this series are very popular. Most often they can be found in old mobile phones, some motherboards, printer cartridges and many other places. The price of these microcircuits is also very attractive. For example, 24LC16 costs 11 rubles.
    This chip is available in various packages, the most popular of which are DIP and SOIC. The microcircuit has the following pinout:

    As you can see, there are very few conclusions. So let's try to figure out what's what.
    A0, A1, A2- are not used in this microcircuit. They can be connected to ground or to the power supply plus. In some other microcircuits of the 24lxx series, these pins can set the address of the microcircuit, so that you can connect as many as 8 memory microcircuits to one i2c bus at once.
    Vss- Earth.
    S.D.A.- data line
    SCL— clock line
    W.P.- Write protection. When this pin is logic 0, then writing to memory is allowed. If you apply a logical one, then only reading from memory is possible.
    Vcc- power supply for the microcircuit. According to the datasheet, it is powered by voltage from 2.5 volts to 5.5 volts.

    Connection to the controller.
    Connecting memory to the MK is very simple. From the wiring you only need a pair of resistors with a resistance of about 4.7 kOhm.

    Software

    To work with memory, a library was developed that implements the following functions:

    i2c_init— adjusts the speed of clock pulses traveling along the line SCL.

    The 24LC16 chip supports frequencies up to 400 kHz. You can calculate the frequency like this:

    CPU Clock frequency— frequency at which the microcontroller operates

    TWBR— a number written in the register of the same name.

    TWPS- predivider. Prescaler values ​​are specified by bits TWPS1 and TWPS0 in the TWSR register

    For the Atmega 32 controller, the following table is valid:

    i2c_start— sends the starting package

    i2c_stop— sends a stop message

    i2c_send- sends a byte

    i2c_receive— receives a byte

    i2c_recive_last— accepts the last byte. The difference from the previous function is that when a byte is received, the microcontroller does not send an acknowledgment bit. If, when receiving the last byte, use i2c_receive then the SDA line will remain pressed to the ground.

    Writing data to a memory chip

    You can record data either in random order or page by page. Since there can be several devices on the i2c bus at once, in order to access any device you need to know its seven-bit address. The address of the 24LC16 chip in binary looks like this:

    Bits A,B,C are used to select a memory block. There are 8 memory blocks in the chip, 256 bytes each. Accordingly, the ABC bits take values ​​from 000 to 111.

    In order to write a byte to the chip, you need to perform the following sequence of actions:

    1. Initialize i2c interface
    2. Send the starting package
    3. Send chip address + memory block address
    4. Send the address of the memory cell to which the recording will be made
    5. Send data byte
    6. Send a stop package

    Example: Need to write a byte 0xFA at the address 0x101.

    rcall i2c_init
    rcall i2c_start
    ldi temp,0b 1010 001 0 //Chip address where:
    // 1010 - chip address
    // 001 - memory block address (Cell 0x101 belongs to block 1)
    // 0
    rcall i2c_send
    ldi temp,1 //Address of the memory cell. (block 1, cell 1)
    rcall i2c_send
    ldi temp,0xFA //Load the byte that needs to be written into the register
    rcall i2c_send //Write a byte
    rcall i2c_stop

    You can write data to memory not only byte by byte but also page by page. Page size is 16 bytes. The post-process recording implies the following: We send the address of the zero byte of the desired page and after that we send the necessary data 16 times. The address counter will increase by one automatically. If you send data for the 17th time, the zero byte will be overwritten, if you send the byte 18th time, it will overwrite byte number 1, etc.

    Example: The first page of block 0 needs to be written.

    rcall i2c_init //Initialize the i2c interface
    rcall i2c_start // Send the starting package
    ldi temp,0b 1010 000 0 //Chip address where:
    // 1010 - chip address
    // 000 - address of the memory block (we are interested in block zero)
    // 0 - read/write bit. 0 - write, 1 - read
    rcall i2c_send
    ldi temp,16 //Address of the first page
    rcall i2c_send
    ldi temp,0x01 //Load byte number 0 into the register
    rcall i2c_send //Write a byte
    ldi temp,0x02 //Load byte number 1 into the register
    rcall i2c_send //Write a byte
    /// here we write the remaining bytes.....
    ldi temp,0x0E //Load byte number 14 into the register
    rcall i2c_send //Write a byte
    ldi temp,0x0F //Load byte number 15 into the register
    rcall i2c_send //Write a byte
    rcall i2c_stop //Send a stop package

    Reading data from the chip
    We seem to have sorted out the recording, now let's start reading. To read a byte you need to do the following:

    1. Initialize the i2c interface (if it has not been initialized previously)
    2. Send starter package
    3. Send the address of the microcircuit and the address of the memory block from where we will read
    4. Send memory address
    5. Resend the starting package
    6. Send chip address and memory block address with “read” bit
    7. Get byte
    8. Send stop parcel

    rcall i2c_init //Initialize the i2c interface
    rcall i2c_start // Send the starting package
    ldi temp 0b1010 011 0 //Chip address + address of the 3rd memory block.
    //Read/write bit is still 0!
    rcall i2c_send
    ldi temp,0x41 //Memory cell address
    rcall i2c_send
    rcall i2c_start //Re-sending the starting package
    ldi temp 0b1010 011 1 //Chip address+memory block address+read/write bit becomes 1
    rcall i2c_send //now you can read the data
    rcall i2c_recive_last //Read the byte. The first and the last.
    rcall i2c_stop //Send a stop package

    Reading can be done sequentially byte by byte, i.e. just calli2c_receive as much as needed. There is no need to send a command to increase the address by one. There is also no need to switch block addresses when reading sequentially. Those. you can take and read the entire microcircuit at once without any problems.

    The library for working with i2c was developed and tested on the Atmega32 microcontroller. I think it will work on many other controllers without any modifications. Naturally, the controller must have hardware support for i2c or as it is also called TWI. Of course, i2c can be implemented in software, but I didn’t bother and there was no need. The demo example is a program that writes bytes from 0 to 15 to the first 16 addresses, and after writing, outputs them to port A. You can see how this works not only live, but also in Proteus.

    And finally, I’m attaching an oscillogram:

    This is what the i2c bus looks like through my eyes :-)
    I welcome all questions and suggestions in the comments.