Tuesday, October 29, 2019

Checking Step Attenuator with NanoVNA

I decided to check the step attenuator with the NanoVNA.  It would be nice to see what the linearity of the step attenuator is across the frequency range I am interested in.  After calibrating the VNA I did a series of sweeps from 1 - 250 MHz. This uses the fundamental frequency range of the VNA, it uses harmonics for higher frequency measurements.  I first did the readings using the VNA's internal display, and then repeated with the PC based software.

With 0 dB selected the sweep showed about 2.4 to  2.6 dBinsertion loss .

The VSWR was between 1.05 and 1.1.  These values will work well for anything I plan on doing.  

I then did a series of sweeps at 10 dB incremnts on the attenuator.  The linearity is within about 1 dB throughout the range.


20 dB
30 dB
40 dB.
50 dB.
60 dB.

The linearity looks good across the entire range, within 1 dB.  With an insertion loss of around 2-3 dB in all ranges, which is more than adequate for what I need.  Trying to decide if I want to modify the attenuator firmware to show the actual attenuation or leve it as is.

The autoscale feature of thes PC software  really makes it easy to to get values across such a wide range without loosing resolution. The noise on the sweeps at higher attenuation levels, is due to the sensitivity of the VNA, but is still quite remarkable for a $50 instrument.  I am quite happy with both of these pieces of equipment.  The VNA does many of the things I wanted to do with a version 3 SNA Jr, so I will put off that project and work on several othr things I have been planning.

Wednesday, September 4, 2019

Using the NanoVNA to check an antenna

This is just quick followup to my last post on the NanoVNA.  I ordered a SNA to UHF female adapter so I could try checking an antenna.  For this I wanted to try the available PC application instead of using the small screen on the unit.
This app  is very east to use, just set the comm port and click the connect button.  Then set your frequency range and display type you want.  You then go through the calibration procedure using the short,open,and load standards provided.  You can also calibrate for through, and isolated if you are going to do something like checking filter responses.

My multi-band antenna is a G7FEK which gives me coverage on 80,40,20,and 15 without a tuner.  I figured this would be a good test of the VNA.  I did the scan with a display set to Smith chart. You can see that the impedance is near 50 ohms across the sweep.
You can move the cursor across the sweep and see frequency, impedance, resistance and reactance at that point on the chart.

By using the drop-down you can change the display to Return Loss

or SWR.
One thing I really like about this software is the ability to scale the data to the range you like, or have it auto scale for you.

Now I just need to play with it some more and try checking  filters, and see what else it can do.  Have also been following activity on the nanovna-users on groups.io and see that additional app are already being developed for it.

Thursday, July 25, 2019

Another new toy Update 8/8/19

After FDIM and spending some time visiting my daughter, I came back and thought about some of the on-going projects.  At FDIM I had a chance to spend some time talking with Farhan, discussing my latest version of SNA, and his Antuino.  While they are very similar, I decided to change my design to use his basic circuit with a few changes.  I did a board layout and now have  5 boards coming from China, on the slow boat.  

While waiting I have  been re-thinking how to buid a Spectrum Analyzer, to make it  simpler but still have the features I want.  After doing a lot of reading  blogs, web-pages and old magazine articles, it became apparent that I will have to use a 1st. IF frequency much higher than I had originally thought.  The major problem with this is that I do not have any test equipment that will work up to several hundred MHz.  

About that time I received an e-mail ad about a small hand held VNA that covers from 50 KHz. to 900 MHz.  and costs around $60.
I did some looking around and found some information on-line about the original design and some of the clones that were being built.  It is known as the NanoVNA and I found the nanovna_users  group just starting on Groups.io.  Since the first ad I had was for a pre-order, it took about 3 weeks to get my unit.  After it arrived, I was surprised with how small the unit was, even with its built in display.  My unit came without a battery, but you can run it off the supplied USB C cable supplied.  It has provisions for adding a 3.7 volt Lithium battery, and has charging circuitry built in.  I ordered an appropriate battery, and gave everything  a try.  I was happy with the way it worked as stand alone and also with the PC software that is available for the unit.  

The battery I ordered was just a little too large to fit inside the unit as designed.  But since the design basically just has a top and bottom cover with the sides open, I had already deiced  to design and print a case to completely enclose the unit.  I made the case just a little larger to provide room for the battery and added some protection on the side of the case for the small switch used to control the device along with its touch screen.

Update 8/8/19
I did some playing with the VNA, and am very happy with it.
In this picture you can see the response of a 1M coax between 50 KHz. and 900MHz.  Peaks are around 98MHz. apart. Looking at the Smith Chart  there is a range of about 53 to 48 ohm impedance peak to trough from 441 to 495 MHz.

Only problem I have had was because of its small size.  I ended up knocking it off my desk and cracking the display.  Everything still works, so I decided to print a protective cover for when I am not using it

I put the .stl files for the case, cover and a sun shield in the following dropbox folder


Tuesday, April 2, 2019

63 dB step attenuator UPDATE 5/9/19

While I was working on the power meter function for the latest version of the SNA, I used several fixed attenuators for checking linearity and calibration.  It would be a lot easier if I had a variable step attenuator.  I have several  digital controlled attenuator modules that I bought one eBay a while ago, and I guess it is time to use some of  them. There are several models available.

   The ones I plan on using are the simplest with only 6 control pins for a total attenuation of 31.5 dB in .5 dB steps.  I am going to connect two in series with the control lines paralleled for a total of 63 dB in 1 dB steps. 

 I will use an Arduino Nano  with a small OLED display for control of the attenuator.  A rotary encoder will be used to select the attenuation level, and the push button switch will be used to select ether 1 or 10 dB steps.  Everything should fit in a small 3D printed cabinet along with a 9 volt battery for power.  The attenuator module runs on 3.3 volts, but the current draw is low enough that I can power it directly from the 3.3 volt output of the Nano.  The module also needs 3.3 volt logic level, so I will use a simple voltage divider on the control lines to drop the 5 volt level of the Nano down to 3.3 volts.  I found that some modules had 10K pull down resistors to ground and others did not.  I hand wired the first one, but laid out and ordered some board so I could build several more.  I laid out the board with provision for optional pull down resistors if needed.  The modules come with female SMA connectors.  I replaced one of them with a male connector so I could connect them directly together without having to use a short cable.  This also made it easier to do the board and case design.

After building the board I worked on the software.  It is very simple, with just checking the rotary encoder and incrementing or decrementing the attenuation value by the step size which can be changed by pressing the encoder button.  If there is an encoder event, the attenuator control lines are set to the correct value.  

