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

https://www.dropbox.com/sh/74g4z97ly3bz1au/AACTRkE0hDRww3M_5Uj3tkpMa?dl=0


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
https://www.dropbox.com/sh/2ymaiyxjt1bagwq/AAAVxnZWWdequNoA7kLNuR5Ra?dl=0








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.   ");
      break;
    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   ");
      break;
    case 2:                 // value in Watts  2 decimal places
      value = dBm2Watt( value );         // convert from dBm to watts
      tft.print (value , 2);
      tft.println (" Watt   ");
      break;
    case 3:                  // value in Watts only one decimal place
      value = dBm2Watt( value );            // convert from dBm to watts
      tft.print ( value , 1);
      tft.println (" Watt   ");
      break;
  }

}

 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.



Monday, December 17, 2018

Getting ready for the holidays

I have not been doing much with actual electronics for the last month or so.  Made a big mistake and took a look at Thingiverse.com to try and find a model for something some storage containers for some of my SMD parts.  Well I found them and also several things that I want to make for family for Christmas.  Since then I have been spending most of my time printing parts and putting things together.

I did do a little design and printing related to electronics projects based on a question from Chuck K7QO in the qrp-tech group. He was wondering about 3D printing a Tuning Dial Bezel for small projects, and listed a couple of examples.  I did a set of quick designs and finally got around to printing them.

 One is for a dial mounted on the front of the cabinet, and the other is for a rear mounted dial.
The rear mounted one is about 50 x 60 mm. and I designed for use with a tuning dial around 1.5" diamater.

 
The one for a front mount dial is about 50 x 70 mm and 4 mm deep to provide room for the dial pointer to fit between it and the face.  I made two different dial pointers, one to slip over a .25" dia. shaft.  The other should fit on a vernier drive if used.  I do not have a drive to test it with but going from some pictures I found it should fit some of them at least.
Both designs look like the would nice on a small QRP transceiver.




I did do a couple circuit board layouts for 'test gadgets' and have them on order from China.  Since I will not get around to doing anything with them, I  ordered delivery by slow boat.  They should be here when I get back from visiting family for the holidays. 

A week ago we had the Christmas Lunch for the North Georgia QRP Club.  We had  a very nice turn out.  It was great to see everyone together again.

All the festivities made me want to go and listen to my all time favorite Christmas song.

https://www.youtube.com/watch?v=BmKzZRyzV6w

I guess this is it for now. See you all next year and everyone have a Wonderful Winter Solstice.






Wednesday, October 3, 2018

Audio Test Gadget

While I was waiting on some parts and a set of boards to come in from China, I decided to try making an audio frequency test gadget.
Since I had some of what I wanted to do already done for a Nano, I will see if I can quickly port that over to the Nano Test Gadget mother board.  The mother board is set up for a I2C LCD that I quickly replaced with a 1.3" OLED  display that is also I2C.   Only software required is a driver library from Adafruit, and their graphics library.  This is small but its 128 x 64 pixel display gives fairly good resolution for displaying things like a simulated analog meter and a simple AF spectrum analyzer.  These are things that I have already working on a pro-mini as a stand alone simulated analog meter for a transceiver.

The upper limit for the spectrum analyzer software with this display is about 4Kkz.  which is fine for the audio frequencies usually found in normal HF transceivers.  With that in mind I decided to limit the display range and the tone generator to 4500 Hz.  Using an Arduino tone library, I wrote a small function to generate tones from 50 to 4500 Hz.  This is a square wave output, so I will have to calculate the values for a low pass filter to make the output appear to be more of a sine wave. 


 A function similar to what I used in other projects is used to display the frequency set the value sent to the tone() function. To make it a little easier I just chose 50Hz. as the step size as a compromise between speed and resolution.

Next thing I waned was a AC voltmeter with a frequency response up to 4.5 KHz. at least.  I found some code from Adafruit  for a sound level meter and used  part of that to get the peak to peak value of the AC signal.  This code samples the input pin for  50 ms. and finds the highest and lowest values and uses the difference as the peak to peak value.  After I had it working I checked the values compared to that of a scope over the desired 4.5 KHz. frequency range and found it to be very accurate.

unsigned int  getACVolts( char inputPin) {
#define sampleWindow  50  //  50 ms  20 Hz. sample rate 
  unsigned long startMillis = millis();  // start of sample window
  unsigned int PeaktoPeak = 0;          // peak-to-peak level
  unsigned int SignalMax = 0;
  unsigned int SignalMin = 1024;
  while ( millis() - startMillis < sampleWindow ) {
    sample = analogRead( inputPin);
    if (sample < 1024) {
      if (sample > SignalMax) {
        SignalMax = sample;                                
// saves just the max levels
      }
      else if (sample < SignalMin) {
        SignalMin = sample;                               
// saves just the min levels
      }
    }
  }
  PeaktoPeak = SignalMax - SignalMin;                      
// max - min = peak-peak amplitude
  return  PeaktoPeak ;

}


Since most of what I work on has a peak to peak value of less than 5 volts I am going with a single range for now.  I could easily switch between the 5 volt reference and the 1.1 volt internal reference for the ADC If I want a more sensitive range,
I decided to just use a current limiting  resistor and forget about a voltage divider for the input.  After getting the p-p value from the ADC, I used that as the value  to find the position of the needle on the simulated display.  This is the same code I have used in several projects detailed in earlier Blog posts.  I decided to convert this to rms for the display scale, and also a digital display on the meter face.  


While I was working on the simulated analog meter for a Bitx, I added some code to do a audio frequency spectrum analyzer display.  While I found this would be mostly useless for a transceiver, it will fit in nicely with this test gadget.  


The code ported over very easily, and after adding a rough frequency scale to the display I was very pleased with the result.  Using the simple menu system I have used on most of my recent projects, I wrapped these up into a fairly simple multifunction test gadget for working with audio frequency circuits.  One thing I did find while trying to get this working is that the combination of the OLED display with its screen buffer stored in the Arduino RAM and the buffers used by the FFT, I quickly started to run out of memory.   It took quite a bit of playing to get every thing to play well together.  But now I can set a frequency on the tone generator and read it with either the voltmeter or the spectrum analyzer.

I have a little work to do on the hardware before this is finished, but it is coming along nicely so far.  The other day I saw a article on a
small Arduino based oscilloscope.  Just thinking about seeing if I can cram another function into this test gadget.

Wednesday, September 5, 2018

CWTD.ORG Test Gadget mother boards

In the last CWTD.org podcast, we discussed 3 possible implementations of a standard 'Test Gadget' platform.  There seems to be a desire for a basic platform using a Nano and another more powerful version using either a Teensy or a ESP32.  One thing that is needed to be standardized is a common 'bus' configuration for the 'gadget' modules.  My original 'test gadget' platform, had started out as a test bed for evaluating the ESP32 as the primary processor I will use for some of my upcoming projects.  Later, after I saw the CWTD project I started building modules along that line.

Since I had a circuit board layout that would be workable with a few changes, I decided to modify it slightly.  This will bring out most of the available pins, that could be configured to closely match those available if using an Arduino Nano.  I came up with two board layouts and ordered 10 of each from a Chinese board house that I have been using for some time now.  After they arrived I started putting together the Nano version.  


Because of the memory available and processing power of the Nano, I decided to only have two connectors for the 'gadgets'. Everything is pretty standard for a simple Nano project, except that I added a separate 3.3 volt regulator instead of using the 3.3 volts from the Nano.  On the Nano the 3.3 volts is provided by the USB serial converter, and has limited current capability. The ESP32 is a 3.3 volt only processor, so I will power some of the 'gadgets' directly from 3.3 volts.  Since I want to be able to swap 'gadgets' between the Nano and the ESP32 system,  I added the additional regulator to take care of any 'gadgets' that need a hefty 3.3 volt supply.  The board has a connector that brings out the I2C signals and power for a I2C LCD display, could also be used with a small I2C OLED display if limited graphics are desired.  I also have pads for directly mounting a rotary encoder on the board.

While I was waiting for the boards to arrive, I had designed a case to hold the 'gadget rack' main frame.  And set my great new 3D printer to getting a home ready for the boards when they arrive.
It took a couple tries to get everything fitting the way I want them, but well worth the effort.  That is the thing I really love about using a 3D printer, the ability to make something that fits your project exactly, not just something you had to cobble up to make things kind of fit.

When I assembled the board I decided to mount the 'gadget' header connector on the side by the Rotary Encoder flush with the board instead of vertical like the other side.  This makes it easier to use the encoder, and allows any 'gadget' to be plugged in on either side without having to wire them up for a specific side.  

One thing I found was that the only I2C LCD display I had on hand was only a 8 x 1 display.  It worked for the initial test but have a couple 16x2 on order.  Now to get started on putting together the ESP32 version and then building a couple 'gadgets' to check them out with.