59
An Introduction toDesigning Ham Radio Projects with PIC Microcontrollers George Zafiropoulos KJ6VU

An Introduction to Designing Ham Radio Projects with PIC

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: An Introduction to Designing Ham Radio Projects with PIC

An Introduction to…

Designing Ham Radio Projects

with PIC Microcontrollers

George Zafiropoulos

KJ6VU

Page 2: An Introduction to Designing Ham Radio Projects with PIC

Topics

• Ham radio applications

• Microcontroller basics

• Hardware design examples

• Implementing your design

• Software tools

• Software examples

• Project gallery

Page 3: An Introduction to Designing Ham Radio Projects with PIC

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

Page 4: An Introduction to Designing Ham Radio Projects with PIC

Hardware Options

Design your own hardwareUse existing

prototype boardHardware platform

Software Options

Assembler

C

Basic

Page 5: An Introduction to Designing Ham Radio Projects with PIC

Topics

• Ham radio applications

• Microcontroller basics

• Hardware design examples

• Implementing your design

• Software tools

• Software examples

• Project gallery

Page 6: An Introduction to Designing Ham Radio Projects with PIC

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

Page 7: An Introduction to Designing Ham Radio Projects with PIC

Microcontroller Suppliers

Page 8: An Introduction to Designing Ham Radio Projects with PIC

Devices for Hobby Projects

Basic StampArduino

Atmel AVR

Microchip

PIC

Chips Modules Boards

HamStack

Page 9: An Introduction to Designing Ham Radio Projects with PIC

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,000th PIC processor

Page 10: An Introduction to Designing Ham Radio Projects with PIC

PIC

18Fxxxx

Family

Page 11: An Introduction to Designing Ham Radio Projects with PIC

Processing Horsepower

PIC

Microcontroller

1 MIP 16 MIPs

<

Page 12: An Introduction to Designing Ham Radio Projects with PIC

What’s Inside a PIC 18Fxxxx CPU Chip?

Page 13: An Introduction to Designing Ham Radio Projects with PIC
Page 14: An Introduction to Designing Ham Radio Projects with PIC
Page 15: An Introduction to Designing Ham Radio Projects with PIC

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

Page 16: An Introduction to Designing Ham Radio Projects with PIC

18F2620 – 18F4620 – 18F8722

All code compatible, just more pins…

28 Pins

40 Pins

80 Pins

Page 17: An Introduction to Designing Ham Radio Projects with PIC

Topics

• Ham radio applications

• Microcontroller basics

• Hardware design examples

• Implementing your design

• Software tools

• Software examples

• Project gallery

Page 18: An Introduction to Designing Ham Radio Projects with PIC

Minimum Configuration – “Blinky”

PicKit2 Programmer

Power Input

Page 19: An Introduction to Designing Ham Radio Projects with PIC

19 User Configurable I/O Pins

PicKit2 Programmer

Power Input

6 Analog Input

Or

Digital I/O Pins

13 Digital I/O Pins

Page 20: An Introduction to Designing Ham Radio Projects with PIC

Many Special Purpose I/O Pins

PicKit2 Programmer

Power Input

6 Analog Input

Or

Digital I/O Pins

Timers

PWM

SPI / I2C

Clock SPI Data In

or I2C Data

SPI data out

UART

Interrupt

PWM

Page 21: An Introduction to Designing Ham Radio Projects with PIC

Howz That Work?

Page 22: An Introduction to Designing Ham Radio Projects with PIC

Minimum Configuration – “Blinky”

PicKit2 Programmer

Power Input

Page 23: An Introduction to Designing Ham Radio Projects with PIC

Let’s add some additional input / output devices

Analog

Inputs

Digital

Inputs

Digital

Outputs

Page 24: An Introduction to Designing Ham Radio Projects with PIC

Now lets add an RS-232 Interface

RS-232

Interface

Page 25: An Introduction to Designing Ham Radio Projects with PIC

Topics

• Ham radio applications

• Microcontroller basics

• Hardware design examples

• Implementing your design

• Software tools

• Software examples

• Project gallery

Page 26: An Introduction to Designing Ham Radio Projects with PIC

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

Page 27: An Introduction to Designing Ham Radio Projects with PIC

Free Schematic Editor

Page 28: An Introduction to Designing Ham Radio Projects with PIC

Free Layout Editor

Page 29: An Introduction to Designing Ham Radio Projects with PIC

Use an bare “off the shelf”

Prototype BoardsExamples from ME Labs

Blank Boards

Simple Prototype Boards

Multi-purpose Prototype

Boards

Page 30: An Introduction to Designing Ham Radio Projects with PIC

Off the Shelf “Single Board Computers”

Arduino Uno HamStack Basic Stamp

Page 31: An Introduction to Designing Ham Radio Projects with PIC

CPU ComparisonArduino HamStack Parallax

Processor ATMega328 PIC 18F46K22 Basic Stamp IISpeed 20 MHz 64 MHz 20 MHzInstructions per second 20,000,000 16,000,000 4,000RAM 2,028 bytes 4,096 bytes 25 bytesFlash memory for program store 32,000 64,000 2,048Flash memory for data storage 1024 bytes 1024 bytes None

Onboard Peripherals8 Bit counter / timer 2 3 None16 bit counter / timer 1 4 NonePWM 6 5 Yes10 bit A to D converter 6 25 NoneSerial UART 1 2 1SPI serial interface 1 2 NoneI2C serial interface 1 2 NoneDigital IO pins 14 30 16Total IO pins at any time 20 30 16

Form Assembled Kit Assembled

CPU board $ 29.00 $ 39.00 $ 49.00

