Tuesday, January 24, 2017

Back to working n the Spectrum Analyzer UPDATE 2/4/17

Now that the BITX is nearly finished, I decided to get back to the Spectrum Analyzer project.  I had did some work on the display and controller using a Arduino Mega and a  3.2" , 320 x 480 display.  It worked well, but was quite large, and the display covered most of the pins on the Mega.  I found a little smaller  2.8" .320 x 240 display that uses a SPI interface instead of a parallel interface.  I wired this up with a Teensy LC micro-controller and started writing some graphics routines.
I decided to keep the waveform display as 300 x 200 to give room for text and cursor values.  The 300 pixel width will work well to give overlapping display ranges in a 1,3,10,30 format.Since the overall range will be around 100 db, using 200 vertical pixels will make it easy to display wave-forms to a .5 dB resolution.
Because I want to have various sweep widths available, I will store the acquired data in a large integer array of 900 elements.  Using this format I can allocate data as one large sweep, or several smaller ones.  Then by designating the starting point in the array and number of points per sweep, I can store multiple sweeps in the same array.  The wave-form drawing routines will work the same way, specify starting point in the array and number of points to display.
 I will be using the same basic data format for storing the acquired data as in the SNA Jr.   The AD8307 log detector has around a 90 dB. dynamic range, and I want to have a 0.1 dB resolution.  I store the data as the dB. value times 10, so all the display routines can work on integer values.  Since I want to have several switched  10 dB attenuators in the system, this will make it very easy to correct the data values.  Just add or subtract 100 to the value to adjust up or down 10 dB. as attenuators are switched in or out.

 To test out the drawing routines, I initialized the array with a triangle wave with values equivalent to 0 to -100 dB.
Then in a loop I display several wave-forms based on that data. These wave-forms start at different points in the array, and display different sweep widths. I am very happy with the display speed I get using the 48MHz. 'Teensy LC', compared to what I had with the Nano in the SNA Jr.  Next to work on the basic controls and menu system.

UPDATE 2/4/17

Did a little work on  the waveform drawing routines to limit to waveforms to the 200 x 300 pixel drawing area.  I plan on using a cheap joystick for the input device instead of a rotary encoder.  Re-wrote a joystick routine I had been working on.  It reads the joystick pots and switch, then sets a flag if a change has occurred. 
It also sets some global variables with the values of these changes,
I use + or - 1 for horizontal and vertical movement depending on direction.  Also set values for either a short or long press of the push button.  I found this to give much faster and easier control than I had with a rotary encoder.
I had been using a 'Teensy'instead of the Arduino Mega that I had started with. I recently bought several cheap stm32 boards I purchased on eBay.  I wanted to see how this ~$3 board compared to a $13 'Teensy'. Speed at 72MHz. is more than adequate for my needs.  It has 8K of SRAM and 65K Flash memory, also enough for my needs.  I pulled out the 'Teensy' and wired in the stm32 board ( usually called the 'blue pill' on the stm32 blogs).  It is just a little bit larger than the Teensy, but brings out more I/O pins.  As they come, they do not have a Arduino compatible boot loader installed.  Programing must be done through a serial converter or a STlink programmer, about $3.  I used the STlink method, and found it very easy and fast.  I changed the Adafruit graphics driver to one modified for the STM processor.  Everything worked as well or better than with the 'Teensy'.  I wrote a little display test routine to scroll through the initialized data buffer.  Scrolling was very smooth with no flicker or hesitation.  By changing the increment I used to step through the data, I could change the rate of scrolling.

All in all I am very pleased with the results, and looks like I will be using the 'blue pill' instead of the 'Teensy' 

A picture of the bread-board using the 'blue pill' with the display running. The stm-32 'blue pill' is just a little bit bigger than the Nano  on the other side of the bread-board.    For about the same price and much more powerful, this might be my choice for any new projects.


  1. I'm watching this project with interest DuWayne. Please keep us all informed as you progress.
    Tony G4WIF

  2. I get Invalid address on attachment on my iPhone

  3. Hi DuWayne, I wonder if it will be possible to use it with a PC screen as well? 73, Caglar

    1. Still thinking about it. I will see if I can use the Specan software from Farhan. Might not be at first, but would like to add the capability some time.