Last active
December 21, 2015 05:09
-
-
Save alejolp/6254971 to your computer and use it in GitHub Desktop.
Arduino SWR Meter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Arduino SWR Meter | |
* Por Alejandro Santos LU4EXT ([email protected]) | |
* | |
* Conectar en Analog0 la salida de potencia directa, y en Analog1 la salida de reflejada. | |
* Creado para usarlo junto a un puente de ROE, por ejemplo el de XQ2FOD. | |
* http://ludens.cl/Electron/swr/swr.html | |
*/ | |
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
void setup() { | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
// Print a message to the LCD. | |
lcd.print("SWR METER LU4EXT"); | |
delay(1500); | |
} | |
int pf=0, pr=0; | |
#define A 0.9 | |
void loop() { | |
int pr_real, pf_real, modulo; | |
float p, swr; | |
pf_real = analogRead(0); | |
pr_real = analogRead(1); | |
pf = pf_real * A + pf * (1-A); | |
pr = pr_real * A + pr * (1-A); | |
p = sqrt( ((float)pr) / pf ); | |
swr = (1+p)/(1-p); | |
modulo = (int)(swr*100)%100; | |
lcd.setCursor(0, 0); | |
lcd.print("f:"); | |
lcd.print(pf); | |
lcd.print(" r:"); | |
lcd.print(pr); | |
lcd.print(" "); | |
lcd.setCursor(0, 1); | |
lcd.print("SWR: "); | |
lcd.print((int)swr); | |
lcd.print("."); | |
if (modulo < 10) { | |
lcd.print("0"); | |
lcd.print(modulo); | |
} else { | |
lcd.print(modulo); | |
} | |
lcd.print(" "); | |
lcd.print(millis()/1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment