Title: Topic 6: Microcontroller Design
1Topic 6Microcontroller Design
- SFSU ENGR 852
- Spring 2003
- 3/31, 4/7
2This Lecture
3A Simple Microcontroller
- Edge detector
- Same as the FSMs function we covered in week 2 of
class - Output Single high pulse when rising edge found
- Input Data line
- Block diagram
4A Simple MicrocontrollerRequired Instructions
Output 0 Output 1 Jump to 00 if IN 0 Jump to 11
if IN 1
5Class ProblemInstruction Set Design
- For practice
- Instruction set I
- Separate OUTPUT JUMP instruction
- Instruction set II
- Design an instruction format for
- OUPUT/COUNT-UP PC
- OUTPUT/JUMP
6A Simple MicrocontrollerMicrocontroller Design
- Things to notice (Instruction Format I)
- Our commands either
- Change output and Count up PC by 1
- Change address (PC value) and hold output
- Our microcontroller must do the same
-
7A Simple MicrocontrollerMicrocontroller Design
- Topdown design Block selection
- A PC that counts up but can also be loaded
- Loadable counter
- ROM to hold the program
- MxN ROM (M , N
) - Flip-flop to hold output during JUMP
- Flip-flop with Enable
8A Simple MicrocontrollerMicrocontroller Design
- General structure of our microcontroller
9A Simple MicrocontrollerMicrocontroller Design
- A handy component that well use A MUX with an
ENABLE. OUT is 0 when EN0.
OUT
10A Simple MicrocontrollerMicrocontroller Design
- General structure of our microcontroller
11A Simple MicrocontrollerClass Problem
12A Simple MicrocontrollerOp-codes
- Op-codes
- Three instructions that I see.
- 1. Output output_value
- 2. Jump to address if IN0
- Jump to address if IN1
Output 0 Output 1 Jump to S00 if IN 0 Jump to
S11 if IN 1
Lets finalize these instructions
op-codes Output op-code 0X output value Jump
if IN1 op-code 10 Jump address Jump if IN0
op-code 11 Jump address
13A Simple MicrocontrollerMicrocontroller Design
- Instruction access To access instruction the PC
contents (The address of the next instruction) is
fed into the ROM.
14A Simple MicrocontrollerMicrocontroller Design
- OUTPUT Instruction If the instruction is an
OUTPUT, O0 is output. This is put in a
flip-flop so if the next instruction is a JUMP,
the ouput value can be held.
Output Flip-Flop
15A Simple MicrocontrollerMicrocontroller Design
- JUMP if IN0 Instruction If IN0 and the
instruction is JUMP if IN0, then PC is loaded.
The PC is loaded with the address from the
instruction, and the MUX is enabled by O7.
16A Simple MicrocontrollerMicrocontroller Design
- JUMP if IN1 Instruction If IN1 and the
instruction is JUMP if IN1, then PC is loaded.
The PC is loaded with the address from the
instruction, and the MUX is enabled by O7.
17A Simple MicrocontrollerMicrocontroller Design
18A Simple Microcontroller IIDesign(1)
- Use the simple microcontroller on the last page
as a model. - Design a controller for the following datapath
19A Simple Microcontroller II Design(2)
- The instruction set is (5 instructions)
- LOAD X ? TMP
- MOVE TMP ? A
- LOAD Y ? TMP
- MOVE TMP ? B
- A B ? TMP
- Design the microcontroller for this system
20A Simple Microcontroller II?-Controller Input
Output
- Remember what a controller is
- It needs something to tell it what to do
- Here the input will be instructions ? Lets
assign values - LOAD X ? TMP 000
- MOVE TMP ? A 010
- LOAD Y ? TMP 001
- MOVE TMP ? B 011
- A B ? TMP 100
7
3
21A Simple Microcontroller II?-Controller
Instruction Set
- For this problem
- Use separate OUTPUT and JUMP instructions
- Each instruction will take at least 2 clock ticks
- OUTPUT ? One clock tick
- JUMP ? One clock tick
22A Simple Microcontroller II Things to Determine
- Things we need to find Jump conditions, output,
ROM width, ROM depth, CTR bits, MUX select lines,
and Outputs.
23A Simple Microcontroller IIROM Width
- To find ROM width find instruction width
- Look for the maximum width needed to successfully
accommodate all instructions - The ?-controller instructions will need to
include - Op-code
- Depends on number of instructions
- Necessary information to carry out instruction
- OUTPUT
- Output values
- JUMP
- New address
24A Simple Microcontroller IIOp-code
- To find Op-code width find number of instructions
- Number of instructions is
- of OUTPUT instructions of JUMP instructions
- of OUTPUT instructions
- 1
- of JUMP instructions
- Not trivial..
25A Simple Microcontroller IIOp-code
- JUMP instruction number depends on IF statements
in program - A possible program represented by graph
- Natural flow is to the right
- Jumps are to the left
26A Simple Microcontroller IIOp-code
27A Simple Microcontroller IIOp-code
- List of JUMPs
- 1. If inst21 Jump
- 2. If inst11 Jump
- 3. If inst01 Jump
- Jump Always
28A Simple Microcontroller IIOp-code
- List of JUMPs
- 1. If inst21 Jump
- 2. If inst11 Jump
- 3. If inst01 Jump
- Jump Always
- List of OUTPUTs
- 1. OUTPUT value
5 Instructions 3-bits of Op-code needed (This
also tells us how many bits will go into the MUX.
Four JUMP instructions, four inputs to the MUX. ?
One input is 1)
29A Simple Microcontroller II Things we know now
- Things we need to find Jump conditions, output,
ROM width, ROM depth, CTR bits, MUX select lines,
and Outputs.
EN
1 IRlt0gt IRlt1gt IRlt2gt
00 01 10 11
?x? ROM
LOAD
Output
Condition selector.
RESET
Width of buses depth width of ROM.
30A Simple Microcontroller IIDesigning Op-Code
The ENABLE signal is part of the Op-code as are
the MUX signals.
31A Simple Microcontroller IIInstruction Width
JUMP
- To find JUMP instruction width
- Youll need 1 enable line bit (In our op-code
already). And enough bits to accommodate any
address you may want to jump to. The program we
wrote has 14 instructions without OUTPUT
instructions. Adding OUTPUT instructions may
cause it to double. 32 addresses looks big enough
? therefore 5 address lines are needed. Youll
need 2 MUX selector bits (In our op-code
already). A total of 8 bits. - Address (5 bits)
- 3-bit op-code (Op-code designed such that it can
be used as input to MUX and as ENABLE signal
directly with no extra logic needed).
32A Simple Microcontroller IIOutput Block Design
- To find Output
- To make ?-controller instructions as few bits as
possible - First, group datapath control signals. ( Look for
groups of signals that can only have member
asserted at a time. ) - Sources ( Values put ON bus ) ? TX, TY, T, TTMP
? - Destinations ( Where values from bus are put ) ?
ENA, ENB, ENTMP ? - So, since only one of each group will be asserted
at a time, lets use decoders flip-flops.
33A Simple Microcontroller II Things we know now
Flip-flops for outputs
EN
1 IRlt0gt IRlt1gt IRlt2gt
00 01 10 11
?x? ROM
LOAD
Condition selector.
RESET
Width of buses depth width of ROM.
Clk
34A Simple Microcontroller IIInstruction Width
OUTPUT
- To find Instruction width
- Look for the maximum width needed to successfully
accommodate all instructions - To find OUTPUT instruction format/width
- This tells you how many bits youll need for an
OUTPUT instruction. Youll need 4 (2 2) for the
decoders and 3 op-code bits ( total 7 bits ) - Source bit 1
- Source bit 0
- Destination bit 1
- Destination bit 0
- 3 op-code bits
35A Simple Microcontroller IIInstruction Width
- To find Instruction width
- Look for the maximum width needed to successfully
accommodate all instructions - The OUTPUT instruction needs 7 bits
- The JUMP instruction needs 8 bits
- ? Instructions need to have 8 bits
36A Simple Microcontroller II Things we know now
Flip-flops for outputs
EN
1 IRlt0gt IRlt1gt IRlt2gt
00 01 10 11
32x8 ROM
LOAD
O7
O60
O6,O5
O40
RESET
Clk