Experiment #3 High Level Programming and System Memory Expansion
Experiment #3 High Level Programming and System Memory Expansion
Experiment #3 High Level Programming and System Memory Expansion
3.2.7 Write an AVR assembly program subroutine in assembly, which fills the external 6116 2K-
memory block with constant values, such as 0x55. Write another subroutine to read the full
content of the external memory 6116 and send each read value along with its memory address
to the external LEDs (similar to the ones on UNI-DS6) on one of the ports with 1 s of delay
between each value. This will be used to verify the added memory chip works correctly. Your
program should be written in a user-friendly style, e.g. the written value of 0x55 should be easily
modified through a constant declaration.
i. The assembly code and the Proteus project should be included into the .zip file you
will submit electronically. You should also bring these files with you to the lab.
ii. If you were to make a measurement on one of the microcontroller pins to validate the 1
second delay you coded into your program, which pin would be appropriate to monitor on
the oscilloscope? Explain.
3.2.8 The Fibonacci number sequence is defined by the following recurrence:
1
1
That is, each Fibonacci number is the sum of the two preceding numbers, excluding initial two
numbers, which are constant.
Write a program in C that reads an 8-bit number n using a DIP switch pack (8-bit input) on UNI-
DS6 board, computes, then stores each Fibonacci number up to number n, to the external 6116
2KB memory block, starting with the first address. Your program should be able to handle 16-bit
unsigned numbers. Other requirements are:
Your program should compute the Fibonacci sequence; lookup tables are not allowed in any
part of the solution.
The main Fibonacci computation (of calculating the next number based on the previous two)
should be done in a recursive subroutine.
The initially entered number n cannot be less than 1. Your program should check this
condition.
After all numbers are stored to the memory the computed Fibonacci numbers should be
read from the memory, and displayed on the LCD display in pairs of numbers with a space
in between. There should be about 2 seconds of delay between the display of each pair. For
example, for n=3, the numbers are displayed in the following sequence in about 8 seconds:
01
11
12
23
A warning message should appear on the LCD display if either of the two final numbers
required more than 16 bits.
You should submit a pseudocode or flowchart to illustrate the planning of your program.
3.2.9 Use the C compiler to generate and inspect the AVR assembly code corresponding to your C
program in 3.2.8. Are there any portions of the compiler generated code you could optimize for
performance and/or program memory savings? Indicate how you would modify the
assembly code, and explain any optimizations.
2
Figure 3.1. Logic schematic showing connection of tri-state outputs
Figure 3.2. Different variations of tri-state buffers: (a) Non-inverting buffer with active high enable,
(b) Non-inverting buffer with active low enable, (c) Inverting buffer with active high enable, (d) Inverting
buffer with active low enable.
Example: Suppose we want to design a 4x1 multiplexer using a 2x4 decoder and a tri-state buffer. The
logic table of the multiplexer is shown below.
E S1 S0 OUT
0 X X High-Z
1 0 0 I0
1 0 1 I1
1 1 0 I2
1 1 1 I3
Figure 3.3 shows the 4x1 multiplexer designed using decoder and tri-state buffers. Using the
below design, you can multiplex 4 input devices without tri-state outputs into a tristate bus.
3.3.2 Memories
Several equal length registers can be incorporated in a single IC and share a common set of
inputs, a common set of output, and a single clock line as shown in Figure 3.4. Each register occupies
a distinct location, which has a unique numerical address. Thus, a memory can be thought as a
collection of addressable registers. A conceptual representation of the memory in Figure 3.4 for n=3
and m=4 is shown in Table 3.1.
3
Figure 3.4. Register representation of a memory.
4
the memory. The physical organization may be different from the logical one. To make it clear let us
define the following abbreviations:
NL=Number of Logical Words
NP=Number of Physical Words
WL=Number of Bits in a Logical Word
WP=Number of Bits in a Physical Word
It is obvious that NLWL=NPWP=Number of bits in the memory.
Conceptually, the simplest organization is a word organized array with linear selection. In
such an organization NL=NP=N and WL=WP=W. The memory is designed as an NxW bit matrix as
shown in Figure 3.5(a). Word selection requires a 1-out-of N decoder. All address inputs are connected
to the select inputs of the row decoder. When an address is applied, only one of the outputs of the
decoder is active, selecting the corresponding word in the memory.
Although conceptually simple, the linear selection method requires a large decoder for large
number of words, which is very costly in chip area. For memories with small number of words, this
organization is acceptable and has advantage of a short access time.
Address decoder size is substantially reduced by organizing the memory matrix and the word
selection logic to allow two-level decoding.
In a memory utilizing two-level decoding, one level corresponds to a physical word and one to
a logical word.
A physical word consists of the number of bits in a row of the memory matrix. A logical word
consists of the number of bits of a physical word which are sensed and gated to the output at one time.
Two-level decoding requires two circuits: A row decoder which selects a physical word and a column
multiplexer which selects one logical word from the selected physical word.
A physical word is divided into S=WP/WL segments (logical words). The row decoder is a 1-out-
of NP decoder and the column multiplexer consists of WL 1-out-of S multiplexers.
The block diagram of a 2048x8 bit ROM organized for two level decoding is shown in Figure 3.5
(b). The memory array is 128x128 bits which means NP=128 and WP=128. Each physical word consists
of WP/WL=128/8=16 logical words. In the first level decoding a physical word is selected using a 7x128
decoder. Address lines A0-6 are used for that selection. In the second level, an 8-bit wide logical word
selected from a 128-bit wide physical word. This is accomplished by using eight 16x1 multiplexers, one
multiplexer for each bit in the logical word. For this selection, address bits A7 to A10 are used.
As observed, the bit organized memory results in a square memory matrix and row and column
decoders of equal complexity. Each row and column decoders decodes n/2 address bits, resulting in a
simplification of decoder required.
5
Figure 3.5. 2048x8 ROM (a) using linear selection, (b) with 128x128 memory array using two level
decoding (e.g. 6116)
6
Figure 3.6. (a) WRITE timing diagram for a R/W memory and (b) READ timing diagram for a R/W
memory.
Figure 3.7. 8 1024x1 bit read-write memories (RAM) are arranged in parallel to make 1024x8 bit (1K
byte) memory system.
Observe that the box with dashed lines may be thought as if it is a single chip 1K byte RAM.
Multiplexing outputs from two or more memory devices as shown in Figure 1.8 increases the
number of words in a memory system.
7
Figure 3.8. Multiplexing outputs from two or more memory devices to increase word count
Observe that if above chips are RAMs, and then one should implement bi-directional multiplexer
with tri-state capability, which apparently increases the complexity of the circuitry. Since the memory
chips are provided with chip select or chip enable type inputs and tri-state outputs, we can implement
the same memory system with a decoder as shown in Figure 3.9.
8
3.3.6 Address Space Organization of AtMega128
It is possible to use an optional external data SRAM with the ATmega128. This SRAM will occupy
an area in the remaining address locations in the 64K address space. This area starts at the address
following the internal SRAM. The Register file, I/O, Extended I/O and Internal SRAM occupies the
lowest 4352 bytes in normal mode so when using 64Kbyte (65536 bytes) of External Memory, 61184
bytes of External Memory are available.
Accessing external SRAM takes one additional clock cycle per byte compared to access of the
internal SRAM. This means that the commands LD, ST, LDS, STS, LDD, STD, PUSH, and POP take
one additional clock cycle. One should be aware that this will increase the number of clock cycles
required to execute the program that needs to access to SRAM.
9
Figure 3.11. AVR Memory Configuration modes.
ATmega128 has two memory configuration modes, which are shown in Figure 3.11. Memory
Configuration mode A is the non-ATmega103 compatibility mode. ATmega103 compatibility mode is
the Configuration mode B shown in the figure above.
External Memory devices have different timing requirements. To meet these requirements,
ATmega128 XMEM interface provides four different wait-states as shown below.
10
3.4 MCU I/O PORT CONNECTOR – Port A
The interconnection with AtMega128 microcontroller is accomplished via the pinhead I/O Port
Connector located on the development board. The connection between the development board and the
external prototype board is made using bit to bit wiring.
3.5.1 Setup 1:
Construct your set-up from prework Section 3.2.7 using an external breadboard for interfacing
the external memory. Check the operation of your circuit by writing and reading data, and
observing the LEDs on UNI-DS6.
i. Demonstrate the functionality of your system to the lab instructor. How do the results
compare your simulations in Proteus?
ii. Make a measurement on an appropriate signal using the oscilloscope to verify your
programmed time delay between displaying different memory word contents on LEDs. Does
your measurement match the expectation? Show and explain any discrepancies to
your lab instructor.
3.5.2 Setup 2:
Construct your designed system in 3.2.8 again using the external memory. Debug and verify
your system correctness. Then demonstrate to your lab instructor.
Note: If you cannot get any part of your systems to fully function, you are expected to take initiative to
debug, and demonstrate to your lab instructor which parts work and which parts do not. For example, if
you cannot communicate with the memory, you should find ways to demonstrate that the code works
correctly (signals at the memory interface are correct). Similarly, if you cannot write to the LCD, can you
11
demonstrate your output through another means? Any debug success in rootcausing your problems will
return to you as partial credit.
REFERENCES:
8-Bit Microcontroller AtMega128 Datasheet.
12
APPENDIX: (Please Refere to METUClass and download complete data sheet of the elements if you need more detail)
DM74LS373N (D latch)
13
M74HC373B1 (D latch)
14
HY6116 (SRAM)
15
LH5116H‐10 (SRAM)
16
17