Micro-controllers

advertisement
Microcontrollers
by
Andy Zwirko – K1RA
Tom Zeltwanger – KG3V
Eric Nystrom – W4EON
Overview
•
•
•
•
•
•
What are microcontrollers?
Microcontrollers vs. microprocessors
Where are microcontrollers used?
Popular microcontrollers & vendors
Programming microcontrollers
Microcontroller projects (Eric, Tom, Andy)
What is a Microcontroller?
• An embedded, low power (uW/nW) computer that
usually runs a dedicated task
• An interrupt driven device providing real time,
predictable responses to events
• A self contained device with no external address
and data buses
What is a Microcontroller?
• A microcontroller (µC, uC or MCU) is a
single integrated circuit that contains the four
major parts of every computer system
• A device optimized for control applications
What is in a Microcontroller?
• All computers have a CPU (central processing
unit) that executes programs
What is in a Microcontroller?
• A computer has some type of memory where it
can store variables and instructions or steps
• Memory may be RAM, ROM, (E)EPROM, Flash
What is in a Microcontroller?
• Computers have a clock or oscillator that
determine the speed of program execution
What is in a Microcontroller?
• Computers have various input and output (I/O)
capabilities to support various peripherals.
What is in a Microcontroller?
• Microcontroller range from 8 – 40+ pin packages
• Extra pins provide analog and digital I/O options
• 8, 16, 32 & 64 bit instructions & data controllers
Where To Use a Microcontroller?
• We need to flash an LED or light 3 times
• Manually you would have to push button 3 times
Where To Use a Microcontroller?
• A microcontroller would allow sensing the button
• The uC and its program could then flash the
LED based on its system clock and pgm timer
Where To Find Microcontrollers?
• Microcontroller are found everywhere!
• uC’s are considered embedded systems
Microcontrollers in Ham Radio
Popular Microcontrollers
• Early day (1970’s/80’s)
– Intel 8048
– Intel 8051
– Zilog Z8
– Motorola 68HC05
Popular Microcontrollers
• Current day
– Microchip PIC / PICAXE
– Amtel AVR / ATmega
– Parallax BASIC Stamp
Microchip PIC 16F628 Specs
•
•
•
•
•
•
•
Programmable Intelligent Controller
8-bit CMOS processor
4 MHz internal oscillator
35 instructions
Single cycle execution (RISC).
200ns instruction execution
Non-volatile memory:
– Flash program memory (3.5K bytes)
– EEPROM data memory (128 bytes)
• Volatile memory
– RAM data memory (224 bytes)
Microchip PIC 16F628 Specs
•
•
•
•
•
•
•
•
1 digital USART (async. RX/TX)
16 I/O pins w/ individual direction ctrl
1 Capture/Compare 16-bit
1 PWM peripheral 10-bit
2x 8-bit & 1x 16-bit timers (48 KHz)
2 Comparators (int. or ext. reference)
Programmable voltage reference
Voltage operation 2 to 5.5 VDC
– 100 nA @ 2 VDC standby
– 120 uA @ 1MHz & 2 VDC
Microchip PIC 16F628 Pin Out
• PIC pins and associated functions
• Some are dual purpose
Programming Languages
for the PIC
C Source File
Assembly
Language File
C Compiler/Linker
Assembler/Linker
Device Programmer
PIC Instruction Set
W – The W register (or accumulator) is used as temp storage for many instructions
f – “f” represents a user defined variable or system memory location
k – “k” represents a literal number or a defined constant
d – The value or “d” (0 or 1) determines where the numerical results is stored W (d=0) or f (d=1)
b – “b” represents a particular bit in a 8-bit memory location (7,6,5,4,3,2,1,0)
Programming the PIC (S/W)
• MPLAB Integrated Development Environment (IDE)
• Assembly for free, C compilers cost $$$
Programming the PIC (H/W)
• Hardware programmer and associated pins
PIC Circuit and Program
• Simple circuit and program that blinks an LED
on pin 6 (RB0) of a PIC16F628
PIC Kits
• PICKit2 - $50
– www.microchip.com
• PICEL-III - $65
– www.kangaus.com
• PIC LAB - $120
– www.apogeekits.com
Atmel AVR ATmega168 Specs
•
•
•
•
•
•
•
•
•
Advanced Virtual RISC
8-bit core
16 MHz clock
Single cycle instruction
100 instructions
Hardware Multiplier
Flash: 16 Kbytes w/ Boot Code
EEPROM: 512 bytes
SRAM: 1Kbytes
Atmel AVR ATmega168 Specs
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
32 registers
2x 8-bit timers
16-bit timer
Real Time Clock w/ oscillator
3x PWM channels
8x channel ADC 10-bit
Two wire serial interface
Master/Slave SPI Serial Interface
Program Serial USART
Watchdog Timer
Analog Comparator
23x I/O lines
AVR program cable
24x external interrupts
On-chip debugging through JTAG
Simple programming (LPT port, 4 resistors & AVRDUDE)
1.8-5.5 VDC / 0.5uA – 3.6mA
Atmel AVR ATmega168 Pin Out
• AVR pins and associated functions
• Some are dual purpose
ATMega168 Instruction Set
Arithmetic
ADD Rd, Rr
ADC Rd, Rr
ADIW Rd+1:Rd, K6
SUB Rd, Rr
SUBI Rd, K8
SBC Rd, Rr
SBCI Rd, K8
SBIW Rd+1:Rd, K6
INC Rd
DEC Rd
AND Rd, Rr
ANDI Rd, K8
OR Rd, Rr
ORI Rd, K8
EOR Rd, Rr
Arithmetic
COM Rd
NEG Rd
CP Rd, Rr
CPC Rd, Rr
CPI Rd, K8
SWAP Rd
LSR Rd
ROR Rd
ASR Rd
MUL Rd, Rr
MULS Rd, Rr
MULSU Rd, Rr
FMUL Rd, Rr
FMULS Rd, Rr
FMULSU Rd, Rr
Bit & Other
BSET s
BCLR s
SBI A, b
CBI A, b
BST Rd, b
BLD Rd, b
NOP
BREAK
SLEEP
WDR
Transfer
MOV Rd, Rr
MOVW Rd+1:Rd,
Rr+1:Rr
IN Rd, A
OUT A, Rr
PUSH Rr
POP Rr
LDI Rd, K8
LDS Rd, K16
LD Rd, X
LD Rd, -X
LD Rd, X+
LDD Rd, Y+K6
LD Rd, -Y
LD Rd, Y+
LDD Rd, Z+K6
LD Rd, -Z
LD Rd, Z+
Transfer
STS K16, Rr
ST X, Rr
ST -X, Rr
ST X+, Rr
STD Y+K6, Rr
ST -Y, Rr
ST Y+, Rr
Branch
Jump
RJMP K12 CPSE Rd, Rr
IJMP
SBRC Rr, b
EIJMP
SBRS Rr, b
JMP K22
SBIC A, b
SBIS A, b
BRBC s, K7
BRBS s, K7
STD Z+K6, Rr
ST -Z, Rr
ST Z+, Rr
LPM
LPM Rd, Z
LPM Rd, Z+
ELPM
ELPM Rd, Z
ELPM Rd, Z+
SPM
ATmega has multiplication hardware, 32 registers, pointer registers (X,Y,Z),
register addressing, I/O ports, access read-only data in program memory,
conditional branches
Call
RCALL K12
ICALL
EICALL
CALL K22
RET
RETI
Programming the AVR
• AVR Studio 5, supports C, Pascal, Basic, free
• GNU gcc support, avr-gcc, WinAVR
AVR ATmega Kits
• STK300 - $130
– www.microcontrollershop.com
• ATMEGADEVBRD - $40
– www.futurlec.com
• Arduino Uno - $30
– www.sparkfun.com
Arduino (ATmega based)
• The 555 of the 21st century
• Open Source Hardware
– Open architecture for expansion
– Shield add-ons:
• USB, ethernet, wireless/XBee, motor, MIDI, BT, LCD
• Open Source Software Development Tools
– Integrated Development Environment
– Rich library sets for supporting peripherals I/O
• Linux, MacOSX and Windows support
Arduino Instruction Set
Programming the Arduino
FARA Member
Microcontroller Projects
• Tom KG3V – CWlink
• Eric W4EON – Antenna Measurements
• Andy K1RA – WSPR Beacon
CWlink
An embedded CW Project
by
Tom Zeltwanger
KG3V
Based on the Arduino Board
CWlink Objectives
• Learn about Arduino boards and
development
• Demonstrate useful Ham Arduino App
• Start by sending canned CW text
• Upgrade to accept hand-keyed CW for
record/playback (preserve “fist”)
• Long Term - Untethered rig operation for
CW using a Keyer (vs. keyboard)
Arduino Duemilanove Board
•
•
•
•
Microcontroller ATmega168
Clock Speed 16 MHz
Operating Voltage 5V
Input Voltage 7-12V
• Digital I/O Pins 14
– 6 provide PWM output
• Analog Input Pins 6
• DC Current per I/O Pin 40 mA
• DC Current for 3.3V Pin 50 mA
• Flash Memory 16 KB
– 2 KB used by boot loader
• SRAM 1 KB
• EEPROM 512 bytes
CWlink Architecture
Rig
Serial
Output
Serial –
Wireless
Link
Arduino
Board
Serial Input
Keyer
Cwlink Keyer State Diagram
Power Up
Cal Failed (loop)
Init
Init Success
Cal
Cal Success
Record
Mode Switch Change
5 Sec Timeout
Playback
Mode Switch Change
PIC, DDS & Return Loss Bridge
An Antenna Measurement Project
by
Eric Nystrom
W4EON
Based on the PIC 16F1827
Signal Generator for Antenna
Analyzer
• PIC 16F1827
– 18 pin device
– 32 MHz
– Accurate internal clock so
no crystal needed
• Pins used
–
–
–
–
3 pins to control DDS80
2 pins for Serial IO
1 pin for AD converter
3 pins for in circuit
programming
Analyzer Development
• Development Tools
– CCS C compiler
– CCS ICD 64 programmer (in
circuit)
• Code
–
–
–
–
2 Files
600 source lines
Reused code from other projects
Only minor modifications for this
project
• Resources:
– ROM used: 1830 words (45%)
– RAM used: 52 (14%)
• PIC code functions
– Serial Interface
– Set frequency of DDS
– Read AD converter
Architecture Diagram
In Circuit
Programmer
Programming
Control
JAVA Program for
Plotting and
Analysis
Serial Link
PICC 16F1827
Bridge Voltage
Return Loss Bridge
Antenna
DDS Control
DDS 80
RF To Bridge
• About 8 hours of development time.
• Code for analysis and plotting is contained in a PC program written in Java.
Lessons Learned
The bridge is a wideband
device. The bridge
measures what the
antenna is receiving as
well as the component
from the signal generator.
Measurement differs from
day to night.
Weak Signal Propagation Reporter
(WSPR) 160m to 6m
Beacon Board Project
by
Andy Zwirko
K1RA
Based on the PICEL-III Board
PICEL-III Development Board
• PIC Programmer for 18-pin PICs via PC
USB Port made by AA0ZZ
• Hardware components:
–
–
–
–
–
–
–
–
–
PIC 16F628A
2x16 line LCD (with backlight)
Rotary encoder
Three general purpose pushbuttons
Three LEDs
Speaker with driver
Stereo jack for CW paddle input
Stereo jack with transistor driver to key TX
Transistor conditioner for converting lowlevel signals for PIC input (frequency
counter) detection
– Multi-purpose BNC connector for signal
I/O
– Expansion port for AmQRP DDS-30/60
AmQRP DDS-60 VFO
• Analog Devices AD9851
DDS
• 0-60 MHz programmable
oscillator
• 5th order elliptic filter
– harmonics down 40db
• Adjustable RF-amp
– 10-40 mW
• 8 pin header
WSPR Beacon Code
• AA0ZZ created signal generator program for
PICEL-III (0-60 MHz)
• W3PM modified AA0ZZ program
– modulate signal generator with WSPR “whisper”
encoding scheme TX-only
– ~2700 lines of code w/ comments
– WSPR signal conveys call sign, Maidenhead grid
locator and power level
– Example: KW4VA FM18 17
– Forward Error Correction (FEC) is employed
– Modulation scheme narrow-band 4-FSK modulation.
KW4VA Beacon DX Last 24 Hours
Call
Grid
Km
N8TWX
EN83
770
W3HH
EL89
1149
KC8NN
EN66
1167
WA9FIO
EN43
1254
WA5ETV
EM15
1741
W5OLF
DM78
2396
• Stations spotting / hearing WSPR beacon in the last 24 hours (30/40m)
• KW4VA beacon running 20 mW and attic antenna fed with 300 ohm feed line
KW4VA WSPR Top 20 Best DX
Date / Time
Beacon
Freq
SN
DT
Grid
Pwr
Reporter
Rgrid
Km
Az
2011-02-26 02:14
KW4VA
10.140268
-21
0
FM18cr
0.02
CT2IWW
IN51wf
5778
64
2011-03-08 00:38
KW4VA
14.097096
-26
0
FM18cr
0.02
WB2FXO
CM94su
3789
277
2011-02-15 00:00
KW4VA
14.097127
-22
-1
FM18cr
0.02
WA7KGX
CN85no
3742
297
2011-02-11 17:12
KW4VA
14.097169
-27
-1
FM18cr
0.02
VE6OG
DO33
3127
313
2011-02-27 05:38
KW4VA
7.040176
-27
0
FM18cr
0.02
KE7LEU
DN41
2827
287
2011-03-08 03:02
KW4VA
14.097189
-26
-1
FM18cr
0.02
KI7AB
DM65qg
2578
270
2011-02-19 04:42
KW4VA
10.140253
-26
0
FM18cr
0.02
W1CDO
DM73
2507
265
2011-02-19 03:24
KW4VA
10.140257
-26
0
FM18cr
0.02
W5OLF
DM78hb
2396
277
2011-02-11 07:42
KW4VA
7.040164
-27
0
FM18cr
0.02
W0DHB
DN70kc
2344
282
2011-02-27 17:36
KW4VA
21.096018
-25
-1
FM18cr
0.02
KN5X
EM10dm
2032
249
2011-02-13 23:54
KW4VA
14.097065
-24
0
FM18cr
0.02
N5VP
EL29jj
1906
242
2011-03-07 15:08
KW4VA
14.097176
-31
0
FM18cr
0.02
K5XL
EM12kp
1868
255
2011-02-18 07:54
KW4VA
7.040186
-28
0
FM18cr
0.02
KE7A
EM12kx
1852
256
2011-02-19 02:36
KW4VA
10.140253
-26
0
FM18cr
0.02
AD4PT
EM12kx
1852
256
2011-02-10 07:56
KW4VA
7.040155
-29
0
FM18cr
0.02
K5ARH
EM30xe
1612
238
2011-02-16 09:36
KW4VA
7.040167
-24
0
FM18cr
0.02
KC8JNV
EN11xe
1576
286
2011-03-02 03:14
KW4VA
7.040183
-29
0
FM18cr
0.02
N0SF
EM29mh
1482
278
2011-02-10 04:12
KW4VA
7.040146
-25
0
FM18cr
0.02
K0GUN
EM36cu
1419
267
2011-02-22 14:12
KW4VA
14.097175
-17
-1
FM18cr
0.02
KC0BMF
EN31be
1396
286
2011-02-26 23:24
KW4VA
10.140234
-17
0
FM18cr
0.02
N0UR
EN33
1380
297
• Best DX copying / spotting KW4VA WSPR beacon over the last 30 days
Information and Links
• Common Microcontrollers
– http://en.wikipedia.org/wiki/List_of_common_microcontrollers
• Microchip Technologies
– www.microchip.com
– Microcontroller chips, development kits and MPLAB IDE
• PIC
– http://en.wikipedia.org/wiki/PIC_microcontroller
• Atmel
– www.atmel.com
– Microcontroller chip, development kits and AVRStudio
• ATmega
– http://en.wikipedia.org/wiki/Atmel_AVR
• Arduino
– www.arduino.cc
– Open source hardware info, software tools, projects, kit vendors
• AVR Community
– http://www.avrfreaks.net/
– ATmega forums, discussions, information groups
Download