Arduino HamStack ParallaxProcessor ATMega328 PIC 18F4620 Basic Stamp IIVendor Atmel Microchip PIC Microchip PIC

Speed 20 MHz 40 MHz 20 MHzRAM 2,028 bytes 4,096 bytes 25 bytes

Flash memory for program store 32,000 64,000 2,048

Flash memory for data storage 1024 bytes 1024 bytes None

Onboard Peripherals

8 Bit counter / timer 2 1 None

16 bit counter / timer 1 3 NonePWM 6 5 Yes

10 bit A to D converter 6 13 NoneSerial UART 1 1 1SPI serial interface 1 1 None

I2C serial interface 1 1 NoneDigital IO pins 14 30 16

Total IO pins at any time 20 30 16Form factor Board Board ChipKit/Assembled Assembled Kit Assembled

CPU board / module $ 29.00 $ 39.00 $ 49.00

Page 32: An Introduction to Designing Ham Radio Projects with PIC

HamStack CPU Board

Upgrade to Newer CPUs

4620…46K22…46K80…

Page 33: An Introduction to Designing Ham Radio Projects with PIC

Topics

• Ham radio applications

• Microcontroller basics

• Hardware design examples

• Implementing your design

• Software tools

• Software examples

• Project gallery

Page 34: An Introduction to Designing Ham Radio Projects with PIC

Software Development Flow

Edit source code

Compile

program

Download into

CPU

Run program

Use any ASCII text editortest.c

Compile or assemble into executable filetest.hex

Use PicKit2 or similar programmer to

transfer the .hex file into the program store

flash memory in the PIC

It’s alive !

Page 35: An Introduction to Designing Ham Radio Projects with PIC

Compilers – Microchip MPLAB IDE & Assembler

Text editor

Assembler

Debugger

Free !

Page 36: An Introduction to Designing Ham Radio Projects with PIC

Microchip C18 Compiler Full-featured C compiler

ANSI compliant

Compatibility with object

modules generated by the

MPASM assembler

Extensive library support

• PWM

• SPI

• I2C

• UART, USART

• string manipulation

• math libraries

Free version available

Page 37: An Introduction to Designing Ham Radio Projects with PIC

Swordfish Basic Editor/CompilerPowerful 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

• I2C

• DS OneWire

• UART ASCII

Lite version $FREE

Full version $150

Page 38: An Introduction to Designing Ham Radio Projects with PIC

In-Circuit Programmer Downloads the ProgramOpen the .hex file Hit the “Write” button

Page 39: An Introduction to Designing Ham Radio Projects with PIC

Topics

• Ham radio applications

• Microcontroller basics

• Hardware design examples

• Implementing your design

• Software tools

• Software examples

• Project gallery

Page 40: An Introduction to Designing Ham Radio Projects with PIC

Software Example

Task: Flash the LED forever

Page 41: An Introduction to Designing Ham Radio Projects with PIC

All Programs Have a Common

Control Program Structure

Initialize Program

Read Inputs

Make Decisions

Write Outputs

Subroutine Library

Loop forever

Page 42: An Introduction to Designing Ham Radio Projects with PIC

“Blinky” Written in Swordfish Basic

' ============================================================================

' blinky.bas

' Blinking LED demo using Swordfish Basic

' ============================================================================

Device 18F2620 ' Select device type

Clock = 10 ' Set clock frequency to 40 MHz

CONFIG_START ' Set hardware configuration parameters

OSC = HSPLL ' Set 4x PLL on (10 MHz crystal * 4x = 40 MHz)

CONFIG_END

TRISC.1 = 0 ' Set pin C1 connected to the status LED to be an output

While true

Low PORTC.1 ' Set pin C1 low (0 volts) LED on

DelayMS (200) ' Delay 200 ms

High PORTC.1 ' Set pin C1 high (5 volts) LED off

DelayMS (200) ' Delay 200 ms

Wend ‘ Loop forever

Page 43: An Introduction to Designing Ham Radio Projects with PIC

“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 */

}

}

/************************************************************************/

Page 44: An Introduction to Designing Ham Radio Projects with PIC

Software Example

Task:

When a button is pressed…

Key my transmitter

Send a CW message

Continue while button pressed

Key Tx

CW Key

Page 45: An Introduction to Designing Ham Radio Projects with PIC

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

Page 46: An Introduction to Designing Ham Radio Projects with PIC

hamstack.bas LibraryModule 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

'=======================================

'=====[ 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

'=============================================================

'=====[ 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

'----- 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 = ".-.."

Page 47: An Introduction to Designing Ham Radio Projects with PIC

Topics

• Ham radio applications

• Microcontroller basics

• Hardware design examples

• Implementing your design

• Software tools

• Software examples

• Project gallery

Page 48: An Introduction to Designing Ham Radio Projects with PIC

HamStack CPU

Page 49: An Introduction to Designing Ham Radio Projects with PIC

HamStack Relay Board

Page 50: An Introduction to Designing Ham Radio Projects with PIC

HamStack Solder-less Breadboard

Page 51: An Introduction to Designing Ham Radio Projects with PIC

HamStack Prototype Board

Page 52: An Introduction to Designing Ham Radio Projects with PIC

Arduino Compatible

Page 53: An Introduction to Designing Ham Radio Projects with PIC
Page 54: An Introduction to Designing Ham Radio Projects with PIC
Page 55: An Introduction to Designing Ham Radio Projects with PIC
Page 56: An Introduction to Designing Ham Radio Projects with PIC
Page 57: An Introduction to Designing Ham Radio Projects with PIC

Multi-Port, Multi-Processor Repeater Control System

Page 58: An Introduction to Designing Ham Radio Projects with PIC
Page 59: An Introduction to Designing Ham Radio Projects with PIC

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