introduction to microcontroller apps for amateur radio...
TRANSCRIPT
Introduction to Microcontroller Apps
for Amateur Radio Projects
Using the HamStack Platform
www.sierraradio.net
www.hamstack.com
Topics
• Introduction
• Hardware options
• Software development
• HamStack project examples
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
Frequent Question That We Get…
I have a project in mind, what should I use?
PIC?
Arduino?
Basic Stamp?
C Language?
Assembly?
Basic?
Embedded Linux?
Scratch-Built code?
Board?
Chip?
Module?
Our Answer…
• Microchip PIC 18F
• Max flash (64k) & RAM (4k)
• SPI, I2C, UART, PWM, A/D
• 30 IO pins
• 40 MHz to 64 MHz
• Arduino compatible board layout
• Built in voltage regulator and RS232
• Uses Microchip PicKit programmers
• Free C compiler
• Free Basic language compiler
The HamStack Platform
Topics
• Introduction
• Hardware options
• Software development
• HamStack project examples
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
PIC
18Fxxxx
Family
Processing Horsepower
PIC
Microcontroller
1 MIP 16 MIPs
<
Devices for Hobby Projects
Basic StampArduino
Atmel AVR
Microchip
PIC
Chips Modules Boards
HamStack
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
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
Minimum Configuration
PicKit2 Programmer
Power Input
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
Let’s Add Some Additional Input / Output Devices
Analog
Inputs
Digital
Inputs
Digital
Outputs
Now Lets Add an RS-232 Interface
RS-232
Interface
• Microchip PIC 18F
• Max flash (64k) & RAM (4k)
• SPI, I2C, UART, PWM, A/D
• 30 IO pins
• 40 MHz to 64 MHz
• Arduino compatible board layout
• Built in voltage regulator and RS232
• Uses Microchip PicKit programmers
• Free C compiler
• Free Basic language compiler
The HamStack Platform
Arduino
Compatability
Arduino UnoHamStack
RS232 Rx -
RS232 Tx -
RE2 Digital IO -
RA4 Digital IO / Mode button -
RC1 Digital IO / PWM 2 -
RC2 Digital IO / PWM 1 -
Status LED -
Programming pin (data) -
Programming pin (clock) -
RB4 Digital IO -
RB3 Digital IO -
RB2 Digital IO -
RB1 Digital IO -
RB0 Digital IO -
Reset Reset
3.3v 3.3v
5v 5v
Ground Ground
Ground Ground
External input voltage External input voltage
Bias (2.5v not supplied by CPU board) Aref
Ground Ground
RC3 Digital IO / SPI CK / I2C Clock (13) Digital IO / SPI CK / LED
RC5 Digital IO / SPI DO (12) Digital IO / SPI DO
RC4 Digital IO / SPI DI / I2C Data (11) Digital IO / PWM / SPI DI
RA5 Digital IO / SPI SS / (10) Digital IO / PWM / SPI SS
RD7 Digital IO / UART 2 Rx (9) Digital IO / PWM
RD6 Digital IO / UART 2 Tx (8) Digital IO
RA0 Digital IO / AN0 analog in 0 Analog in 0
RA1 Digital IO / AN1 analog in 1 Analog in 1
RA2 Digital IO / AN2 analog in 2 Analog in 2
RA3 Digital IO / AN3 analog in 3 Analog in 3
RE0 Digital IO / AN4 analog in 4 Analog in 4 / I2C Data
RE1 Digital IO / AN5 analog in 5 Analog in 5 / I2C Clock
RD5 Digital IO (7) Digital IO
RD4 Digital IO (6) Digital IO / PWM
RD3 Digital IO (5) Digital IO / PWM
RD2 Digital IO (4) Digital IO
RD1 Digital IO (3) Digital IO / PWM / Interrupt
RD0 Digital IO (2) Digital IO / Interrupt input
RC6 Digital IO / Serial UART 1 Tx (1) Digital IO / Serial UART Tx
RC7 Digital IO / Serial UART 1 Rx (0) Digital IO / Serial UART Rx
HamStack CPU Board
Stacking Board Concept
CPU Board
Accessory
Board
“Project Board”
Dual relay board
stacked on top of
the CPU board
ZigBee RF Module
Topics
• Introduction
• Hardware options
• Software development
• HamStack project examples
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
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 18F4620 ' Select device type
Clock = 10 ' Set clock frequency to 40 MHz
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 */
}
}
/************************************************************************/
For Advanced Projects - HamStack C Library
Cooperative multi-tasking kernel supports…
• Unlimited number of milisecond timers
• Sine wave tone generation
• Interrupt driven serial port send and receive
• Interrupt driven CW generation
• Interrupt driven DTMF generation
• 2 line x 16 character LCD display
• Shift register digital i/o expansion
• A/D converter support
• Dallas Semiconductor DS18B20 one-wire digital temperature chip
• Interrupt driven rotary encoder support, for user controls
• CW keyer functions
In-Circuit Programmer Downloads the ProgramOpen the .hex file Hit the “Write” button
Topics
• Introduction
• Hardware options
• Software development
• HamStack project examples
Temperature Controlled Fan
In High-Power Dummy Load
Temperature Controlled Fan
In High-Power Dummy Load
GPIO Board with CPU Module
Serial
Hub
RS232
RS232
RS232
RS
485
RS
485
RS
485
RS
485
RS
485
RS
485
HamStack CPU &
General Purpose IO Boards
PC
“Virtual Control Head”
software
Hardware
Control Head
Elecraft K3
AC Power Relay
Antenna Relay
Temperature Probe
Voltage Probe
Station Control Demonstration
GPIO Board
GPIO Board
HamStack Project Board
HamStack Project Board
HamStack Project Board Keyer
CPU Board kit
The HamStack Platform
Accessories
Starter Pack
Project PackGPIO Board kit
www.sierraradio.net www.hamstack.com