An Introduction to Designing Ham Radio Projects with PIC Microcontrollers George Zafiropoulos KJ6VU
Topics Ham radio applications Microcontroller basics Hardware design examples Implementing your design Software tools Software examples Project gallery
Ideas for Projects Using PIC Microcontrollers TR sequencer Memory keyer CW keyboard Station power controller Rotor controller Tone generator Test equipment controller Speaker / audio router Repeater controller Fox hunt tx controller Radio control Morse code decoder APRS encoder Frequency counter Battery monitor Audio meter
Hardware Options Design your own hardware Software Options Use existing prototype board Hardware platform Assembler C Basic
Topics Ham radio applications Microcontroller basics Hardware design examples Implementing your design Software tools Software examples Project gallery
Picking a Microcontroller Selection Criteria for Ham Radio Projects Cheap Easy to program (relatively) Serial interface (for control and configuration) Fast Non-volatile flash memory (program and data) 5V supply and I/O Wide variety of IO besides digital in/out A/D converter, SPI, UART, I2C, PWM (tone), etc DIP package Code examples Big eco-system RF immune Low noise generation
Microcontroller Suppliers
Devices for Hobby Projects Atmel AVR Basic Stamp Arduino Microchip PIC HamStack Chips Modules Boards
Lets Pick the PIC what s a PIC? Product of Microchip Technology PIC1640 originally developed by General Instrument's Microelectronics Division PIC = "Programmable Interface Controller PICs are low cost & widely available Large user base Low cost or free development tools In 2008 Microchip shipped its 6,000,000,000 th PIC processor
PIC 18Fxxxx Family
Processing Horsepower 1 MIP 16 MIPs < PIC Microcontroller
What s Inside a PIC 18Fxxxx CPU Chip?
Lets Use the 18F2620 CPU up to 10 MIPS performance (40 MHz) CPU up to 16 MIPS performance (64 MHz) C, Assembler, Basic compiler support 8 x 8 Single Cycle Hardware Multiply System Internal oscillator support 31 khz to 8 MHz Fail-Safe Clock Monitor allows safe shutdown if clock fails Watchdog Timer with separate RC oscillator Wide operating Voltage range; 2.0V to 5.5V nanowatt Power Managed Modes Run, Idle and Sleep modes Idle mode currents down to 5.8uA typical Sleep mode currents down to 0.1uA typical Analog Features 10-bit ADC, 10 channels, 100K samples/second Programmable Low Voltage Detection Module Programmable Brown-out Reset module Two Analog comparators with input multiplexing Peripherals Master Synchronous Serial Port supports SPI and I2C Master and Slave Mode EUSART module including LIN bus support Four Timer Modules Up to 2 PWM outputs
18F2620 18F4620 18F8722 All code compatible, just more pins 28 Pins 80 Pins 40 Pins
Topics Ham radio applications Microcontroller basics Hardware design examples Implementing your design Software tools Software examples Project gallery
Minimum Configuration Blinky PicKit2 Programmer Power Input
19 User Configurable I/O Pins PicKit2 Programmer 6 Analog Input Or Digital I/O Pins Power Input 13 Digital I/O Pins
Many Special Purpose I/O Pins PicKit2 Programmer Timers PWM 6 Analog Input Or Digital I/O Pins SPI / I2C Clock PWM Power Input UART SPI data out SPI Data In or I2C Data Interrupt
Howz That Work?
Minimum Configuration Blinky PicKit2 Programmer Power Input
Let s add some additional input / output devices Analog Inputs Digital Inputs Digital Outputs
Now lets add an RS-232 Interface RS-232 Interface
Topics Ham radio applications Microcontroller basics Hardware design examples Implementing your design Software tools Software examples Project gallery
Design Your Own Boards Low cost prototype PCB services Free design tools Prototype quality Drilled and plated Production quality Drilled, plated, solder mask, silkscreen Prototypes Minimum order 2 boards ~$120 and up for 2 Or get 3 boards 2.5 x 3.8 for $52 www.expresspcb.com www.pcbexpress.com www.pcb123.com
Free Schematic Editor
Free Layout Editor
Use an bare off the shelf Prototype Boards Examples from ME Labs Simple Prototype Boards Blank Boards Multi-purpose Prototype Boards
Off the Shelf Single Board Computers Arduino Uno HamStack Basic Stamp
CPU Comparison Arduino Arduino HamStack HamStack Parallax Parallax Processor Processor ATMega328 ATMega328 PIC PIC 18F46K22 18F4620 Basic Basic Stamp Stamp II II Vendor Speed Atmel 20 MHz Microchip 64 MHzPIC Microchip 20 MHz PIC Speed Instructions per second 2020,000,000 MHz 16,000,000 40 MHz 4,000 20 MHz RAM RAM 2,028 2,028 bytes bytes 4,096 bytes 25 25 bytes Flash Flash memory memory for for program program store store 32,000 32,000 64,000 2,048 Flash Flash memory memory for for data data storage storage 1024 1024 bytes bytes 1024 1024 bytes bytes None None Onboard Peripherals Onboard Peripherals 8 Bit 8 counter Bit counter / timer / timer 2 2 13 None None 16 bit 16 counter bit counter / timer / timer 1 1 34 None PWM PWM 6 6 5 Yes Yes 10 bit 10 A bit to A D to converter D converter 6 6 13 25 None Serial Serial UART UART 1 1 12 11 SPI SPI serial serial interface interface 1 1 12 None I2C I2C serial serial interface interface 1 1 12 None None Digital Digital IO pins IO pins 14 14 30 30 16 16 Total IO pins at any time 20 30 16 Total IO pins at any time 20 30 16 Form factor Board Board Chip Form Assembled Kit Assembled Kit/Assembled Assembled Kit Assembled CPU CPU board board / module $ 29.00 $ 29.00 $ 39.00 $ $ 49.00
HamStack CPU Board Upgrade to Newer CPUs 4620 46K22 46K80
Topics Ham radio applications Microcontroller basics Hardware design examples Implementing your design Software tools Software examples Project gallery
Software Development Flow Edit source code Use any ASCII text editor test.c Compile program Compile or assemble into executable file test.hex Download into CPU Use PicKit2 or similar programmer to transfer the.hex file into the program store flash memory in the PIC Run program It s alive!
Compilers Microchip MPLAB IDE & Assembler Text editor Assembler Debugger Free!
Microchip C18 Compiler Full-featured C compiler ANSI compliant Compatibility with object modules generated by the MPASM assembler Extensive library support PWM SPI I 2 C UART, USART string manipulation math libraries Free version available
Swordfish Basic Editor/Compiler Powerful and easy to use basic language String handling Relational operations Boolean Logic Operators Floating Point Math In line assembly Graphical LCD support Compact Flash USB in/out SPI I 2 C DS OneWire UART ASCII Lite version $FREE Full version $150
In-Circuit Programmer Downloads the Program Open the.hex file Hit the Write button
Topics Ham radio applications Microcontroller basics Hardware design examples Implementing your design Software tools Software examples Project gallery
Software Example Task: Flash the LED forever
All Programs Have a Common Control Program Structure Initialize Program Read Inputs Make Decisions Loop forever Write Outputs Subroutine Library
Blinky Written in Swordfish Basic ' ============================================================================ ' blinky.bas ' Blinking LED demo using Swordfish Basic ' ============================================================================ Device 18F2620 Clock = 10 ' Select device type ' Set clock frequency to 40 MHz CONFIG_START OSC = HSPLL CONFIG_END ' Set hardware configuration parameters ' Set 4x PLL on (10 MHz crystal * 4x = 40 MHz) TRISC.1 = 0 ' Set pin C1 connected to the status LED to be an output While true Low PORTC.1 DelayMS (200) High PORTC.1 DelayMS (200) Wend ' Set pin C1 low (0 volts) LED on ' Delay 200 ms ' Set pin C1 high (5 volts) LED off ' Delay 200 ms Loop forever
Blinky Written in Microchip C18 /* blinky.c - This is a simple program that blinks the status LED */ #include <p18cxxx.h> /* Use PIC18 processor family */ #pragma config WDT = OFF /* Turn off watchdog timer checking */ /************************************************************************/ void delay (void) /* Delay subroutine */ { long i; /* Declare variable i as a long integer */ for (i = 0; i < 1000; i++); /* Increment the counter */ } /************************************************************************/ /************************************************************************/ void main (void) { TRISC = 0; /* Set IO register C to output mode */ while (1) /* Loop forever */ LATCbits.LATC1 = 0; /* Turn on status LED */ delay (); /* Wait by calling the delay subroutine */ LATCbits.LATC1 = 1; /* Turn off status LED */ delay (); /* Wait by calling the delay subroutine */ } } /************************************************************************/
Software Example CW Key Key Tx Task: When a button is pressed Key my transmitter Send a CW message Continue while button pressed
CW Beacon Transmitter ' HamStack CW Beacon Device = 18F4620 Clock = 10 Include "hamstack.bas" ' Initialize relay_1_off relay_2_off led_off While true If mode_button = pressed Then led_on relay_2_on DelayMS (500) send_cw ("CQ CQ CQ DE KJ6VU K") DelayMS (500) relay_2_off DelayMS (2000) EndIf Wend
hamstack.bas Library Module hamstack '======================================= '=====[ Physical IO pin assignments ]= '======================================= Public Dim relay_1 As portb.3 Public Dim relay_2 As portb.2 '======================================= '=====[ Common Public Variables ]===== '======================================= Public Const on As Byte = 1 Public Const off As Byte = 0 Public Const yes As Byte = 1 Public Const no As Byte = 0 Public Const pressed As Byte = 0 '============================================================= '=====[ Send CW ]=========================================== '============================================================= Public Sub send_cw (ByVal cw_string As String) '----- VARIABLE DEFINITIONS --------------------------------------- Dim wpm As Byte ' CW speed in words per minute Dim cw_time As Word ' Calculated time value of a dit in ms. Dim cw_len As Byte ' Working variable, length of string Dim i As Byte ' Working variable Dim x As Byte ' Working variable Dim y As Byte ' Workign variable Dim cw_char As String(2) ' Holds the character being sent Dim cw_bits As String(15) ' Dit / Dah pattern being sent Dim cw_temp As String(2) ' Working variable '======================================= '=====[ Status LED Control ]========== '======================================= Public Sub led_on () High (portc.0) End Sub '------------------------------------------ ---------------------------------- Public Sub led_off () Low (portc.0) End Sub '======================================= '=====[ Relay control ]=============== '======================================= Public Sub relay_1_on () High (relay_1) End Sub '--------------------------------------- Public Sub relay_1_off () Low (relay_1) End Sub '----- INITIALIZE VARIABLES ---------------------------------------- wpm = 13 ' CW speed in words per minute '----- START MAIN PROGRAM CODE ------------------------------------- cw_time = 1200 / wpm ' Calculate the length of a dit cw_len = Length(cw_string) ' Determine the length of the string '----- START MASTER CONTROL LOOP ------------------------------------ master_loop:' Outer loop will process the whole string. For i = 0 To cw_len-1 ' Go through the string cw_char = Mid(cw_string,i,1) ' Grab the current char Select cw_char Case "A" : cw_bits = ".-" Case "B" : cw_bits = "-..." Case "C" : cw_bits = "-.-." Case "D" : cw_bits = "-.." Case "E" : cw_bits = "." Case "F" : cw_bits = "..-." Case "G" : cw_bits = "--." Case "H" : cw_bits = "..." Case "I" : cw_bits = ".." Case "J" : cw_bits = ".---" Case "K" : cw_bits = "-.-" Case "L" : cw_bits = ".-.."
Topics Ham radio applications Microcontroller basics Hardware design examples Implementing your design Software tools Software examples Project gallery
HamStack CPU
HamStack Relay Board
HamStack Solder-less Breadboard
HamStack Prototype Board
Arduino Compatible
Multi-Port, Multi-Processor Repeater Control System
Summary Easier then you may think Many good tools and examples Pick a project and jump in For more information ExpressPCB www.expresspcb.com Microchip www.microchip.com Swordfish Basic www.sfcompiler.co.uk Sierra Radio www.sierraradio.net HamStack www.hamstack.com