an introduction to designing ham radio projects with pic ... · pdf filean introduction to...

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

Upload: doantu

Post on 16-Mar-2018

228 views

Category:

Documents


4 download

TRANSCRIPT

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

prototype boardHardware platform

Software Options

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

Basic StampArduino

Atmel AVR

Microchip

PIC

Chips Modules Boards

HamStack

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

PIC

18Fxxxx

Family

Processing Horsepower

PIC

Microcontroller

1 MIP 16 MIPs

<

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

40 Pins

80 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

Power Input

6 Analog Input

Or

Digital I/O Pins

13 Digital I/O Pins

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

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 BoardsExamples from ME Labs

Blank Boards

Simple Prototype Boards

Multi-purpose Prototype

Boards

Off the Shelf “Single Board Computers”

Arduino Uno HamStack Basic Stamp

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

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

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 !

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

• I2C

• UART, USART

• string manipulation

• math libraries

Free version available

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

In-Circuit Programmer Downloads the ProgramOpen 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

Write Outputs

Subroutine Library

Loop forever

“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

“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

Task:

When a button is pressed…

Key my transmitter

Send a CW message

Continue while button pressed

Key Tx

CW Key

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

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