Transcript Micro-controllers
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 • 24x external interrupts • On-chip debugging through JTAG AVR program cable • 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
Arithmetic
COM Rd NEG Rd CP Rd, Rr CPC Rd, Rr CPI Rd, K8 SWAP Rd LSR Rd ROR Rd ASR Rd INC Rd DEC Rd AND Rd, Rr ANDI Rd, K8 OR Rd, Rr ORI Rd, K8 EOR Rd, Rr 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
Transfer
STS K16, Rr ST X, Rr ST -X, Rr ST X+, Rr PUSH Rr POP Rr STD Y+K6, Rr ST -Y, Rr ST Y+, 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+ STD Z+K6, Rr ST -Z, Rr ST Z+, Rr LPM LPM Rd, Z LPM Rd, Z+ ELPM ELPM Rd, Z ELPM Rd, Z+
Jump
RJMP K12 IJMP EIJMP JMP K22
Branch
CPSE Rd, Rr SBRC Rr, b SBRS Rr, b
Call
RCALL K12 ICALL EICALL CALL K22 SBIC A, b SBIS A, b BRBC s, K7 BRBS s, K7 RET RETI LDD Rd, Z+K6 LD Rd, -Z LD 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
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 21 st 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
Keyer
CWlink Architecture
Rig Serial Output Arduino Board Serial – Wireless Link Serial Input
Cwlink Keyer State Diagram
Power Up Cal Failed (loop) Init Success Init Cal Cal Success Mode Switch Change Record 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 DDS Control DDS 80 Return Loss Bridge RF To Bridge Antenna • 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 low level 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 • 5 th 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
N8TWX W3HH KC8NN WA9FIO WA5ETV W5OLF
Grid
EN83 EL89 EN66 EN43 EM15 DM78
Km
770 1149 1167 1254 1741 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
2011-02-26 02:14 2011-03-08 00:38 2011-02-15 00:00 2011-02-11 17:12 2011-02-27 05:38 2011-03-08 03:02 2011-02-19 04:42 2011-02-19 03:24 2011-02-11 07:42 2011-02-27 17:36 2011-02-13 23:54 2011-03-07 15:08 2011-02-18 07:54 2011-02-19 02:36 2011-02-10 07:56 2011-02-16 09:36 2011-03-02 03:14 2011-02-10 04:12 2011-02-22 14:12 2011-02-26 23:24
Beacon
KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA KW4VA
Freq
10.140268
14.097096
14.097127
14.097169
7.040176
14.097189
10.140253
10.140257
7.040164
21.096018
14.097065
14.097176
7.040186
10.140253
7.040155
7.040167
7.040183
7.040146
14.097175
10.140234
-28 -26 -29 -24 -29 -25 -17 -17
SN
-21 -26 -22 -27 -27 -26 -26 -26 -27 -25 -24 -31
Grid
FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr FM18cr 0 0 0 0 -1 0 0 0
DT
0 0 -1 -1 0 -1 0 0 0 -1 0 0 0.02
0.02
0.02
0.02
0.02
0.02
0.02
0.02
Pwr
0.02
0.02
0.02
0.02
0.02
0.02
0.02
0.02
0.02
0.02
0.02
0.02
Reporter CT2IWW WB2FXO WA7KGX VE6OG KE7LEU KI7AB W1CDO W5OLF W0DHB KN5X N5VP K5XL KE7A AD4PT K5ARH KC8JNV N0SF K0GUN KC0BMF N0UR Rgrid
IN51wf CM94su CN85no DO33 DN41 DM65qg DM73 DM78hb DN70kc EM10dm EL29jj EM12kp EM12kx EM12kx EM30xe EN11xe EM29mh EM36cu EN31be EN33 • Best DX copying / spotting KW4VA WSPR beacon over the last 30 days
1852 1852 1612 1576 1482 1419 1396 1380 Km 5778 3789 3742 3127 2827 2578 2507 2396 2344 2032 1906 1868
256 256 238 286 278 267 286 297
Az
64 277 297 313 287 270 265 277 282 249 242 255
Information and Links
• Common Microcontrollers – – • PIC – – – – – http://en.wikipedia.org/wiki/List_of_common_microcontrollers • Microchip Technologies www.microchip.com
– Microcontroller chips, development kits and MPLAB IDE 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