Microcontrollers and Amateur Radio – a Club Project Dave Green VE3TLY QCWA Nov. 18 2008 Dave Green VE3TLY 1 Acknowledgements • Mike Kelly, VE3FFK • David Conn, VE3KL QCWA Nov. 18 2008 Dave Green VE3TLY 2 Recent Club Projects • 2007: ‘Smart’ Battery charger kit (Mike Kelly VE3FFK) • 2008: Microcontroller (VE3KL, VE3FFK, VE3TLY) – Pervasive technology, – ‘New’ technology for many of us. QCWA Nov. 18 2008 Dave Green VE3TLY 3 My Reservations • Complex technology: – – – – – – – Digital hardware, Digital systems, Processor architectures, Programming concepts, Programming languages, Software development tools, Debugging tools. • Club members with diverse technical backgrounds. • Resolved by selection of appropriate technology. QCWA Nov. 18 2008 Dave Green VE3TLY 4 Talk Overview • Concepts: – Processors, Microprocessors, Microcomputers and Microcontrollers, • • • • Overview of PICAXE Microcontroller, PICAXE vs. PIC, The OARC Project, Examples of amateur radio applications of microcontrollers. QCWA Nov. 18 2008 Dave Green VE3TLY 5 Concept of a Modern Digital Stored Program Computer Instr0 Control Unit Instr1 Instr2 - Processing Element InstrK System Memory (Program and Data) QCWA Nov. 18 2008 Dave Green VE3TLY 6 Microprocessor Register Array Arithmetic Logic Unit (ALU) Control Unit Central Processing Unit (CPU) Data Bus Address Bus Control Bus System Memory QCWA Nov. 18 2008 Dave Green VE3TLY 7 Microcomputer • Board level microcomputer • Single chip microcomputer Microprocessor Bus Memory QCWA Nov. 18 2008 Input/Output Dave Green VE3TLY 8 Microcontroller • A single chip microcomputer optimized for control applications, • Rich Input/Output connectivity to access: – Switches, – Sensors, – Motors, – Displays, – Etc. QCWA Nov. 18 2008 Dave Green VE3TLY 9 The PICAXE used by the OARC QCWA Nov. 18 2008 Dave Green VE3TLY 10 Examples of Microcontroller Applications • Automotive: – – – – – Engine management Automatic transmission Anti-lock braking Cruise control Dashboard Instrumentation • Kitchen appliances, • Power tools, • Amateur radio gear: – – – – Transceivers, Keyers, Autotuners, Instrumentation, antenna analyzers etc. QCWA Nov. 18 2008 Dave Green VE3TLY 11 PIC16F886 Microcontroller • PIC: Programmable Intelligent Controller • Microchip Technology Inc., (AZ) – www.microchip.com • 8-bit CMOS processor. • 35 instructions – single cycle execution (RISC). • Non-volatile memory: – Flash program memory (8K x 14) – EEPROM data memory (256 x 8). • Volatile memory – RAM data memory (368 x 8). QCWA Nov. 18 2008 Dave Green VE3TLY 12 Programming a PIC C Source File Assembly Language File C Compiler/Linker Assembler/Linker Device Programmer QCWA Nov. 18 2008 Dave Green VE3TLY 13 What is a PICAXE??? ‘PICAXE Command Interpreter’ Program PIC Microcontroller aka ‘PICAXE’ QCWA Nov. 18 2008 Dave Green VE3TLY 14 Programming the ‘PICAXE’ Flash Program Memory User program: PICAXE commands User Program PICAXE ‘Compiler’ PICAXE Command Interpreter Serial Download No Device Programmer required. QCWA Nov. 18 2008 Dave Green VE3TLY ‘PICAXE’ 15 Over 120 PICAXE Commands • Digital input/output • Analog input (10-bit ADC) • Pulse width modulation • Pulse counting • Looping and branching operations • Subroutines • Off-chip expansion with serial buses • Low power (Sleep) mode… QCWA Nov. 18 2008 Dave Green VE3TLY 16 PICAXE Programming • Easy to learn ‘BASIC-like’ language top: QCWA Nov. 18 2008 high 2 ;set pin 2 high pause 500 ;delay ½ sec low 2 ;set pin 2 low pause 1000 ;delay 1 sec goto top ;loop Dave Green VE3TLY 17 Interfacing a PICAXE… QCWA Nov. 18 2008 Dave Green VE3TLY 18 Interfacing with Digital Input/Output high 7 ;enable LED if pin 3 = 0 then… high 1 ;enable output QCWA Nov. 18 2008 Dave Green VE3TLY 19 Driving an Opto-isolator high 7 ;toggle Pin 7 pause dit_length low 7 pause char_space High 7 Pause dah_length Low 7 QCWA Nov. 18 2008 Dave Green VE3TLY 20 Capturing Analog Voltage readadc10 0, variable0 QCWA Nov. 18 2008 Dave Green VE3TLY 21 Iambic Keyer with Speed Control QCWA Nov. 18 2008 Dave Green VE3TLY 22 Controlling Motor Speed using Pulse Width Modulation Pulse width Modulator • Single • Half bridge • Full bridge • Duty cycle control To Motor Driver Counter input From Shaft Encoder count 4, 100, w1 QCWA Nov. 18 2008 Dave Green VE3TLY 23 Serial Input/Output Serial transfers to LCD serout 1,N9600_8,(“Hello") Transfers to PC serial port serin 0,T2400_8,b1,b2,b3 serout 0,T2400_8,(10,13,"> ") QCWA Nov. 18 2008 Dave Green VE3TLY 24 Keyboard Interface • Uses 2-wire interface. • Reads keystrokes. • Control Keyboard LEDs. QCWA Nov. 18 2008 Dave Green VE3TLY 25 i2c and SPI Serial Bus • hi2csetup • hi2cin • hi2cout • EPROM • Static RAM • Floating point co-processor • Real time clock… QCWA Nov. 18 2008 Dave Green VE3TLY 26 PIC vs. PICAXE PIC16F886 PICAXE-28X1 Ease of Programming Complex or not so complex (C, BA$IC, or Assembly) Simple (BASIC) Performance (4 MHz Clock) 1 ms/instruction ~330 ms/command (high/low commands) Cost (chip) Oct. 25, $ Can $3.72 $12.60 Free Software • MPLAB IDE + Assembler • HI-TECH C PRO ‘Lite’ PICAXE Program Editor Device Programmer Google! N/A QCWA Nov. 18 2008 Dave Green VE3TLY 27 PICAXE • Revolution Education Ltd. (UK) – www.picaxe.co.uk – Education market (secondary and higher) – Electronics hobbyists • Products available in Canada from HVW Technologies – www.hvwtech.com – ‘AXE-28 Starter Kit C$58.74 (Oct. 29) QCWA Nov. 18 2008 Dave Green VE3TLY 28 PICAXE-28 Starter Kit QCWA Nov. 18 2008 Dave Green VE3TLY 29 PICAXE Programming Editor • A free download! (www.picaxe.co.uk) • Program development tool. • Complete documentation set is included. • Program ‘compiler’ and downloader. • Simulator. • Debugging tools. QCWA Nov. 18 2008 Dave Green VE3TLY 30 The Ottawa Amateur Radio Club Project • A hands-on introduction to microcontrollers. • Algonquin College lab facilities. • 6 Saturday morning sessions: – Kit assembly – Programming tools – Program development • Short presentations: – – – – Programming tools Manuals and help literature Debugging Binary number representation… QCWA Nov. 18 2008 Dave Green VE3TLY 31 QCWA Nov. 18 2008 Dave Green VE3TLY 32 QCWA Nov. 18 2008 Dave Green VE3TLY 33 QCWA Nov. 18 2008 Dave Green VE3TLY 34 Exercises • • • • • Blinking LEDs. Morse code generator (LED). Subroutines. CW speed control via ADC input. CW Keyer: coupled via Opto-isolater to a Transceiver. QCWA Nov. 18 2008 Dave Green VE3TLY 35 Results • • • • QCWA Nov. 18 2008 25 participants. 17 on average over each of 6 sessions. Lots of enthusiasm for the project. Want to do more… Dave Green VE3TLY 36 Some Examples Microcontroller Applications for Amateur Radio… QCWA Nov. 18 2008 Dave Green VE3TLY 37 PIC-based Rechargeable Battery Conditioner • Bertrand VE2ZAZ, QEX Sept./Oct. 2008 ADC In PWM Out Rechargeable battery pack QCWA Nov. 18 2008 PIC To PC for Setup and Data Logging Charge/Discharge Circuitry Dave Green VE3TLY 38 Examples of Commercial PIC-based Amateur Radio Gear QCWA Nov. 18 2008 Dave Green VE3TLY 39 MFJ-259B SWR Analyzer QCWA Nov. 18 2008 Dave Green VE3TLY 40 LDG Z-100 autotuner QCWA Nov. 18 2008 Dave Green VE3TLY 41 Examples of PIC-based Amateur Radio Projects (via Google) • • • • • • • • • Frequency counter Capacitance meter Digital wattmeter Microwattmeter Morse code speedometers, keyers, readers CW/BPSK Beacon transmitter Fox hunting transceiver controller “PeakPack” Packet radio monitoring tool NUE-PSK standalone PSK modem QCWA Nov. 18 2008 Dave Green VE3TLY 42 M3 Electronix Semiconductor Analyzer Kit QCWA Nov. 18 2008 Dave Green VE3TLY 43 Byonics TinyTrak3 APRS/GPS Position Encoder Kit QCWA Nov. 18 2008 Dave Green VE3TLY 44 How to Start? • • • • • Check out the literature. Decide between a PIC and a PICAXE. Order the hardware. Download the free development tools. Have fun! QCWA Nov. 18 2008 Dave Green VE3TLY 45 Resources • PIC – Manufacturer • www.microchip.com – Excellent references: • http://robotag.carleton.ca/resources/technical/pic_introduction.shtml • www.voti.nl/swp/n_index.html • PICAXE – PICAXE developer – Canadian supplier – Discussion forum www.picaxe.co.uk www.hvwtech.com www.picaxeforum.co.uk • Google! QCWA Nov. 18 2008 Dave Green VE3TLY 46 Questions? QCWA Nov. 18 2008 Dave Green VE3TLY 47 Additional Material QCWA Nov. 18 2008 Dave Green VE3TLY 48 Performance Measurements Using Bit Flipping top: out1 high 1 low 1 high 1 command to be measured low1 goto top QCWA Nov. 18 2008 Dave Green VE3TLY 49 PICAXE Performance Measurements Using ‘Bit flipping’ Most PIC instructions execute in 1 instruction cycle (4 clock periods) or 1 ms at 4 MHz clock. Measured PICAXE output pin maximum toggle rate (high/low commands) Setfreq m8 ;8 MHz clk high 2 ; toggle out2 low 2 high 2 • 650 ms or 1.5 kHz (4 MHz clock) low 2 • 320 ms or 3.125 kHz (8 MHz clock) high 2 Measured PICAXE high/low command execution time: low 2 … • 330 ms (4 MHz clock) • 160 ms (8 MHz clock) QCWA Nov. 18 2008 Dave Green VE3TLY 50 PIC16F886 © 2008 Microchip Technology Inc. QCWA Nov. 18 2008 Dave Green VE3TLY 51