Você está na página 1de 27

EE251: Introduction to Microprocessors

Tuesday, May 16
Flip-Flops and Sequential Circuits
Components of a Microcontroller
Register Model

Read: Chapter 3 (3.3 is C and not required)


Labs: Started this week! Lab 1 due next week.
Note, Lab 2 starts tomorrow and will be due next week.
Prework is due at beginning of your Lab 2, so get started
on it!
Homework: #1 Due next week. Check web page.
Lecture #2 1
Just for Fun Again

Lecture #2 2
Important Resources for ECE251
Embedded Systems: Introduction to ARM Cortex-M
Microcontrollers, Jonathan Valvano, On reserve in Morgan
Embedded Systems: Real Time Interfacing to ARM Cortex-M
Microcontrollers, Jonathan Valvano. On reserve in Morgan
The Definitive Guide to Arm Cortex-M3 and Cortex-M4 Processors,
Joseph Yiu. Access to be determined.
Tiva TM4C123GH6PM Microcontroller Data Sheet (1409 pages)
Various other Reference Manuals, User Guides, and web page
references that can sometimes be helpful: found on ECE251 main
website.
Check the ECE251 website regularly to find more helpful
resources for the course.

Lecture #2 3
Flip-Flops
A key memory device in microprocessors is the flip-flop.
Remember: Flip-flops are clocked. Latches are not. Computers
use clocked circuits => flip-flops.

For example, a J-K flip-flop is shown as:

Q Q

J K

Clk

When do the outputs of the flip-flop above change? __________________


How can you tell?

In microprocessors, flip-flops are typically grouped together with common


control signals into registers.
Lecture #2 4
Memory
Another common subsystem in microprocessors is MEMORY, with
multiple address lines and multiple data lines:

a0
a1
.
.
. Read/Write
aN-1 Clk

d0 d1 . . . dM-1

The above has N address lines and M data lines. The capacity of this
memory system is _________ bits.
Why the power of 2 for addresses, but not data?

Lecture #2 5
Sequential Circuits
Sequential circuits are logic circuits with memory (state), including
registers and/or memory cells

In Output Output
Logic

Sn Next State Sn+1


Logic

Memory

Clk

What kind of sequential circuit have I drawn? ______________________

Hint: What are the two types, and what is the difference between them?

Lecture #2 6
Sequential Circuits continued
Another type of sequential circuit:

In
Next State
Sn
Logic Sn+1

Memory
Clk

Output
Output
Logic

What kind of sequential circuit is this? ______________________


Hint: Outputs do not depend on inputs.
This is (almost) universally the kind of sequential circuits used in real
computer systems. Why?
Lecture #2 7
State Transition Diagrams

Input Next State


State
Output Output

Moore

Input
Output
State Next State

Mealy

Lecture #2 8
New Content: Computer Block Diagrams

Von-Neumann Harvard e.g. ARM


Instructions and data are Instructions and data are
stored in the same memory. stored in separate memories.

Lecture #2 9
Features of the ARM Cortex M4 Microcontroller
(Specifically the TM4C123GH6PM that well be using)

- 32-bit CPU (32 bit wide registers and address path)


- 80 MHz max internal clock
- 4 GBytes memory space (232 = 22230 = 4230 = 4G where G = 230 = 1,073,741,824)
- 32 kBytes of on-chip RAM
- 2 kBytes of flash EEPROM memory
- 256 kBytes of Flash memory
- SysTick Real-Time Clock
- Sophisticated timer functions that include: input capture, pulse output,
- Serial communication interfaces: SCI, SPI, CAN,
- 2 12-bit A/D converters with max sample rate of 1 million samples per second
- and lots, lots more

- Dont panic! This is just an overview. We have a whole semester to


understand its key functionality (and some of it we wont even get to).

Lecture #2 10
TM4C123GH6MP Block Diagram

So, where
is the CPU?

Lecture #2 11
TM4C123GH6MP Block Diagram

CPU

Lecture #2 12
Embedded System

- A product that uses one or more microcontrollers as


controller(s). Also called an embedded product.

- End users are interested in the functionality of the


product, not the microcontroller itself.

- Cell phones, home security systems, and modern


automobiles are examples of embedded products.
Others you know of?

Lecture #2 13
Samsung Gear Fit Fitness Tracker

STMicroelectronics STM32F439ZI 180


MHz, 32 bit ARM Cortex-M4 CPU
Lecture #2 14
iPhone 4 Teardown

The A6 processor is the first


Apple System-on-Chip (SoC)
to use a custom design,
based off the ARMv7
instruction set. It is a
predecessor to the ARM
Cortex-M4 well be using.

This is an iPhone 4. What


processor does the iPhone 6
use?

Lecture #2 15
Semiconductor Memory
- Random access memory (RAM): same amount of time is
required to access any location on the same chip. Read/write.
- Read-only memory (ROM): can only be read; cannot be
written to directly by the processor

Random Access Memory


- Dynamic Random Access Memory (DRAM): periodic
refresh is required to maintain the contents of a DRAM chip
- Static Random Access Memory (SRAM): no periodic
refresh is required. Always more predictable and usually
faster than DRAM.
- So what the heck is an SDRAM, so often used nowadays?

Read-Only Memory
- Mask-programmed read-only memory (MROM):
programmed when being manufactured
- Programmable read-only memory (PROM): the memory
chip can be programmed by the end user

Lecture #2 16
Erasable Programmable ROM (EPROM)
1. Electrically programmable many times
2. Erased by ultraviolet light (through a window)
3. Erasable in bulk (whole chip in one erasure operation)

Electrically Erasable Programmable ROM (EEPROM)


