#1: A C++ tutorial on interfacing with USB devices using .dll libraries
I recently had to test RF DUTs during my RAship. For that I was using the Signal Hound VSG25A Signal Generator. Usually these low cost instruments are USB based with a GUI on the computer and lack front panel buttons. So everything works via the software. But for complex test cases, it gets tedious to go through similar settings every time.
My requirement was to automate the signal generator as part of a large test suite written in Python. For this, the test instrument must support SCPI but this instrument’s didn’t. So Python was out of the question. The option that comes with this Signal Hound device for automating its functionality is a C++ Windows API. In Windows, linking DLLs with your C++ program is still a bit of a “small adventure” because you have to have it in your path variables and so on…
The easy way to do it is just to include the SG_API.dll in your working directory and have the header files SG_API.h in a dedicated includes folder also in the working directory.
The following are some snippets of the code:
#pragma once
#include <VSG25A/sg_api.h>
#include <Windows.h>
#include <synchapi.h>
#include <iostream>
using std::cout;
using std::endl;
enum class mode {
frequencySweep,
powerSweep,
mixedSweep
};
enum class errorStatus {
ConsoleCtrlErr = -1,
Success = 0,
NotFound = 1,
RfSetFail = 2,
RfParamSetFail = 3,
RfCWSetFail = 4,
RfSweepSetFail = 5,
VSGCloseFail = 6,
};
// safely close device on CTRL_C event
BOOL WINAPI consoleHandler(DWORD signal) {
if (signal == CTRL_C_EVENT)
sgCloseDevice(deviceHandle);
return TRUE;
}
int main(int argc, char** argv)
{
// open device
sgStatus deviceStatus = sgOpenDevice(&deviceHandle);
if (deviceStatus != sgUnableToFindDevice)
{
// assign start freq to current freq on start of program/loop
double currentFreq = startFreq;
while (loopCount <= ITERATION_STEPS)
{
if (loopCount == ITERATION_STEPS)
{
loopCount = 0;
}
// Turn RF off
if (sgRFOff(deviceHandle) != sgNoError)
{
cout << "Error on RF off\n";
programFlag = RfSetFail;
break;
}
// Set parameters
if (sgSetFrequencyAmplitude(deviceHandle, currentFreq, amplitude) != sgNoError)
{
cout << "Error on setting RF parameters\n";
programFlag = RfParamSetFail;
break;
}
// Turn CW RF signal on
if (sgSetCW(deviceHandle) != sgNoError)
{
cout << "Error on turning ON CW RF signal\n";
programFlag = RfCWSetFail;
break;
}
cout << "Current Freq is: " << currentFreq/1e6 << "MHz with power "
<< amplitude << "dBm\n";
//Sleep(DWELL_TIME * 1000);
currentFreq += sweepStep;
loopCount++;
}
}
#2: Using ADF4351 PLL to generate 35MHz to 4.4GHz with RPI2040
I bought the ADF4351 to do some CW experiments and just finished the schematic. The controller will be The Raspberry Pi RPI2040. The schematic and layout are shared below.
Here is the schematic:
ADF4351-RPI2040And here is the RFPCB layout:
Doppler_PCBHere’s the 3D preview generated by KiCAD:
#3: A simple microstrip filter for the 1-2GHz frequency band
Filters are an important building block in the RF domain. They are used to damp down unwanted frequencies in a system. These filters might be Off-The-Shelf (OTS) type or Distributed Element type which includes Microstrip (MS) or Stripline filters. The OTS filters are very convenient since they are guaranteed to work according to the manufacturers data sheet. It is usually recommended to use these type of filters whenever you can find as they significantly reduce design complexity and time. But when you go to higher frequencies these OTS filters will become hard to find. So we have to use Distributed Element filters in these scenarios.
The distributed element filters have many variants but they are hard to design and often require costly EDA tools to analyze/tune. The filter which we’ll be looking at today is the Quarter Wavelength Filter. It is easy to analyze and even more easier to design.
As the name suggests, it is built with resonators of quarter wavelength of the desired frequency. This wavelength may also be called the guided wavelength. The filter features series and parallel λg/4 resonators. The resonators can be increased to get a steeper transition region. The filter can be better understood by looking at the schematic below.
The good thing about this filter is that it is extremely easy to manufacture and gives a very wide bandwidth. The manufacturability problem with filters often comes up when to achieve a desired response Suspended Striplines have to be used or very tight tolerances are needed to get the exact coupling in coupled line filters. This filter is very design friendly too as you just have to draw CLINES (Allegro terminology for copper traces) of a particular width (for 50 ohm characteristic impedance) and length (Quarter Wavelength), and you’ll be on your way.
So how does it perform in the real world you might ask. As with all things in RF, it might depend on your frequency or substrate type. I am using the RT2880 substrate on which this filter performs exceptionally well and the results are also shown for the same substrate. If time permits, I’ll make one with the FR4 material too.
Here are the simulated and measured results shown side by side:
One thing to remember when using this filter and distributed filters in general is that their response repeats at odd harmonics as can be seen above. The response for the fundamental 1.5GHz repeats at 4.5GHz. So this topology should not be used to filter out harmonics like those generated from a nonlinear signal source like a PLL or signal generator.
#4: Are cheap SMA connectors worth it?
If you have ever done Bill of Materials for RF projects, you’ll realize that most of the BOM costs are associated with connectors, adapters or wires. For my own personal project, I bought SMA connectors from China. You can get 20 or sometimes 30 of these in $4-5. In contrast, just one SMA connector from Amphenol RF costs about $7. Huge difference!
So why the difference? One guess is that Amphenol RF ones are rated upto 18GHz but the China ones don’t have frequency information on their AliExpress pages. I have access to a VNA so lets find out the difference in real world scenarios. The test circuit is shown below.
Its a thru line Grounded Coplanar Waveguide with about 1.5mm ± 0.1mm of width so it should almost have a 50ohm impedance from 10MHz to 10GHz.
Let’s see the s-parameters of the cheap SMA connectors on the VNA. Frequency sweep of 10MHz to 10GHz is set
The response is pretty much perfect except for the one dip in S21 and S12 around 5-6GHz. They will work just fine for my ISM band project.
These SMA connectors seem like a good deal at least frequency performance wise but there’s a catch! You may even call it a hamartia. Physically these connectors are poorly built. The threads are not fine and they seem to take a lot of torque to tighten. The Amphenol RF ones are smooth as butter in terms of connector mating. This means that while you do pay less upfront with these connectors, overtime they will cost you a hella lot more. Especially if you make the mistake of using these with the 40GHz VNA cable. So only use these with bad cables and keep them separate from the rest of the inventory!
All in all, if you don’t have to worry about damaging lab equipment and are on a hobbyist budget, I’ll definitely recommend these connectors. Otherwise don’t buy these!
#5: Some pointers on debugging a signal chain with few testpoints using Python and SCPI
A presentation about a problem in the Software Defined Radio that took many days to resolve and some novel ways of debugging signal path/chain problems.
Specifically, this part of a UHF/VHF receiver:
#6: Distribution of multiple voltages on a 2-Layer PCB using polygonal copper pours
The 2 layer stackup is the usual choice for small run, cheap and prototype PCBs. For complex PCBs like RF, FPGA or high speed stuff, you need to move to custom stackups with multiple layers. Custom stackups are only needed when you have to maintain characteristic impedances for digital or RF. And multiple layers are used when power distribution involves multiple voltages.
But what do you do when you need to design a high power PCB with 2 layer constraint and it includes multiple voltages. That is where we use the polygonal pours, similar in concept to the ground/power plane. Bear in mind that when designing a multi-layered PCB, you always dedicate a full layer to the common voltage (say +5V) and another layer for GND, making that layer the return path for all currents.
For a 2-layer PCB, you can’t assign a whole layer to a specific volage. Easier designs with with single supply voltages have to choose between dedicating the BOTTOM layer to VCC or GND. Almost all designs, make the BOTTOM layer the GND plane. Some designs can also use the TOP layer for power distribution by using a polygon shaped power plane. But almost always, you use the TOP layer also for signal routing (RF or high speed). For power delivery, use thick traces or copper pours.
As an example, lets see a real PCB with power planes and the ground planes. The BOTTOM layer:
The TOP layer:
As can be seen in the two pictures, this design achieves power distribution on the expense of having a severely cut GND plane. The design has somewhat adjusted to this using a ground pour on both TOP and BOTTOM layers but this will not work for high speed designs.
When using polygon shaped planes, always use a capable EDA tool. The EDA tool must have a DRC checker that can do connection check as well shape to shape overlap or short check. The above design uses Cadence Allegro.
#7: An easy (and potentially dangerous) way to find shorts in prototype PCBs
Our Lab has a prototype PCB manufacturing machine (LPKF S103). It is one of the best equipment money can buy and comes very handy when you accidentally get something wrong in the design of a production PCB.
Recently, a prototype PCB was fabricated on it but something was very wrong. The unpopulated PCB’s +5V rail was shorting with GND. Moreover, it wasn’t a “proper” short. Rather this was a short of a few kilo Ohms when tested with a multimeter on resistance mode. Very surprising and curious 🤔.
One thing that I was certain of was that this was not a layout mistake (i checked my design thoroughly) i.e. not a “proper” short. A “proper” short is one in which you have a copper trace touching the GND plane (another copper entity) and it gives you a perfect 0ohm resistance even if your trace is 0.1mm (I checked!). So, the short appearing in the test circuit is likely due to a piece of conducting residue stuck somewhere. But where????????
There are three ways to find the problematic area or track. All of these methods exploit the nature of shorts:
- Put controlled power through the unpopulated board and use a thermal imaging camera to find the short. A short being an electrical connection of a tiny width should heat up when a lot of current is passed through it. Remember its a resistance of 1-2 kilo ohms.
- Put controlled power through the unpopulated board wet with Isopropyl Alcohol and inspect the area where the wet board starts to dry itself.
- Put controlled power through the unpopulated board and let the short destroy itself due to heat.
We will be looking at the 3rd method in action here, that is we put 30V & 5A through the board, and let the residue burn itself. Check the video below:
This method gets the job done as can be seen from the smoke arising. The short was due to the ProConduct paste used for making plated through holes (PTH vias). Some of the residue made its way out of the through hole (the smoke can be seen rising from a hole in the PCB) and connected it to GND. The through hole is on +5V rail so it was caught during the initial PCB fab tests.
#8: A 10dB Microstrip Directional Coupler for the ISM band (2.4GHz)
Today, I will be discussing the design of a coupler and will walkthrough the design procedure of the 10dB coupler I will be using in my Doppler Radar project. If you are interested in the theory of couplers, you can read this excellent yet concise tutorial by the Quite Universal Circuit Simulator (QUCs) team.
RF Couplers are usually used in a signal chain when:
- you have to snoop the signal from a testpoint
- want a sample of the signal to be used somewhere for TSSI/RSSI or for mixing the TX/RX signals for radar applications.
Keep in mind that an ideal coupler achieves both of these things without disturbing the signal path. But since nothing is perfect, it will still have some insertion loss and the coupled port disturbances will be coupled into the signal path.
The dB value of a coupler determines the strength of the sample signal it gives at its 3rd port. For example, from Minicircuits I have the ADC-10-4+ and ADC-26-52+. The naming scheme of Minicircuits for couplers is that the first number to appear in the name of the coupler will be the coupling coefficient. So, the ADC-10-4+ will have a 10dB coupling and the ADC-26-52+ will have a 26dB coupling.
To make a Microstrip coupler, only the requirement of coupling and the substrate on which you will implement it is required. The coupler here is on an FR4 material with the goal of 10dB coupling. Most planar technologies like couplers or filters usually require few iterations (usually 2-3) to tune to specs so the goal of 10dB will not be achieved in a single iteration.
Through Port:
The coupler is a 4-port network so each each port-port characterization will produce 2×2 S-matrix. Here we see the through port shown as S21 or S12 below:
Coupled port:
Similarly, we can see the coupled port shown in S21 or S12:
#9: Making RF PCBs on KiCAD
I started using KiCAD for a AD4351 based 35MHz-4400MHz signal generator. KiCAD already had a transmission line calculator for MLIN, CPWG, CPW etc which I use more than ADS’s LineCalc utility. KiCAD also has added a microwave toolbar recently but it is more geared towards adding stubs and length matching. For an RF PCB design the following tools are a must:
- via fencing
- via stiching
- rounded traces
- soldermask expansion over a microwave track
These are not yet supported natively but the KiCAD RF tools plugin brings all this functionality into KiCAD. The Rounder for Tracks requires some getting used to but after that it does the job pretty well. All 4 tools were used to achieve this layout.
#10: FreeCAD is awesome!
I was always searching for an Open-source solution for mechanical CAD drawings and STEP viewer. Recently found FreeCAD and loving the simplicity and obviously free aspect of the software. Highly recommended!
#11: Talking to your Test Instruments or Speeding Up Wideband RF Measurements – a Standard Commands for Programmable Instruments (SCPI) Tutorial
Planned for future….
#12: Understanding Fractional-N Phase Locked Loops
Planned….
#13: A tutorial on genetic algorithms
Planned…
#14: Modding the original Xbox
Will be following Bunnie’s book and discussing communication of various parts of the XBOX using HW/SW reversing techniques
#15: The Art of Modding a PCB
Will walkthrough a modification (aka “mod”) of a PCB I made recently….