void setAtten() {
  int atten = AttenValue;
  if (atten >= 32) {
    digitalWrite(DB_32, HIGH);
    atten = atten - 32;
  else  digitalWrite(DB_32, LOW);
  if (atten >= 16) {
    digitalWrite(DB_16, HIGH);
    atten = atten - 16;
  else  digitalWrite(DB_16, LOW);
  if (atten >= 8) {
    digitalWrite(DB_8, HIGH);
    atten = atten - 8;
  else  digitalWrite(DB_8, LOW);
  if (atten >= 4) {
    digitalWrite(DB_4, HIGH);
    atten = atten - 4;
  else  digitalWrite(DB_4, LOW);
  if (atten >= 2) {
    digitalWrite(DB_2, HIGH);
    atten = atten - 2;
  else  digitalWrite(DB_2, LOW);
  if (atten >= 1) digitalWrite(DB_1, HIGH);
  else  digitalWrite(DB_1, LOW);

To check the proper logic I used to set these lines, I used a little less than $10  eight channel USB logic analyzer I picked up on eBay.  The first logic analyzer I used was abound 1980, and was a 16 channels unit and cost several thousand dollars.  At that time the software in the unit was very basic, with only simple trigger options.  The little USB unit uses a open source program called Sigrok PulseView.  It is also a fairly basic program, with similar trigger options to the one I used before.  But, it also has several advanced functions such as being able to decode I2C, serial, and other data streams to the binary,hex, or ASCII values sent or received. 
 I connected the logic analyzer to the 6 control lines going to the attenuator modules and another line to one of the rotary encoder pins.  As I turned the rotary encoder I captured the logic levels on all the connected pins.  The results are shown in this diagram.  With the delay I have between value changes, I was not able to get smooth continuations  change in values.  But each turn of the rotary encoder produced the proper logic level changes to the attenuator modules.

Now all I have to do is finish the 3D printed case and put everything together.

UPDATE 5/9/19
I received the additional pair of attenuators I ordered, finally finished the project.  I added some header pins to the power connectors on the two attenuator modules.  This way I can just  plug into  header sockets mounted to the back of the controller board.
I have been using 9 volt batteries for powering most of the smaller projects, and usually use a rechargeable battery.  This has meant that I have to remove the back cover from the unit to change the battery.  I recently found some 9V batteries that have a built in charge controller, and can be recharged through a Micro USB connector mounted on the bottom of the battery.  This has made it possible to just include an access hole on the case to allow connecting of the USB cable for recharging.  they cost a little more than the  rechargeable batteries I have been using, but the convenience makes up for the slight difference.
This version of the the battery has built in red and green LED indicators in the bottom of the battery, so I made the access hole large enough so I can see the status when recharging.

When I was happy with the final design of the printed case, I added some laser print decals.  I also painted the inside of the case and bottom cover with several coats of an acrylic paint that contains some actual powered copper.  Have not checked, but hope this will provide a little additional shielding to help reduce any radiated signal.  After I was finished, I measured the signal attenuation at various values and found it to be quite accurate.  Also measured insertion loss with it set to 0 dB, and found about a 3 dB loss at all frequencies I am interested in. 

Link to dropbox files

Friday, February 8, 2019

New SNA Power Meter function update 2/17/19

Finally got around to working on the hardware and software for the new SNA.  I decided to build the hardware in stages and test each as I went along.  After getting the ESP32 module and display working, I started on the AD8307 power meter circuit.  One of the differences between my version and the UR5FFR circuit, is that I use a separate AD8307 instead of switching between inputs.  This made the board layout a lot easier, and I already had several AD8307s on hand. 

 I partially populated the input portion of the circuit board, and started working on the software.  I want to be able to use this for broadband measurements of low power signals in dBm., and with a 40 dB. tap  to measure levels up to around 100 Watts.  There will be four ranges   +15dBm with direct input, and 1, 10,  100 Watts using an external 40 dB tap.  Range selection is made by moving the Joystick in a up or down direction.  I decided I wanted to measure  Peak value and the Average power during a user selectable time window.  I currently have time windows of  0.1, 1, and 2.5 seconds. The time window is selected by moving the Joystick to the right or left.  The use of the Joystick for the input device has made the changing of parameters much easier than it had been when I was using a rotary encoder and switches. With the Joystick, I can easily control two different parameters without having to create a sub-menu.  I still have the ability to look for either a Short or Long press on the Joystick pushbutton .    A short press will mostly be used to toggle a function or operation on or off.  In all cases I have decided that a Long press will be used to get out of whatever modality or setting screen  you are in and return to the main or upper menu.

The power meter screen will use my standard simulated analog meter with the scale changing with the range selection.  The Peak reading during the time window will be displayed, along with the Average power over the entire time period.  I also display the current range and time window.

The software for this is a basic While loop.  It first uses the millis() function to get the start time then checks current time  before each time through the loop.   It exits the loop when the selected window time is reached. During each pass through the loop it checks for a higher peak reading and updates a sum and counter that are used to compute the average, I also store the last reading.  I compare the current reading with the previous to determine if I should redraw the needle and print current value.  This helps a lot with eliminating a flicker on the meter.

UPDATE 2/17/19

  tft.setTextColor( BLACK, WHITE);
  while ((millis() - startTime) < pmWindowTimes[pmWindow]) {  // sample for window 
    adc = analogRead(pmADCpin);     // get reading
    average = average + adc;    // add readings to compute average
    if (adc > peak)  peak = adc;   // check if a new peak reading
    count++;     // increment count for computing average
    pmDB = ADC2dBm(adc); // calculate dB value times 10
    if ((abs(lastAdc - adc)) > 4)  {  //  limit change size  to reduce jitter
      // erase old needle and draw in new position
    tft.fillRect(DB_MTR_X + 2, DB_MTR_Y + 30, DB_MTR_W - 4, DB_MTR_H - 40,  WHITE);
      if (pmRange == 0) {        // dBm  direct input
        plotNeedle(DB_MTR_X, DB_MTR_Y, DB_MTR_W, DB_MTR_H, adc, 3300, BLACK);
        lastAdc = adc;   // save last reading for comparrison
      else {             // Watts  using 40 dB tap
        pmWatt = dBm2Watt( pmDB);     // convert dbm reading to watts
        pmWatt = int( pmWatt * (1000 / pmRangeVal[pmRange]));    // prescale
        if (pmWatt > 1000)pmWatt = 1050;      // keep needle on meter face
        plotNeedle(DB_MTR_X, DB_MTR_Y, DB_MTR_W, DB_MTR_H, pmWatt , 1080, BLACK);
        lastWatt =   pmWatt;   // save last reading for comparrison
      tft.setCursor(120, 150);
      printPMValues( pmDB);
  average = average / count;       // compute average  and print
  pmAverage = ADC2dBm(average);    // convert adc readings and store in global 

  pmPeak = ADC2dBm(peak);

Made some changes to the loop that updates the display to reduce some of the jitter I was seeing.  Also took care of some minor issues, such as keeping the needle display on the  meter if  value goes over range.  After a lot of playing around, I was able to come up with a single function to print the power value correctly scaled for whatever range is selected.

void printPMValues( float value) {
  switch (pmRange) {
    case 0:                 // value directly in dBm.
      tft.print ( value / 10, 1);
      tft.println (" dBm.   ");
    case 1:                 // value in mWatt
      value = dBm2Watt( value );         // convert from dBm to watts
      tft.print (value * 1000, 0);       //  scale up for mw display
      tft.println (" mWatt   ");
    case 2:                 // value in Watts  2 decimal places
      value = dBm2Watt( value );         // convert from dBm to watts
      tft.print (value , 2);
      tft.println (" Watt   ");
    case 3:                  // value in Watts only one decimal place
      value = dBm2Watt( value );            // convert from dBm to watts
      tft.print ( value , 1);
      tft.println (" Watt   ");


 This function is used for the value  displayed on the meter, and the Peak and Average values.

I did a manual calibration using a signal source and a fixed attenuator to determine the ADC counts per dB.  Later I will add a calibration function and have the  value stored in eeprom.

Next I have decided to reuse some of these functions and add a modulation monitor.  This will display the power output on a simulated oscilloscope screen.  I think I will have both a Rectified and a RF envelope display. This should help in setting Mic. gain levels to prevent distortion.

Thursday, January 17, 2019

Holidays over, Getting back to projects

The holidays are over and I am back home from visiting family.  So it is about time to get back to some of my projects.  I am going to start the year with a update to my SNA Jr.   I had started it previously, and ran into problems with my original design.  After looking around the net I found two different designs that have some of the options I want to include in my design.  One is the Antenna Analyzer by IW2NDH and other the SI5351 Network Analyzer by UR5FFR. With a lot of help from Google Translate I was able to get all the information I wanted from their documents.  

My new design will include much of the circuitry from their projects, along with some of the things I developed while working on the 'Test Gadget'.  My earlier design used an Arduino Nano as the processor, but I found I needed more program and storage memory.  This design will use a ESP32 development module, along with a 320 x 240 TFT display.  I will also use a small Joystick instead of a rotary encoder for the user input.  Before the holidays I designed a PCB board and sent it off to one of the Chinese board houses that I have been using recently.  The board arrived shortly after I returned home, and I started building up one so I can test it in sections.

One of the things I want is that the instrument will run off of an internal battery.  In the earlier version of the SNA, I used a pair of 18650 lipo batteries with a separate charge controller board.  This gave me around 7-8 volts that I could feed to a 5 volt regulator on the main SNA board.  I recently found a lipo module that has a built in holder for a 18650 battery, a charge controller,  boost converter and regulators that gives 5 and 3 volts regulated out.  One of these should power the new SNA  board with the ESP32 without having to include a regulator on board.  But,  just in case it does not work out I did include a 5V regulator on the circuit board.

After I got all the major parts in, I could design a case for everything to fit in.  What I really like about having the 3D printer is the ability to design a case to exactly fit the project.  Along with the proper holes for controls and displays, I can also design in all the mounting posts and standoffs for all the major components.  It might take a couple tries to get everything to fir the way I want them.  But it usually costs less than a dollar in plastic to print a part in draft quality.  When everything is the way you want it, print in higher resolution.  
It took a couple tries to get everything exactly the way I wanted, but finally printed the top and have all the parts mounted.  Just need to finish wiring everything up.  Using one of the early attempts as a mounting platform to use while working on the software. The case I have now is in regular PLA, but I have some Carbon Fiber filled filament that I might try.  It should add some RF shielding, but don't know if it will help in the HF range or just at VHF and UHF frequencies. The way I designed the clam-shell case, the top and bottom are symmetrical.  When I get around to designing the bottom half, all I have to do is remove the existing cutouts and mounting posts and replace them with the posts needed for the SNA circuit board itself.