Introduction
In telecommunications, particularly in radio, signal strength refers to the magnitude of the electric field at a reference point that is at a significant distance from the transmitting antenna. It may also be referred to as received signal level or field strength. Typically, it is expressed in voltage per length or signal power received by a reference antenna. High-powered transmissions, such as those used in broadcasting, are expressed in dB-millivolts per metre (dBmV/m). For very low-power systems, signal strength is usually expressed in decibels above a reference level of one milliwatt (dBm).
MikroElektronika has introduced the RF Meter click board and made signal strength measurement easy like never before. This compact board carries the Analog Devices AD8318 ( demodulating logarithmic amplifier, capable of accurately converting an RF input signal to a corresponding decibel-scaled output voltage ) and Microchip's MCP3201 ( 12-bit analog-to-digital converter ).
https://github.com/MikroElektronika/Click_RF_Meter_AD8318
Setup
MikroE. has always gone the extra distance in bringing the barrier to entry into high tech a short journey. Our IDE makes added libraries just as easy as checking your email. With this in mind, we are going to be installing the RF Meter click library and examine the code that make it work.
- Get package or source code from Libstock or Github
- Unzip your platform ( ARM, PIC, FT90x, PIC32, DSPIC )
- Install libary using the Package Manager
- Open the IDE and start a new project
- Verify Click_RF_Meter is now visible in the Library manager, include it in your project by checking it
The first thing we want to do is include the RF Meter library into our search path. This can be easily done by selecting Project / Edit.
… add search path.
Include the rf_meter_hw.h header file into our project by:
#include "rf_meter_hw.h" void main() { while( 1 ) { //TODO: The real magic goes here } }
Our device works with SPI bus, therefore we need to initialize the bus that our RF Meter is attached to in order for communication to work. The SPI library should be selected in the Library manager when you selected the RF Meter library.
Also we must execute the library init function that sets values ( slope and intercept ) to default, and prepares the library for use.
Initialization is best when moved away from the main function by placing all the initialization routines into a separate function.
#include "rf_meter_hw.h" void system_init( void ); void system_init() { SPI3_Init_Advanced( _SPI_FPCLK_DIV64, _SPI_MASTER | _SPI_8_BIT | _SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION | _SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1, &_GPIO_MODULE_SPI3_PC10_11_12 ); } void main() { system_init(); rf_meter_init(); while( 1 ) { //TODO: The real magic goes here } }
The library also requires that you declare what pin the chip select is on. I’m using the EasyMx PRO version 7 and placing the RF Meter in the mikroBUS slot 1. The chip select for that port is PD13, also the pin should be declared as digital output. We will also add small delays after each initialization to be sure that routine and voltages are stable.
#include "rf_meter_hw.h" sbit RF_METER_CS at GPIOD_ODR.B13; void system_init( void ); void system_init() { SPI3_Init_Advanced( _SPI_FPCLK_DIV64, _SPI_MASTER | _SPI_8_BIT | _SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION | _SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1, &_GPIO_MODULE_SPI3_PC10_11_12 ); GPIO_Digital_Output( &GPIOD_BASE, _GPIO_PINMASK_13 ); Delay_ms( 200 ); } void main() { system_init(); rf_meter_init(); Delay_ms( 200 ); while( 1 ) { } }
Our board is now ready for use. Measuring RF signal strength now can be done with the rf_meter_get_signal_strength() function. More explanation about this, and all other functions that are available can be found on the help pages provided within the library.
#include "rf_meter_hw.h" sbit RF_METER_CS at GPIOD_ODR.B13; void system_init( void ); void system_init() { SPI3_Init_Advanced( _SPI_FPCLK_DIV64, _SPI_MASTER | _SPI_8_BIT | _SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION | _SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1, &_GPIO_MODULE_SPI3_PC10_11_12 ); GPIO_Digital_Output( &GPIOD_BASE, _GPIO_PINMASK_13 ); Delay_ms( 200 ); } void main() { double result; system_init(); rf_meter_init(); Delay_ms( 200 ); while( 1 ) { result = rf_meter_get_signal_strength(); } }
Now you can build your project and check measurement values through debug mode. If you want to display your measurements on a TFT, I suggest you try the example that can be found in the example folder with the RF Meter library.
Note
The RF Meter library uses default slope and intercept values. However to improve signal strength measurement you can calibrate your RF Meter click board by setting slope and intercept values to your individual click board. The equation can be rewritten for output voltage, from the measurement mode section, using an intercept expressed in dBm.
V(out) = Slope × ( P(in) – Intercept )
In general, the calibration is performed by applying two known signal levels to the AD8318 input and measuring the corresponding output voltages. The calibration points are generally
chosen to be within the linear-in-dB operating range of the device. Calculation of the slope and intercept is done by:
Slope = ( V(out1) − V(out2) ) / ( P(in1) − P(in2) )
Intercept = P(in1) − V(out1) / Slope
Once the slope and intercept are calculated, you can store values with functions rf_meter_set_slope() and rf_meter_set_intercept() .
Example
/******************************************************************************* * Title : Demo of RF Meter click * Filename : ARM_example.c * Author : MV * Origin Date : 04/01/2016 * Notes : None *******************************************************************************/ /*************** MODULE REVISION LOG ****************************************** * * Date Software Version Initials Description * 04/01/16 .1 MV Module Created. * *******************************************************************************/ /** * @file ARM_example.c * @brief Example of RF measurement */ /****************************************************************************** * Includes *******************************************************************************/ #include "rf_meter_hw.h" #include "resources.h" /****************************************************************************** * Module Preprocessor Constants *******************************************************************************/ /****************************************************************************** * Module Preprocessor Macros *******************************************************************************/ /****************************************************************************** * Module Typedefs *******************************************************************************/ /****************************************************************************** * Module Variable Definitions *******************************************************************************/ // TFT module connections unsigned int TFT_DataPort at GPIOE_ODR; sbit TFT_RST at GPIOE_ODR.B8; sbit TFT_RS at GPIOE_ODR.B12; sbit TFT_CS at GPIOE_ODR.B15; sbit TFT_RD at GPIOE_ODR.B10; sbit TFT_WR at GPIOE_ODR.B11; sbit TFT_BLED at GPIOE_ODR.B9; // RF METER chip select pin sbit RF_METER_CS at GPIOD_ODR.B13; // Example variables int track; int last_track; double result; char tmp_txt[15]; /****************************************************************************** * Function Prototypes *******************************************************************************/ void system_init( void ); void display_init( void ); /****************************************************************************** * Function Definitions *******************************************************************************/ void system_init() { SPI3_Init_Advanced( _SPI_FPCLK_DIV64, _SPI_MASTER | _SPI_8_BIT | _SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION | _SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1, &_GPIO_MODULE_SPI3_PC10_11_12 ); GPIO_Digital_Output( &GPIOD_BASE, _GPIO_PINMASK_13 ); Delay_ms( 500 ); track = 0; last_track = 0; } void display_init() { TFT_Init_ILI9341_8bit( 320, 240 ); TFT_BLED = 1; TFT_Set_Pen( CL_WHITE, 1 ); TFT_Set_Brush( 1,CL_WHITE,0,0,0,0 ); TFT_Set_Font( TFT_defaultFont, CL_BLACK, FO_HORIZONTAL ); TFT_Fill_Screen( CL_WHITE ); TFT_Set_Pen( CL_BLACK, 1 ); TFT_Line( 20, 46, 300, 46 ); TFT_Line( 20, 70, 300, 70 ); TFT_Line( 20, 196, 300, 196 );; TFT_Line( 20, 220, 300, 220 ); TFT_Set_Pen( CL_WHITE, 1 ); TFT_Set_Font( &HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL ); TFT_Write_Text( "RF Meter click", 95, 14 ); TFT_Set_Font( &Tahoma15x16_Bold, CL_BLUE, FO_HORIZONTAL ); TFT_Write_Text( "AD8318", 130, 50 ); TFT_Set_Font( &Verdana12x13_Regular, CL_BLACK, FO_HORIZONTAL ); TFT_Write_Text("EasyMx PRO v7 for STM32", 19, 223); TFT_Set_Font( &Verdana12x13_Regular, CL_RED, FO_HORIZONTAL ); TFT_Write_Text( "www.mikroe.com", 200, 223 ); TFT_Set_Font( &Tahoma15x16_Bold, CL_BLACK, FO_HORIZONTAL ); TFT_Write_Text( "Current signal strength", 30, 200 ); TFT_Set_Font( &HandelGothic_BT21x22_Regular, CL_BLACK, FO_HORIZONTAL ); TFT_Image( 114, 100, signal_lo_bmp , 2 ); } void main() { system_init(); display_init(); // Device initialisation // Must be done before usage rf_meter_init(); Delay_ms( 200 ); while( 1 ) { // Signal strength measurement result = rf_meter_get_signal_strength(); // Change the track value only in case of the signal strenght chaged // scope to avoid the display refreshing on every single loop if ( result < -50.0 ) track = 0; else if ( ( result < -35.0 ) && ( result >= -50.0 ) ) track = 1; else if ( ( result < -20.0 ) && ( result >= -35 ) ) track = 2; else track = 3; // If scope changed delete old picture and draw a new one if ( track != last_track ) { TFT_Rectangle( 112, 98, 196, 166 ); switch( track ) { case 0 : TFT_Image( 114, 100, signal_lo_bmp , 2 ); break; case 1 : TFT_Image( 114, 100, signal_lo_m_bmp , 2 ); break; case 2 : TFT_Image( 114, 100, signal_hi_m_bmp , 2 ); break; case 3 : TFT_Image( 114, 100, signal_hi_bmp , 2 ); break; } // Replace old scope value with the new one last_track = track; } // Display signal strength sprintf( tmp_txt, "%5.1f dBm", result ); TFT_Rectangle( 198, 200, 288, 218 ); TFT_Set_Font( &Tahoma15x16_Bold, CL_BLUE, FO_HORIZONTAL ); TFT_Write_Text( tmp_txt, 205, 200 ); Delay_ms( 500 ); } }
Summary
Frequencies are getting faster and faster in the world of communications which constitutes better isolation and connectivity. How else are we to measure the efficiency of such systems? While traditional oscilloscopes are made to measure such signals, the cost can be a quick deterrent from such an endeavor. The RF Meter click can dramatically reduce the cost and give the same valuable feedback. That, and it's fun to measure your cell phone output.
References
Signal Strength Wikipedia 2016
Libstock RF Meter Library 2016
GITHub Source for RF Meter Library 2016