Homebrew Embedded DSP - PCB In Progress

Post Reply
VK2DDS
Frequent Poster
Posts: 114
Joined: Wed Aug 03, 2011 7:04 pm

Homebrew Embedded DSP - PCB In Progress

Post by VK2DDS » Sun Feb 17, 2013 1:24 pm

I guess this is the right section for this, happy for the admin to move the thread.

I've been interested in embedded DSP for a while but haven't wanted to splash out cash on a proper DSP development board so I had a crack at making one using easy to find/implement components. The goal was to see how much could be done with cheap components with the hope of making something useful that was easy for the casual homebrewer to reproduce.

The system blocks are:

Anti-alias filter -> MCP3201 ADC ($3.61) -> ATMEGA168P @ 20MHz (~$6.50)-> MPC4822 dual DAC ($4.20) -> Reconstruction filter (not yet built, see text below)

Total parts cost is about $15, depending on how many resistors/caps/op-amps are already on hand, prices are single unit quantities from Element14.

The anti-alias filter is two cascaded 3rd order Chebyshev filters (3dB passband ripple) built from a sallen-key topology (calculator here: http://sim.okawa-denshi.jp/en/Sallenkey3Lowkeisan.htm). The signal is biased to about 2V as the ADC/DAC operate on a 4.096V reference which is internal to the DAC. Since it's a dual DAC one of them is set to full scale in software and its output used as the voltage reference on the ADC.

To select an ADC I just searched on Element14 for 12-bit ADCs in DIP packages and sorted by price, the MCP3201 was the cheapest one with AU stock. Same deal with the DAC.

The ATMEGA168P was used because I had some lying around. It is defiantly NOT a good choice for a DSP calculations, the Microchip 16-bit dsPIC range would be the best I know of in a DIP, but I don't have a programmer or any experience with them. The best processor I know of would be a Texas Instruments Piccolo F28069 USB dev board (available from Element14 or Ti estore) which has an 80MHz 32-bit floating point processor on it.

Despite using a poor choice of CPU I managed to get it doing filtering with 3rd order elliptical IIR filters. Normally IIR filters are considered highly numerically unstable unless high precision calculations are used, but I managed to get them working using 32-bit fixed point arithmetic. A single filter calculation uses about 1500 cycles on the AVR, leaving enough for an envelope follower based compression as well! To make these calculations as accurate as possible the 12-bit ADC value is left shifted 4 times so the calculation has a 16-bit dynamic range. After the filter calculation it's shifted right 4 bits to remove the gain and numerical noise in the lower 4 bits. The filters were designed using the ellip() function in MATLAB/Octave, the coefficients it returns were multiplied by 2^16 for the fixed point calculations.

The (poorly commented) source code can be found here: http://www.fireflydesign.net.au/DSP.c

The large string of NOPs in the main idle loop are to reduce sampling jitter. With just while(1){} in the idle loop the compiler produced a single rjmp instruction. This takes two cycles to complete, if the timer interrupt triggered at the end/start of this instruction it started on the next clock cycle. If, however, the timer interrupt triggered half way through the rjmp instruction there would be a clock cycle latency on the interrupt service routine. This was fairly random and caused significant sampling jitter which increases the numerical noise floor. Adding a large number of NOPs reduces the jitter as the probability of the ISR triggering during the rjmp instruction is very low.

EDIT: Forgot to talk about the reconstruction filter. Instead of building one in hardware I did a LPF on the recording. For ham radio work the radio's ceramic IF filter will remove the high frequency (>4kHz) content.

Enough waffle, have some demo videos. If anyone wants more documentation (ie: a schematic and implementation notes) I'm happy to prep the documentation.

This video is a voice demo, the one below is synthetic signals.


This is the most up to date video, it shows all the currently implemented features:


Overall description and filter demonstration


Compression + filter demo, this is the setting I'd like to use on air


Enhanced compression, I fixed a few numerical issues so the compression was a bit less noisy and doesn't overflow/clip in this video
Last edited by VK2DDS on Sat Mar 02, 2013 5:56 pm, edited 3 times in total.

VK2DDS
Frequent Poster
Posts: 114
Joined: Wed Aug 03, 2011 7:04 pm

Re: Homebrew Embedded DSP on the Cheap

Post by VK2DDS » Thu Feb 21, 2013 9:14 pm

No interest? I've been working on it a fair bit this week, today saw the introduction of input/output VU meters:



There's not also a pot which sets the compression point/gain/amount/whatever, next in line are pots to set gate level and compressor release time. I'm yet to think of a good way of selecting the high pass filter, currently there's 3 programmed, plus pass-through, so a 2-bit number is set with DIP switches to select it. I feel this is a rubbish user interface, hopefully something better can be designed and more filters programmed. I'm thinking perhaps 1/8th octave steps from 100Hz to 1kHz, maybe 32 different filters.

User avatar
VK4GHZ
Forum Diehard
Posts: 1879
Joined: Mon Jul 04, 2011 10:39 pm
Contact:

Re: Homebrew Embedded DSP on the Cheap

Post by VK4GHZ » Thu Feb 21, 2013 10:40 pm

Brenton, a great looking project. :D
It's always a good feeling seeing a breadboard design come to life.

Video is hard to beat these days, to show things off, eh!
Thanks for taking the time to do this, and always a refreshing change to put a face to a callsign... it shows real people make things happen.

Are you planning to have PCBs etc available?
Adam, Brisbane
http://vk4ghz.com | VK4GHZ on Youtube

10 things that happen when you stop checking Facebook constantly: http://tiny.cc/t5h7cz

User avatar
VK3ALB
Forum Diehard
Posts: 1250
Joined: Sat Dec 22, 2007 3:56 am
Location: Geelong

Re: Homebrew Embedded DSP on the Cheap

Post by VK3ALB » Fri Feb 22, 2013 8:35 am

Excellent work Brenton.

To my ear the 300Hz HPF sounded just about right. On the topic of filter selection, as these are normally set & forget functions you might investigate using mini rotary switches that are adjusted with a screw driver. Whilst having 32 filters might be good in the testing phase most of them will probably not be used. It's probable that 95% of users will use a small range of settings. Depending on the kinds of switches you can get, 8 or 16 filters my be more appropriate. In the case of bypass/through switch, I think a simple push on/push off action would suffice.
Lou - VK3ALB

I'll decide how I enjoy my hobby.

VK2DDS
Frequent Poster
Posts: 114
Joined: Wed Aug 03, 2011 7:04 pm

Re: Homebrew Embedded DSP on the Cheap

Post by VK2DDS » Fri Feb 22, 2013 9:06 am

Hi Guys,

Thanks for the encouragement!

This project is being developed under a Summer research grant at uni and since I haven't spent any of my supervisor's money yet I'm going to ask him to approve a PCB run. Furthermore, as a student I keep all the IP, so there's no issues with me selling kits or designs.

At this stage I'm planning on using 4 PCB mount pots to set op-amp input gain, compression level, compression release and gate level. If people think that setting a 3-way DIP switch to a binary code to select a filter isn't a big deal then that's the easiest way to do it! There's still a fair bit of tweaking to go, dropping the noise floor, maybe choosing better op-amps (they were 20c for a quad package) etc, but the basic design and algorithms are up and working.

No doubt there will be more updates in the next week or so.

User avatar
VK3ALB
Forum Diehard
Posts: 1250
Joined: Sat Dec 22, 2007 3:56 am
Location: Geelong

Re: Homebrew Embedded DSP on the Cheap

Post by VK3ALB » Fri Feb 22, 2013 9:33 am

Hi Brenton,

It's a really great project and I see plenty of potential. Since you're still in the design phase there's a couple of things you may want to consider (perhaps you already have?) when laying out your PCB. Look at the standard plastic and metal boxes available from Jaycar and Altronics and consider how the board would fit into those. Also is there a way to lay out the board so all the pots & switches can be adjusted without pulling the cover off the box? Will the board be small enough to retrofit into a rig? Will that effect the board layout?

I know these are all obvious questions but I'm reminded of a club project produced some time ago that was a great idea but because of the board layout didn't end up being as neat as it could have been. Small thing I know but something that could have been easily avoided at layout time.

Carry on, you're doing a great job.
Lou - VK3ALB

I'll decide how I enjoy my hobby.

User avatar
VK4GHZ
Forum Diehard
Posts: 1879
Joined: Mon Jul 04, 2011 10:39 pm
Contact:

Re: Homebrew Embedded DSP on the Cheap

Post by VK4GHZ » Fri Feb 22, 2013 10:45 am

VK3ALB wrote:... Look at the standard plastic and metal boxes available from Jaycar and Altronics and consider how the board would fit into those. Also is there a way to lay out the board so all the pots & switches can be adjusted without pulling the cover off the box? Will the board be small enough to retrofit into a rig? Will that effect the board layout?
This sounds familiar!
I was in Jaycar last week, and did just this - started buying cases for a future project to see if LCDs, keypads and switches can all be mounted to the PCB, and fit within the enclosure.

Double sided PCBs are easy to design up and get professionally made, so the hassle of chemicals of etching your own becomes debatable.
With enough development effort (and we can see this going on), you can go from breadboard, straight to a production PCB.

Are those LM3914/LM3915 LED drivers?
Notice you are using discrete LEDs. What about the bargraph modules?
RS have them (cheaper than Jaycar too) http://australia.rs-online.com/web/p/le ... s/7192399/
Would make construction easier, but one colour.
It would be a nice visual touch to have, say, low level Green LEDS, through Yellow, with Red being peak level, as per pro VU metering.
They must be around, as per this item http://www.ebay.com.au/itm/VU-30seg-66m ... 232836bb88
VK2MEV wrote:... If people think that setting a 3-way DIP switch to a binary code to select a filter isn't a big deal then that's the easiest way to do it!
You might be surprised, but some people just can't their head around BCD and HEX numbering systems.
What about a BCD PCB rotary switch?
(There are HEX versions availble too, if there's room for an extra bit HEX PCB mount rotary switch.)
These are pretty cool, not overly expensive, and the end-user doesn't need to think about 1-2-4-8 at all.

With clever design, PCB mounted sockets, switches, and LEDs, it could mount inside an enclosure, with minimal internal wiring required - a bit like today's modern transceivers.
VK2MEV wrote:No doubt there will be more updates in the next week or so.
It's fun and rewarding developing a project from complete scratch.
Keep at it.
VK3ALB wrote:Carry on, you're doing a great job.
+1
Adam, Brisbane
http://vk4ghz.com | VK4GHZ on Youtube

10 things that happen when you stop checking Facebook constantly: http://tiny.cc/t5h7cz

VK2DDS
Frequent Poster
Posts: 114
Joined: Wed Aug 03, 2011 7:04 pm

Re: Homebrew Embedded DSP on the Cheap

Post by VK2DDS » Fri Feb 22, 2013 11:59 am

Thanks for the input, you've both raised issues which I hadn't considered before. My PCB experience has centered around getting maximum performance in mixed signals RF circuits, so I'm fine with calculating microstrip impedances, keeping analogue and digital ground planes separated etc but not very experienced at making things user friendly.

It's very easy to post images of a prototype and get feedback, certainly designing around an easily available box size etc is something I hadn't thought about. Past projects have either been unmounted (build, show an academic, forget about) or at most included some 3mm holes in the corners for screwing to a bit of timber.

The LEDs were chosen because I had a bag of ~100 handy, certainly an 8 segment module with VU appropriate colours would be sought after for a kit version. The driver chips are 8 bit latched serial to parallel shift registers (4094), the VU level is calculated in software.

Rotary hex encoders are a great idea! I didn't know they existed and would certainly make the UI much easier.

One idea for the PCB would be to have all the chips etc located on one side and the rotary encoder, pots and LEDs on the other. It could then be mounted with small standoffs so that the pots are flush with the lid of the case, allowing easy adjustment with a screwdriver. I'd also like to have a switch to disable the LEDs as their power consumption is about 5mA per LED when lit (~90mA when all lit), the rest of the circuit (op-amp, CPU, DAC, ADC) only uses 35mA!

Edit: From a popularity perspective what do people think about using an SMD microcontroller? Atmel's 32bit chips are available for ~$10 and run up to 50MHz and include fixed point DSP operations. The performance improvement over the 8-bit chip I'm currently using would be insane BUT they're not available in DIP. I'm thinking something like: http://au.element14.com/atmel/at32uc3b1 ... dp/1715454

Edit 2: Damn, my programmer (AVR ISP Mk ii) doesn't support the 32-bit range. The uni has AVR ONEs which do, but they're $600 or so and I'd rather not be dependent on the uni's gear. There are some AVR xmega chips I can use though, still SMD.

User avatar
VK3HZ
Forum Diehard
Posts: 464
Joined: Sat Apr 02, 2005 4:52 pm
Location: Melbourne, Australia
Contact:

Re: Homebrew Embedded DSP on the Cheap

Post by VK3HZ » Fri Feb 22, 2013 3:19 pm

Good on you Brenton.

I've always enjoyed realtime programming. I spent a few years programming Motorola DSP-56000 series DSP's (quite a few years ago!) developing things like an ultra high-speed (for then) modem using an array of processors.

For the Atmel processors (which I believe are head and shoulders over PIC's), get an AVR Dragon board: http://www.atmel.com/tools/avrdragon.aspx
Not only does it handle just about every Atmel processor (8 and 32-bit) but it supports SPI, JTAG and other programming and debug modes.
Cost only about $80 including shipping: http://www.mouser.com/ProductDetail/Atm ... tIZaKRJg==

Regards,
Dave.

VK2DDS
Frequent Poster
Posts: 114
Joined: Wed Aug 03, 2011 7:04 pm

Re: Homebrew Embedded DSP on the Cheap

Post by VK2DDS » Fri Feb 22, 2013 4:09 pm

Hi Dave,

For the most part I agree with you on PIC Vs AVRs. However, the dsPIC range offer much higher DSP performance (16-bit, multiply-accumulate instructions, 40MHz, I2S etc) in a DIP. Unfortunately there isn't a free c compiler for them (free versions are crippled, optimisations are turned off and the like) so I'm not considering them.

What I might do is get this project to a "finished" state with the ATMEGA168P and 12-bit ADC/DAC and then look into developing a more powerful 16-bit* DSP later on. Although not ideal the AVR does, in fact, get the job done. Furthermore, The single unit price from DigiKey is only about $2.50, so a small run of kits should end up quite cheap and be totally through hole.

*16-bit referring to the ADC/DAC resolution, for a more powerful project I'd probably go for a 32-bit floating point CPU like the Texas Instruments C2000 Delfino/Piccolo series.

VK2DDS
Frequent Poster
Posts: 114
Joined: Wed Aug 03, 2011 7:04 pm

Re: Homebrew Embedded DSP on the Cheap

Post by VK2DDS » Sat Feb 23, 2013 10:42 pm

Ok, the progress over the last few days has mainly be on UI. I decided against the hex rotary encoder because a pot is cheaper, so it's now got 64 different filters controlled by an ADC input. The 4 pot controls are now compressor gain, compressor release time, gate level and cutoff frequency. In addition there are two jumpers which control the filter, one turns it on/off, the other selects a 3rd order (18dB/octave) or 2nd order (12dB/octave) filter. The advantages/disadvantages of each are described in this rather lengthy ~15min video:



This video only shows synthetic test signals (tones, ramps, white noise), a video with real voice testing will come later.

VK2DDS
Frequent Poster
Posts: 114
Joined: Wed Aug 03, 2011 7:04 pm

Re: Homebrew Embedded DSP on the Cheap

Post by VK2DDS » Sun Feb 24, 2013 1:19 pm

Another demo video, this time with my voice as the input. The whole video uses audio which has been put through the DSP.


VK2DDS
Frequent Poster
Posts: 114
Joined: Wed Aug 03, 2011 7:04 pm

Re: Homebrew Embedded DSP on the Cheap

Post by VK2DDS » Fri Mar 01, 2013 11:20 pm

Quick update: First draft of the schematic is completed: http://www.fireflydesign.net.au/VoiceDSP.pdf

It's not very easy to follow, but shows the scale of the project to experienced eyes. The main modules are:

-Mic preamp (both electret and balanced (pro audio) mic inputs are available)
-Anti Aliasing filter (6th order Chebyshev, 3kHz LPF)
-ADC/DAC
-ATMEGA168 CPU
-Output buffer and reconstruction filter. Sockets are provided for unfiltered audio (ie: direct to radio) and filtered (ie: to headphones for monitoring)

The PCB draft should be done tomorrow and I'll get the tech staff at uni to mill it next week.

VK2DDS
Frequent Poster
Posts: 114
Joined: Wed Aug 03, 2011 7:04 pm

Re: Homebrew Embedded DSP on the Cheap

Post by VK2DDS » Sat Mar 02, 2013 5:42 pm

Prototype PCB layout is complete, I'll submit it for milling on Monday and hopefully have a working prototype for JMFD.

Mounting holes/PCB size is designed for Jaycar ABS enclosure HB-6130 (or HB-6132). Space on the right side is for an XLR socket and battery pack (6xAA recommended), it is designed to operate from about 6.5V (lower limit of TL074 op-amps and 7805 dropout) up to 30V, although I haven't calculated the thermal limit on the regulator, power consumption can be up to about 100mA with all the VU meter LEDs on so the practical max input voltage is probably significantly lower.

This is what the PCB looks like, top view with bottom layer preference:
DSP_bottom.png
Top view with top layer preference:
DSP_top.png
Board size is 195x120mm, rough component count is 48 capacitors, 58 resistors, 17 LEDs, 9 ICs and a handful of plugs/sockets/pin headers.

VK8DOD
Forum Novice
Posts: 47
Joined: Thu Dec 16, 2010 7:38 am

Re: Homebrew Embedded DSP - PCB In Progress

Post by VK8DOD » Sat Jan 16, 2016 10:39 am

Brenton, have you dropped this project off it's website or too busy with Uni right now ? I'd like to get access to your code, but the page is offline.

Post Reply