Friday, December 31, 2010

Sneaking in the Build Environment

Wife and kids are now occupied.. I will sneak in this post...

One of my goals with this project (probably the number two goal after operating "mainly" home built and experimental equipment as my mainstay) is the educational aspect.  A long time ago, before my title was Senior Software Engineer, Software Engineer, Systems Engineer (at previous employer) I was just a "Electrical Engineer" at my first job (previous, previous employer).

At that job, I did some DSP work to control machinery, in machine language/assembly on a 320C50 fixed point DSP.  The company was a small one and could not afford thousands of dollars on tools and "C" compilers at the time (the situation now is much better as some C compilers are low cost or free) so I did NON-adaptive filters for mechanical machinery control.  I was fresh out of school and did okay despite not knowing anything but what I learned in my controls classes (which was strictly linear control.)  Luckily,  most of the DSP algorithms are fairly commonly available.  I enjoyed that but haven't done much since with it except for a very short stint coding VHDL in FPGA's.

Juha has kindly made his code GPL so there is ample opportunity for the members of this project to learn DSP as it applies to radio on small fixed-point microcontrollers.  There is a hell of a learning opportunity here.

You see, my commentary about porting to the PIC32MX (and maybe other controllers) is also about needing to understand the code well enough to be able to do this.  If I do start adding filters I'll document my thoughts on this later...I'm kicking around a manual notch filter for the SDR-Cube by using a 4-tap IIR filter..the thoughts on this are not complete yet as I need to analyze the filter coefficients more to see if I can reduce the number I'll need or to see if I can calculate them in code.

But you can do stuff like add audio filters in the code.  This is the real benefit of the promise of SDR.  I hate the term SDR.. did I say that yet on this 'blog?  You still need the radio hardware component to be a radio.  Until we get 60 MHz+ 32-bit+ A/D's (and D/A's) to get the dynamic range needed for "real radio" (which is like 140 dB) these radios will either be limited in Dynamic range (such as the Flex radios and the SDR-Cube) or flexibility as a hardware filter and AGC circuit is needed to compensate for the 90-110 dB of Dynamic range the current CODEC's have.  There are also issues with the direct conversion zero-IF approach (least of which is the reason for the two I/Q adjustments on the cube).

Anyway I just digressed.  Later I might write an essay on that subject.  If you, the reader is lucky, maybe I wont! :O)

The first step about understanding the SDR-Cube IMHO is to get the source code, the free MPLAB IDE (indirect link.. get most current version from bottom of the page!) and the "Lite" C30 Compiler (go to bottom of the page and download the MPLAB C Compiler for PIC24 and dsPIC v3.25 in LITE mode 
by clicking on the link of that same name) .

Small digression here: Even though dealing with Microchip on a professional level has been light years better than ATMEL (which I actually think has technically better products.. another post if you are unlucky) which is really bad in my experience to deal with (parts never in stock, won't sample unless you are going to use 5000 devices a year, etc.).. with Microchip I do have a major ethical problem with some of the C compilers (or at least the PIC32MX compiler, but I suspect the C30 as well) in that they are based on GCC but somehow Microchip is charging real money for them (*they SHOULD NOT!*).  Luckily, if we can live with optimizations disabled, they now have some free compiler options.  This wasn't the case until a couple of years ago.. and that helps us little guys greatly.

Anyway.. after downloading the nearly 100 Mb of goodness from Microchip,  FIRST install the IDE by using the windows installer.  NEXT install the C30 Compiler.  In it's own directory off of the root C: drive (I use C:\SDR-Cube) unzip the source code.  You will end up with a directory like C:\SDR-Cube\SDR-Cube-Source-v1.0 as the project directory.  Click on SDR-Cube.mcp to bring up the project.  To build, I typically suggest doing a "Clean" first and then doing a "build-all".  The compiler and linker are different versions than is on Juha's desktop.. so you will get a string of error messages that state that the compiler and linker are not found and a suggestion to use the compiler/linker at a different location.  Say yes to all of these!  You should then see a successful compile (one warning in one module, but that's a don't care).  When you are done you should see a screen like this:

Screen shot from MPLAB 8.63 with the "LITE" C30 'C' Compiler

Notice my screenshot shows "PICKit 3" on it instead of "ICD 2".  Yup I have a clone PICKIT 3 coming from China as it has a nice programming pod and cables with it for less money and isn't nearly as ugly looking as the real thing.  It's reported to take Microchip firmware and the MPLAB IDE doesn't know/care.  To change the programmer/debugger all you have to do is go to the programmer tab, change it and then save the project workspace.  You should, of course, save the workspace after you compile anyway so all of those links you fixed by clicking "yes, yes, yes, yes" above stay saved!

I decided to go ahead and spend the $40 on it because I do work with the PIC32MX processors as well, and my little PICPROG type serial and parallel programmers from 10 years prior are getting too long in the tooth to use.

The SDR-Cube has a minimally modified serial boot loader on it (Microchip AN1094).. what this means is that as long as you don't completely hose up the code (it's pretty hard.. I've never done it on my similarly boot loaded PICMX32 MX440 CUI32 (sparkfun) and MX460 UBW32 (sparkfun) boards..USB HID in the case of the PIC32MX's)  The USB audio example on the CUI32 is interesting.. I wonder if I couldn't make that work as an adapter from a "soundcard" in Windows to direct digital input on the cube (the "digital NUE-PSK port)... so many projects/toys.. so little time... I digressed again...

Anyway what that means is that you CAN play with the code (add your callsign to it.. a change filter coefficients from the standard or add more) without a programmer.  Just a serial port.

Pretty cool stuff actually...

One last parting note.. There are a few free coefficient/filter generator programs out there.  I will link the one I was looking for (that I have on my work computer) later as I can't find it.  But this one seems fairly promising as well even though it's not been updated since 2004.  MATLAB and it's free clones have routines to calculate filter coefficients also.  FIR and IIR filters are simply delay lines.. FIR's don't use feedback, IIR does.  A standard Crystal and LC filter literally is an analog version of an IIR filter.  This should get you started...

You don't like one or all of Juha's filters?  Do your own 101-tap FIR and replace his coefficients with your own.  Cool eh?  Want 8 filter selections instead of just four?  It can be done fairly easily.. there are a lot of little tweaks like this possible along with more major things like my idea for a tunable manual notch filter...

No comments:

Post a Comment