microcontrollers by andy zwirko – k1ra tom zeltwanger – kg3v eric nystrom – w4eon

Post on 24-Dec-2015

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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)

• 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 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

What is in a Microcontroller?

Where To Use a Microcontroller?

• We need to flash an LED or light 3 times• Manually you would have to push button 3 times

• 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 Use a Microcontroller?

Where To Find Microcontrollers?

• Microcontroller are found everywhere!• uC’s are considered embedded systems

Microcontrollers in Ham Radio

• Early day (1970’s/80’s)– Intel 8048– Intel 8051– Zilog Z8– Motorola 68HC05

Popular Microcontrollers

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)

• 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 Specs

Microchip PIC 16F628 Pin Out

• PIC pins and associated functions• Some are dual purpose

C Source File

C Compiler/Linker

Device Programmer

AssemblyLanguage File

Assembler/Linker

Programming Languages for the PIC

PIC Instruction Set

W – The W register (or accumulator) is used as temp storage for many instructionsf – “f” represents a user defined variable or system memory locationk – “k” represents a literal number or a defined constantd – 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)

• MPLAB Integrated Development Environment (IDE)• Assembly for free, C compilers cost $$$

Programming the PIC (S/W)

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

• 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• Simple programming (LPT port, 4 resistors & AVRDUDE)• 1.8-5.5 VDC / 0.5uA – 3.6mA

Atmel AVR ATmega168 Specs

AVR program cable

Atmel AVR ATmega168 Pin Out

• AVR pins and associated functions• Some are dual purpose

ATMega168 Instruction SetArithmeticADD Rd, RrADC Rd, Rr

ADIW Rd+1:Rd, K6

SUB Rd, RrSUBI Rd, K8SBC Rd, RrSBCI Rd, K8

SBIW Rd+1:Rd, K6

INC RdDEC Rd

AND Rd, RrANDI Rd, K8OR Rd, RrORI Rd, K8EOR Rd, Rr

Bit & OtherBSET sBCLR sSBI A, bCBI A, b

BST Rd, bBLD Rd, b

NOPBREAKSLEEPWDR

TransferMOV Rd, Rr

MOVW Rd+1:Rd, Rr+1:Rr

IN Rd, AOUT A, Rr

PUSH RrPOP Rr

LDI Rd, K8LDS Rd, K16

LD Rd, XLD Rd, -XLD Rd, X+

LDD Rd, Y+K6LD Rd, -YLD Rd, Y+

LDD Rd, Z+K6LD Rd, -ZLD Rd, Z+

JumpRJMP K12

IJMPEIJMP

JMP K22

BranchCPSE Rd, Rr

SBRC Rr, bSBRS Rr, b

SBIC A, bSBIS A, b

BRBC s, K7BRBS s, K7

CallRCALL K12

ICALLEICALL

CALL K22

RETRETI

TransferSTS K16, Rr

ST X, RrST -X, RrST X+, Rr

STD Y+K6, RrST -Y, RrST Y+, Rr

STD Z+K6, RrST -Z, RrST Z+, Rr

LPMLPM Rd, Z

LPM Rd, Z+ELPM

ELPM Rd, ZELPM Rd, Z+

SPM

ArithmeticCOM RdNEG Rd

CP Rd, RrCPC Rd, RrCPI Rd, K8SWAP Rd

LSR RdROR RdASR Rd

MUL Rd, RrMULS Rd, Rr

MULSU Rd, RrFMUL Rd, Rr

FMULS Rd, RrFMULSU Rd, Rr

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 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

CWlinkAn embedded CW Project

byTom Zeltwanger

KG3V

Based on the Arduino Board

• 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)

CWlink Objectives

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

Keyer

Serial Output

ArduinoBoard

Serial Input

Rig

Serial – Wireless

Link

Init

Cal

Record

Playback

Power Up

Init Success

Cal Success

Mode Switch Change

5 Sec Timeout

Mode Switch Change

Cal Failed (loop)

Cwlink Keyer State Diagram

PIC, DDS & Return Loss BridgeAn Antenna Measurement Project

byEric 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

JAVA Program forPlotting and

AnalysisReturn Loss BridgePICC 16F1827

DDS 80

Serial Link

DDS Control

Bridge Voltage

RF To Bridge

Antenna

In CircuitProgrammer

ProgrammingControl

• 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 6mBeacon Board Project

byAndy 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

• 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 HoursCall 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 DXDate / 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

top related