Panteltje's swr_pic page

Panteltje's swr_pic page


Here you find the listings for 2 PIC 16F690 to function as RF power and SWR meter, with RS232 interface.

The asm sources:
First PIC: swr-0.6.1.asm
Second PIC: pwtx-0.5.1.asm

See also xpvox, xpvox is a program that o.a. has voice level activation, and can control swr_pic via a serial line.

This version uses a 4 lines x 20 character display (google HC200401C-VA.pdf, with controller S6A0069.pdf)
This version additonally has battery voltage, battery current, and ampere-hours display, and a 20 character message area (via RS232) on line 4, also 'h' prints help.
For diagrams see below.

This is the response to typing 'h' at the terminal (I use the communication program for Linux 'ptlrc', you can download it here: ptlrc-0.3.tgz ):
# ptlrc -d /dev/ttyS1
Panteltje ptlrc-0.3 using device /dev/ttyS1
Escape exits.
RS232 commands:
ASWR alarm beeper on, status saved in EEPROM.
aSWR alarm beeper off, status saved in EEPROM.
BnnnENTERsets swr alert level, enter 17 for 1.7, stored in EEPROM.
bprints SWR alarm level.
Denters debug mode, continuously prints adc steps for I, U, P, forward, reflected, and flags2.
dexits debug mode.
Fflash clock separator, status saved in EEPROM.
fdo not flash clock separator, status saved in EEPROM.
GnnnENTERsets clock calibration, timer1 reload low byte, use 175 for nominal, is saved in EEPROM.
at first power up (directly after programming) the EEPROM is set with the default value for G(175).
gdisplays clock calibration (timer1 reload low byte).
HnnENTERsets hour, range 0-24.
hprints help.
iprints battery current
MnnENTERsets minute, range 0-59.
PnnnENTERsets PWM output value, LCD backlight, range 0 to 100, stored in EEPROM.
pprints PWM setting
Rreset ampere hours.
sprints SWR.
tprints time.
uprints battery voltage.
vprints version number.
wprints power in Watts.
X transceiver power on (PIC 2).
xtransceiver power off (PIC 2).
Ytransmit on (PIC 2).
ytransmit off (PIC 2).
zprints ampere hours used.
ctrl ASOME TEXTENTERsends 'SOME TEXT' to line 4 of the LCD, max 20 characters, text is displayed upon ENTER.
ctrl Gactivates the beeper for part of a second, can be used to draw attention to a new text for example.

The following Linux bash script, when the serial port is initilalized, sends a message to the LCD, and beeps, I use it to send inside and outside temperature to the LCD:
# text as arg1
echo -e "\0001$1\r" > /dev/ttyS1
# bell
echo -e "\0007" > /dev/ttyS1

Here is the diagram of the SWR box as it is now:

About the diagram:
There are 4 inputs to the first PIC, range 0-5V, power, forward, reflected, and battery current.
It outputs to a 4 line character LCD display, and can also be read via RS232 by for example a PC.
The battery current is measured across the MOSFET when it is on (the voltage drop over the Rdson is amplified by a LM324).
The second PIC has as input the battery voltage, and also listens to the RS232, and switches the transceiver power, TX line, and a low battery alert LED.

The range is 149 Watt for 5 V DC in, and SWR is calculated as the ratio between the 2 other analog inputs, and should work over a wide range.
The supply is the voltage reference for the PIC, perhaps use a LM317.
The PICs use the internal oscillator.
The math is done in integer, some rounding takes place.
You can set the 'SWR alarm' from the PC, to say to 1.8, and the LED will come on and beeper will be activated if SWR >= 1.8.
The clock speed calibration, and LCD brightness (PWM) can also be set from the PC, and all settings are saved in EEPROM,
so you basically have to do that only once.
SWR, Power, and the settings for SWR alarm, clock calibration, as well as ADC steps, can all be read from the PC if need be.

The SWR transformer is a little PCB with diodes taken from an existing Pan SWR power meter (with analog meters).

The menu for all commands, including the function in the second one, is also in the first PIC.
The PICs communicate with the PC at 19200 Baud, 8 bits no parity.

About the math:
SWR is calculated as SWR = (Vfwd + Vrefl) / (Vfwd - Vrefl).
From this follows that the main requirement is that the signals Vforward and Vreflected are within the ADC 0 to 5V input range.
The absolute value is not that critical, but try to go for 5V max at 160 W for example.
Test shows that with very low voltage (low output power) the SWR is still displayed correctly.
Here is the intended input circuit for the power input, connected to the transmitter side of the SWR meter.
With a 50 Ohm load, and 150 W, then U^2 / 50 = 150, or U = sqrt(7500) = 86.6 Veff.
The peak value is sqrt(2) x 86.6 = 122.474 V.
The diode drops about .7 V, that leaves 121.77 V DC on the capacitor.
The output divider is 1/26, leaving 4.68 V on the PIC for 150W.
This is about 958 (of max 1023) ADC steps, the PIC asm math is based on this.
Some people may object to the loading on the transmitter by this circuit, causing distortion (harmonics),
in that case you can make a resistor divider, and place the diode behind that, and adapt the ASM math as now
the diode drop has more effect (especially at low power levels), and this effect is squared in the calculations.
Make sure you decouple the analog input pins of the PIC with say 100nF right at the pins, to avoid instability.

The RS232 connector, the audio in (for audio or packet radio) is a tulip, the audio out + TX control to the RCI-2970DX is a 5 pole DIN 180 degrees connector, and the power 12 V is just a big strip.
The extra not used holes, and connections are for a power MOSFET to control the fan so it is only on in transmit, now the fan is on all the time when power is applied.

The LEDs are placed behind a semi-transparent inkjet printed sheet, the sheet and text is covered by a second transparent plastic sheet. Some air bubbles remain.
'Low Batt' is not a switch position, but there is a red LED behind that, the PIC switches off the power to the transceiver below 10.0V.
The 'SWR alert' LED is not on in the picture, is red, and is also connected to a beeper.
Perhaps it would make more sense to put all indicators in the LCD display, and forget about LEDs, but the colored LEDs look nice.
The big knob is very old, found it in the junkbox, and looks really cool here :-)
The power either comes from a 12 Ah sealed lead acid battery, or a power suply from an old computer.


Click here for some other programs I make available under the GPL.

Click here to send mail