1. Electrically programmable many times
2. Electrically erasable many times
3. Can be erased one location, one row, or whole chip in one operation

Flash Memory
1. Electrically programmable many times
2. Electrically erasable many times
3. Can only be erased in bulk

Lecture #2 17
Computer Software
- Computer programs (programs) are known as software
- A program is a sequence of instructions

Machine Instruction
- A sequence of binary digits that can be executed by the processor
- Hard to understand, program, and debug for human being
- E.g. in the ARM Cortex M4, instruction 0010 0010 0110 0100 puts the
number 100 in register #2. How many bytes long is this instruction?
- OK, the instruction is also 0x2264. Does that help much? What is 0x64
in base 10?
So what might 0x22 be? Thats 0010 0010 or 00100 010. OK, 001002 is move
immediate and 0102 is register #2

Assembly Language
- Defined by machine instructions
- An assembly instruction is a mnemonic representation of a machine
instruction, e.g. ADD represents a register add (0001100)
- Assembly programs must be translated to binary before it can be executed:
Assembler does this translation:
ADD R2 R1 R0 0001100 010 001 000 = 0x1888
- In this course well be dealing with Assembly Language almost exclusively.
Lecture #2 18
High-level Language
- Syntax of a high-level language is similar to English
- A translator is required to translate the program written in a
high-level language -- done by a compiler
- High-level languages allow the user to work on the program logic
at a more conceptual level (e.g. you dont have to worry about
whats in register R2).
- Our textbook uses some C language examples, which are helpful if
you understand C, but is not necessary to this course.

Source Code
- A program written in assembly or high-level language

Object Code
- The output of an assembler or compiler--machine instructions
and data in binary (ones and zeroes) form.

Lecture #2 19
So Why Use Assembly Language in 251?
Writing software in a higher level language is more efficient
Employers want new engineers who are good with higher level
language coding
BUT
The goal of this course is understanding how processors work,
not writing large programs to do complex tasks
Assembly Language is a readable version of the instructions the
processor understands
Programming things like big register manipulation is actually
more straightforward in assembly language than in a high level
language (arguable point, but we arent going to argue about it!)
Employers also usually like engineers who understand well the
inner workings of the computers they are using

Lecture #2 20
ARM Cortex-M4 Registers

This is important!
Learn it!

Lecture #2 21
ARM Cortex-M4 Registers

Lecture #2 22
We will represent number bases with these prefixes
Base Prefix Example

binary 0b 0b10001010
octal @ @1234567
decimal 12345678
hexadecimal $0x 0x5678
or hex

Memory Addressing
- Memory consists of a sequence of directly addressable locations.
- A location is referred to as an information unit.
- A memory location can be used to store data and instructions.
- A memory location has two components: an address and its contents.

Address Contents

The components of a memory location

Lecture #2 23
Data transfers between the CPU and the memory are done over the
common buses: address bus and data bus.

Transferring Data between CPU and Memory

Notations: [addr] represents the contents of a memory location,


[register name] refers to the contents of the specified register.

E.g. [0x20] refers to the contents of memory location at address 0x20, i.e. at address 32.

E.g. [R1] refers to the contents of register R1; similarly with other registers.

Value Address means that the data value Value is stored at memory or register
address Address. E.g. 0x20 R1 means that the value 0x20 is placed in register R1.
What does 0xAB 0x2000 mean?

Lecture #2 24
Operation of a Computer (see Section 1.4 in text)
Computers execute programs instruction-by-instruction. Lets look at the execution of
instructions in detail:

0. Program counter register PC points to (i.e. contains the address of) the memory
location containing the next instruction to be executed. This counter will be updated to
point to the following instruction during or after execution of the current instruction.

1. Instruction Fetch: Using the current value of PC, read the next instruction to execute
from memory. Store this data in the instruction register, IR. That is: [[PC]] IR
PC is the name of the register;
[PC] is the address of the instruction to be executed;
[[PC]] is the instruction itself, contained at the memory address [PC].
Note that IR is an internal register, not accessible with computer instructions.

2. Decode Instruction: Determine which instruction is to be executed using the


contents of the IR.

3. Execute Instruction: Activate appropriate control lines in processor sequentially to


perform the action specified by the Instruction at particular clock ticks. This is a
classic Moore machine operation.

Lets go over a simple example on the next slide.


Lecture #2 25
Instruction Execution Example
Lets execute the instruction ADD R4,R3,R0 and assume this instruction begins at
address 0x1000. This instruction means: add contents of register R0 to the contents of
register R3, and store the results into register R4. Heres what happens:
1. Fetch instruction (read) from memory addresses 0x1000 and 0x1001. The contents
of these are the computers bit pattern for ADD R4,R3,R0. Store these 16 bits in
instruction register, IR.
2. Decode the instruction in IR. Determine that it is the ADD instruction.
3. Connect register R0 to input 1 of the ALU.
4. Connect register R3 to input 2 of the ALU.
5. Set controls to ALU to do a 32-bit add operation.
6. Store the outputs of the ALU into register R4.
7. Increment the program counter and store that value back in the program counter:
[PC] + 2 PC. Why 2? This operation can actually occur after step 1, in parallel with
steps 2-6. Why?
8. Go back to step 1, using the new value of PC.

See a more complete example in Sections 1.4.2-1.4.3 in text.


Understand this example!
Lecture #2 26
Questions?

Next Lecture: Moving Data From (load) and To


(store) Memory with ARM
These are basic concepts well use throughout
the semester. Understand them!
Read Chapter 5 in text (Load and Store)

Lecture #2 27

Você também pode gostar