Professional Documents
Culture Documents
Microcontroller
STK500
Development
Board
Description of STK500
A row of eight
g p
pushbutton switches,, each of which has a
small LED lamp above it. These can be connected to the
microcontrollers using the array of connectors just
above.
above
There is then a large white area, which is where the AVR
chips to be programmed are inserted.
Usually, a STK500 comes with a Atmega 16L chip
mounted in the large socket on the right.
The
Th green area att the
th top
t contains
t i the
th programming
i
electronics, and the connectors for power and
communications.
ATmega 16
Micro
Controller
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
O
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
D t retention:
t ti
20 years att 85C/100 years att 25C(1)
Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
p
True Read-While-Write Operation
Programming Lock for Software Security
Memory
Memory
Flash ROM
Like EEPROM but faster and cheaper
Limited write cycles (but in the several thousands)
Registers
Register-a
Register a generic term with many meanings. At
the top level, its a group of bits (like a byte).
I/O registers are set to configure the microcontroller
1 =Output
0=Input
1 byte
EEPROM
Line 4095
In p
programming
g
g world, 4K does not equal
q
4000, it equals
q
4096=2^12. And we
would address 4096 bytes starting from zero and going up to 4095
The Atmega16 is called so because it has 16 kB of Flash RAM,
Addressing
How many bytes can I address with an 8
or 16 bit register?
8 bits=2^8=256 (0-255)
16 bits=2^16=65,536 (0-65,535)
=refer to
Line 0
SRAM
4Kbytes x 8
4095=0xFFF
1 byte
Line
4095
Program Flow
A special
p
register
g
called the p
program
g
counter
keeps track of the address in the Flash RAM to
be executed.
On each clock cycle,
cycle that address is decoded
and the appropriate values are taken from
memory and passed into the Arithmetic Logic
Unit (ALU) to be processed.
processed
The value to be processed (operands) must
come from a special set of 32 registers called
the
h G
Generall P
Purpose R
Registers.
i
T
To access
SRAM or I/O, they must be brought in/out of the
registers.
g
Program Memory:
(The Planning Center)
Input/Output: Eyes,
ears, and other
senses
Program Counter
What element holds the address of the next line to be
executed in program memory?
The program counter
rjmp Main
0x0001
0x0002
0x0003
call MySubroutine;
0x0004
.more code
Restore Program
counter using SP
as address to
retrieve value from
stack
MySubroutine:
0x01BD
0x01BE
Internal Memory
(Gen. Purpose Registers, I/O registers, SRAM)
0x0100
Call Subroutine
jumps Program
counter and stores
return address in
stack
0x0101
0x10FD
0x10FE
0x10FF
00
00
00
00
00
04
Stack Pointer
Initialized
10FF
Stack Pointer
0007
Store Copy here
Rising/Falling Edge
Everything
y
g in a microcontroller happens
pp
on the
rising or falling edge of a signal.
Most components with in the microcontroller
allow
ll
you to choose
h
which
hi h edge
d b
but d
default
f l iis
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.
More prescale
For devices like the A/D, the prescale will
determine how fast you sample (if in freerunning mode).
You want to sample fast enough so that you do
not alias (refer to Alias lecture).
But you may want to not set the prescale too
small (too fast sampling) because it wastes
power
For small systems running on battery power,
reduction of power is critical
critical.
Timing
I/O ports
Input
p and Output
p p
ports are the way
y the uC interfaces
with other components.
Each port contains 8 pins.
Ports can be input only
only, output only
only, or bi
bi-directional.
directional
The ATmega has all bi-directional ports. Bi-directional
ports means they have the capability to be both, but you
must choose one or the other at any given time
time.
The direction of each pin is set through a special register for
each port.
I/O ports
Inputs
External connections determine pin voltage
Outputs
Microcontroller sets pin voltage
Serial communication
USART=Universal Synchronous
y
and Asynchronous
y
serial Receiver and Transmitter
Serial communication
Communicate serially
y back to a PC
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.
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 steadyy 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
Status Register
Bit 7 I: Global Interrupt
p 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
Bit 2 N: Negative Flag
Bit 1 Z: Zero Flag
Bit 0 C: Carry Flag
Interrupts