Monday 7 November 2016

BASIC Tech Group - MyNews 3 - RF Meter

Here's the RFMETER. Input impedance is 50R, input attenuator of 20dB, max input power 2W. Two line display of dBm, Watts & Volts

Screen Shot 2016 11 07 at 17 53 10

Input is to Arduino Uno pin A0, AREF analog reference is connected to 3.3V.

Code

// RF-Meter,
// input 50R/2W via a pi 20dB attenuator 82R - 240R - 68R
// displays dBm, Watts, Volts. Autoscaling

#include 
#include 

#define LCDADDR 0x3F
#define LCDCOLS 16
#define LCDROWS 2

// Analog input pin
#define DCIN A0
#define AREF 3.3

// intercept (dBm), slope (mw/dB), input impedance, attenuator (dB).
#define INTERCEPT 84.0
#define SLOPE 25.0
#define IMP 50
#define ATTN -20

LiquidCrystal_I2C lcd(LCDADDR, LCDCOLS, LCDROWS);

void setup() {
  lcd.begin();
  lcd.backlight();

  // 3.3V connected to AREF
  analogReference(EXTERNAL);

  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("RF METER");
}

void loop() {
  float mV, dBm, mW, V;
  
  // calculations for MV input, dBM, mW, and Volts
  mV = 1000.0 * (float)analogRead(DCIN) * (AREF / 1023);
  dBm = (mV / SLOPE) - INTERCEPT;
  dBm -= ATTN;
  mW = pow(10, (dBm / 10));
  V = sqrt((mW / 1000) * IMP);

  // dBm
  lcd.setCursor(0, 1);
  lcd.print(dBm, 0);
  lcd.print("dBm ");

  // Watts
  if (mW < 1.0) {
    lcd.print(mW * 1000, 0);
    lcd.print("uW ");
  }
  else if (mW < 1000.0) {
    lcd.print(mW, 0);
    lcd.print("mW ");
  }
  else {
    lcd.print(mW / 1000, 1);
    lcd.print("W ");
  }

  // Volts
  if (V < 1.0) {
    lcd.print(V * 1000.0, 0);
    lcd.print("mV  ");
  }
  else {
    lcd.print(V, 1);
    lcd.print("V  ");
  }

  delay(500);
}

float dbmMw(float dbm)
{
  return pow(10, (dbm / 10));
}

No comments: