Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Microcontroller
STK500
ment
Development
Board
Description of STK500
ATmega 16
Atmega16 Features
Features
High-performance, Low-power AVR 8-bit Microcontroller
Advanced RISC Architecture
131 Powerful Instructions Most Single-clock Cycle Execution
32 x 8 General Purpose Working Registers
Fully Static Operation
Up to 16 MIPS Throughput at 16 MHz
On-chip 2-cycle Multiplier
High Endurance Non-volatile Memory segments
16K Bytes of In-System Self-programmable Flash program
memory
512 Bytes EEPROM
1K Byte Internal SRAM
Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
Data retention: 20 years at 85C/100
years at 25C(1)
Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
Programming Lock for Software Security
MOS memories
RAM's
ROM's
I I
-
SRAM DRAM ROM
I
'" )(
. .,.
" y .
' .
.$10FF
S 11,0[], ' "' x.... ;,
=' ,,,.
"'
.,.
{Q - 6-4K IC 8)
- "
Exte-.malSR.AA.1 '' t... _ .... _
. -- . .
--
. -. -
- .
-
-
Re gister S
mmry .
- .
.
. . . -- .
-
.
.
.
. .
--- -
-- -- -
:a -- "'
-
-- ,u
--
-- - - -
=
'I1.--- . . . .
-
. . . . . . . .
. . . . . . . .
EEPROM
Line 4095
16 bits=2^16=65,536 (0-65,535)
Line 0 1 byte
SRAM
Remember, everything starts with zero. So 4Kbytes x 8
we have 65,536 elements that range from 0
to 65,535
Line
4095=0xFFF 4095
Program Flow
A special register called the program counter
keeps track of the address in the Flash RAM to
be executed.
On each clock cycle, that addres is decoded
and the appropriate values are taken from
memory and passed into the Arithmetic Logic
Unit (ALU) to be processed.
Unit (ALU) to be processed
The value to be processed (operands) must
come from a special set of 32 registers called
the General Purpose Registers. To access
SRAM or I/O, they must be brought in/out of the
registers.
Atmega 16 Core (The Brain)
G
Generall Purpose
P R i t
Register
(The Interface)
Everything going in/out
must touch the registers
Program Memory:
(The Planning Center)
10FF 0007
Stack Pointer Store Copy here
Timing (the heartbeat)
Microprocessors uses oscillator (a quartz crystal) which
can produce a constant square wave to provide the
d
synchronization t t
of everything t
on the chip. id th
Each rising
edge of the square wave allows an operation to take
place such as loading instructions, executing
place such asand
instructions, loading instructions
saving results. executing
Different operations take a different amount of cycles
(one period of the square wave). See Instruction set
summary for cycles.
The oscillator source can be external or internal (on
some chips).
The Atmega16 can be set to have a clock frequency of
8MHz. With many of the operations taking only 1 cycle,
that is approaching 8 million operations per second! You
could add the numbers from 1 to a million in .125
seconds!
Rising/Falling Edge
Everything in a microcontroller happens on the
rising or falling edge of a signal.
Most components with in the microcontroller
allow you to choose which edge but default is
rising .
The edge is the signal for a component to take in
new information and output the just processed
information.
It also allows for registers, components, etc. to
be synchronized.
Prescale for a Timer
Main Clock (1 MHz)
Well learn more about the specific operation of A/D and D/A later in
the course
Timers
Timers are really just counters
A register that counts (up or down depending on
settings)
The time runs using the main system clock and a
prescaler. A prescaler divides the main system clock.
Each of the four timers in the Atmega128 has its own
prescaler.
So, if the system clock runs at 1 MHz, and I set the
prescaler to 1024, then my clock frequency will be ~1
kHz. In other words, I get 1 count every ~.001
seconds.
Pulse Width Modulation
Pulse Width Modulation
A method by which devices can be sent a voltage that is
equivalent to an analog voltage
If I have a device that I want to give 2.5 volts, I could use and
D/A or I could use a 5 volt PWM signal with a 50% duty cycle.
The effective voltage seen by the device is equal to the peak
value * the duty cycle (0-1)
Veffective=5 volts*.5=2.5 volts
The key is that the frequency of the PWM wave must be faster
than the device can respond too.
If I have a small motor, and I suddenly step the voltage to 5 volts
and record the time it takes to come to steady state speed. And I
find that it takes .1 seconds to reach 63% of the steady state value,
this is called one time constant (1-e-1). Then, following a good rule
of thumb, I should make my PWM frequency at least 10 time faster
than it can react. .1 second=10 hz100 Hz (minimum)
PWM
Atmega 16 Circuit Diagram
Status Register
Must set this to enable interrupts
Bit 7 I: Global Interrupt Enable
Bit 6 T: Bit Copy Storage
Bit 5 H: Half Carry Flag
Bit 4 S: Sign Bit, S = N V
Bit 3 V: Twos Complement Overflow Flag
V: Twos Complement Overflow Flag
Bit 2 N: Negative Flag
Bit 1 Z: Zero Flag
Bit 0 C: Carry Flag
Interrupts
Interrupts are similar to subroutines except that you dont call
interrupts, they happen whenever a particular
interrupts p rt c l r event happens
happens.
Internal interrupts are generated from several sources like
timer/counters. I could set up a counter to interrupt when it reaches
a certain value. When it interrupts, the main program would stop
and the iinterrupt
d th t t routine
ti would be executed.
ld b t d After
Aft completion,
l ti the
th
reti command (return from interrupt) would load our return location
into the program counter where it was stored from the stack.
External interrupts have a similar operation except that their source
is from pins on the mP. I could set an interrupt to occur when a
certain pin on the chip went high.
You must set the Global Interrupt Enable in the SREG register to
allow interrupts. This is easily done with the sei command. Further,
you usually will need to clear the GIE when executing an interrupt.
Why? Because you dont want another interrupt to interrupt you
while executing the first interupts code. Clearing GIE is done with
the cli.