Saturday, January 29, 2011

Audio setbacks

Well, I knew I didn't have all of the audio issues worked out, but I didn't know it was this bad.

I finally broke out one of the DS1807 digital pots and got it working.   Some notes:
* I think I have the audio biased around +2.5v correctly.  Even without this the pot works and I don't hear clipping, but it's noticeably better with.  I'm probably still screwing something up here.   No mater what, the audio board layout I've got is definitely wrong and needs a pretty big re-work.
* The zero-point crossing feature of this chip is not working.  I've tried tying AREF to +2.5 as well as to the other end of the wheatstone bridge, but there is still a *click* when level changes.
* My row/column scanning pauses *very* noticeably when writing over the I2C bus.  this means the write is taking a really long time, like 0.5sec.  I should dig into the Arduino Wire library and see what I find;  perhaps I'll need to resort to port manipulation.   I'd rather not :(
* Lighting any LEDs in the matrix causes noise.  Lighting many LEDs causes a LARGE amount of noise.  It seems to go away when I turn the pots all the way down, meaning it's not noise related to the ATMega328 crunching or the shift registers doing their thing...   This is probably good news, as I'll have the LEDs pretty well isolated in the final product.
* Writing over I2C is LOUD.  A half-second of BZZZZT happens on every write.  I am sure there are ways to avoid this, as the DS1807 is primarily intended for audio applications.  I've just gotta get better at isolation and grounding.
* USB noise is still present, especially when I do something graphically heavy on the computer.  I'm encouraged because it was much, much worse before.  I'm assuming this is because components are in different locations on the breadboard now, and that means it's probably fixable with intelligent layout.

In my last post I defined my main issues to be:  snappy display and responsive controls.  I'm adding noise-free operation to this list.

Friday, January 28, 2011

Display test

In the midst of some breadboard work I began to get worried about cycles.   Specifically, I wasn't sure the ATMega328 + arduino bootloader would have enough processing power to do everything I have in mind.    As I see it, the two critical factors are a snappy display and responsive controls.   The LEDs have to be updated at least every 4ms to avoid a strobe effect, and preferably more like 3 or 2ms.  I thought this would be easy with a 16mhz CPU, but some quick tests I ran (with my terrible, terrible code) had me worried;  I was running into strobe territory with a very small number of additional instructions.

So I wired up the whole display section on a breadboard to see if I'm on the right track.   Here's video of an early test.   4 10-segment LED arrays.   Each time through the main loop:
* An analog pin is read 5 times
* The values are mapped from 0-8
* The mapped values are shifted out to the Row and Column registers.
I put a pot on the analog pin so I could wiggle it around and see the results.   I'm relieved to see that there seems to be quite a bit of headroom.   (The flickering LEDs in the upper right are due to me selecting poor cutoff values)



Heartened, I next wired up all 5 LED arrays, and added the extra shift register needed for LEDs 9 and 10.  Additionally, I added the multiplexer I plan to use to switch between each audio input and wired 4 pots to the MUX (didn't have 5 on hand).   In this video, each loop has the following steps:
* The three MUX control pins are set 5 times to select input channel
* The analog pin is read 5 times
* The values are mapped from 0-8
* The mapped values are used to lookup the appropriate LEDs to light
* The looked-up values are shifted out to the two Row and one Column registers 



It appears my concerns were unwarranted.  I know that many of the Arduino functions (like shiftOut) translate to quite a few steps in actual AVR code, so I'm glad to see that I've still got a good amount of headroom after doing so many shifts and reads.  I was able to add up to a 4ms delay on the whole program and it was still quite acceptable.   Hooray.

There's some issues with using the MUX.  When the signal approaches +5v, things get flickery and glitchy. I should probably read the datasheet.  Also, since the MUX needs 3 control pins plus the one output pin AND I'm only reading 5 inputs, I'm only saving 1 pin...   I need to revisit my audio board design once I have a better grasp of the amping and biasing process.  If the signal is already in a happily-readable state before it hits the mux, I'll just remove the mux and run them all right back to analog pins on the arduino.   I just happen to have a single pin free, and this would remove a good number of steps from the main loop. 

I'm still struggling with audio signal manipulation and interpretation.  A couple of halfassed attempts at biasing and amping a linelevel signal produced bupkis.   Perhaps I should read up on what I'm doing instead of taking more shots in the dark.

Sunday, January 16, 2011

Audio Board Again

Spent a few hours today reworking the audio board.   I've learned that digital devices want an audio signal that's not referenced to 0V.   Makes sense if you think about it, they only work in the positive domain, so an audio signal that spends half of it's time below 0 isn't going to be happy.   My current solution is to simply add 2.5V DC to the signal, the 2.5 I was already generating for the inverting input on the single-supply op amp. In theory this will center the signal between ground and VCC.

The latest audio board.
edit: added output caps, fixed input caps.

I also applied my newfound groundpour abilities to the board.
I've got a few little issues on this, but I'm pretty certain I'll be adding a component or two before it's done.

Friday, January 14, 2011

Main Board layout

Now that I have a decent idea of what each subboard will require, I've begun laying out the main board.  It's really just a breakout board for the processor, but I've included the MSGEQ7 chip here too because the audio board is already pretty busy and this will cut down the number of header pins needed.

Front and back of the mainboard

I've learned about ground pours and how to draw them in Eagle.  It's a little counterintuitive at first, but it makes sense once you see it.   This is a good but outdated tutorial. I'm pretty sure I'll have some noise issues once I assemble everything,  but hopefully this will have a positive effect.

In other news, I managed to score $60 credit in Sparkfun's Free Day.  The servers were slammed but mysteriously opened up right at the end, so I only had the chance to answer 6 questions before the money ran out.   $60 in free stuff is awesome, I am definitely not complaining!

Sunday, January 9, 2011

Display layout

While I wait for my USB<->Serial chip to come in I've been working on the display board layout.  Initially I just wired it up and tossed the components on there as I went, and it came out kinda OK I guess
Five 10-LED arrays with resistors and three shift registers to drive them.
The horizontal resistors would have been soldered on the back of the PCB.
But then I remembered that I want the display on the front panel of a 1/3rack 1U enclosure and that (optimistically) gives me 1.35" of vertical space to work with.  Couple this limitation with the 4" width limitation on the free version of Eagle and I simply ran out of room.

My solution (for now at least) is to stack two boards, giving me a poor-man's 4-layer board.  This is very similar to the 'shields' you see available for various pre-made arduino boards.   I separated the bits into display and logic and connected them via headers;  they'll just press together.

In this iteration, all resistors live on the back of the display board, right next to their LED.


The display board has some very, very close traces.  I don't know if this is printable.  I think I'll be using sparkfun's batchpcb.com for this, and possibly for the whole project.   Since they have a (very reasonable) $10 setup fee per board, I may try and have these made as a single board, and just dremmel them apart myself.

In other news, it's finally raining.

Friday, January 7, 2011

The perfect chip.

In the process of researching my audio circuit I came across the perfect chip.  The SSM2163 mixes 4 stereo  signals down to two via VCAs, is controlled via I2C, and even includes it's own Vref generator.   Basically it's my whole audio board in one chip.   It's absolutely perfect, and of course it hasn't been manufactured in a decade.  Apparently it was made by SSM for analog synths, but they were absorbed by Analog Devices in the 90s and AD has no use for the device anymore.

While trying to track down one of these chips I came across a sort of chinese grey market for used and discontinued electronics.   The process was interesting:  I put my email and the part number into a couple of websites and within an hour I had 40+ bids!  The prices did not inspire confidence;   they ranged from $2.50 to $175...  just what am I dealing with?     I eventually threw caution to the wind and made a $20 payment to a company who promised two parts, shipped.  

And then they reply, telling me they're now out of stock.   I kissed my $20 goodbye and considered it a lesson learned, but to my total surprise I was refunded in full.    Hooray for the free market?   For the record, the company was HY (HK) IC LIMITED and 'Julie' handled the transaction extremely well.


After poking around some more I've given up on this chip.  I've already got the DS1807 digital pots, and the hassle of fielding so many offers was quite a bit more trouble than just laying this out in discrete parts.

Wednesday, January 5, 2011

Whoops, that wasn't right AGAIN.

You'd think I'd have learned my lesson by now.  Once again I was fiddling around with power supply (this time I was trying to reduce noise from the USB or computer) and managed to kill my fancy-ass FTDI USB<->Serial chip.  The whole part was $15 (making it the most expensive component in the device, ouch!)  but I can get the chip itself for $4+shipping.   Looks like it's time for another sparkfun order, and then I get to learn how to solder SMDs...

Tuesday, January 4, 2011

LED Matrixes with shift registers

I've learned a bit about LED matrixes in the last few weeks.  Here's a few key points:

* The basic concept couldn't be simpler.   A shift register flips on one column, and another register lights whichever LEDs need to be on for that column.  Then you do the same for the next column.  Do it fast enough and boom hotdog.
* Yes, each LED needs to have it's own resistor.  Otherwise the column will get dimmer as more LEDs are lit. EDIT:  Whoops, I'm dumb.   Since only one column will be lit at any one time,  you only need one resistor per row.
* Many shift registers don't deliver enough current to drive more than a few LEDs.   Ditto for the registers on the cathodes;  they must be able to sink the current for every LED they control without asploding.
There are a few ways around this, but most of them involve transistors.  The low-current register signal flips the switch and the transistor does the higher power work.

I'm planning 5 columns of 10 LEDs.   I don't intend to ever drive the LEDs to full power, as this device is intended to sit next to a television and I don't want  it to be distracting.  With some experimentation I've found that a basic 8-bit shift register will happily drive 5 LEDs per channel at my desired brightness without heating up, so that eliminates the need for a transistor array on the rows.  However, the same registers were not happy sinking the current for 10 LEDs so my columns must be handled differently. Fortunately I'd anticipated trouble here, and put this high-power shift register in my last sparkfun order and it happily handles all 10 LEDs.   Important to note:  this chip will not source current, only sink it.

I'm very happy that I won't need to mess with darlington arrays or anything.   A few hours of digging for a simple cheap PNP array were fruitless.

I'll wrap this up with a video.
Here is the familiar 'count to 255 in binary' program, but the high-power shift register is switching the output between three LED arrays, once per step.   I've slowed the steps down a lot so that they would each be visible - normal column-scanning should happen so fast you aren't aware of it.

Monday, January 3, 2011

Noise noise noise

After sorting out the distortion issues with my single-supply opamp, I thought I was essentially finished with audio quality issues, at least until I started to pack these components closely in an enclosure.   Boy was I wrong.

I've left the core of the mixer circuit breaded and active as I play with the display circuit, and I began to notice some noise.   Then when I plugged the USB interface in, the noise got distractingly bad.  It's definitely some sort of interference that's getting passed down the power or ground lines, and it absolutely has to go.

This has been a more difficult subject to research, mostly because the material I find is largely dedicated to high-frequency and RF circuits, not audio.  One of the first successes was putting buffering capacitors (1uf and 0.1uf) on the voltage-dividing-buffering opamp, between the supply and ground.   This immediately cleaned up all but the tiniest bit of already-tiny noise I was hearing without the USB attached.  (That is mostly the noise from the microprocessor,)   The USB noise is proving much harder to tackle.   A trip to Fry's got me an assortment of chokes and ferrite rings, and I've been swapping them in and out on supply and ground from the USB bridge, with varying success.   The biggest problem is that this sort of interference seems to be very hard to chase down;  just waving my hand over the board makes a difference, and the inherent component-jostling that comes with swapping parts makes for fairly unrepeatable results.   I can't tell if my efforts are making a difference, or if I'm just having a lucky low-interference moment...

I noticed that the USB cable I'm using doesn't have a choke on it.    Since the noise I'm hearing seems to track the computer's activity at least as much as the arduino's, I'll see what a better cable can do.

Saturday, January 1, 2011

More audio board simplification

Right, that was dim.   Instead of sending each L/R signal all the way back to the multiplexer before summing them, why don't I sum them at the source?  boom, 50% fewer long traces.

I really like the clean and repetitive upper portion.   The bottom half is a bit awkward, but by this point it's clear that I'll be making more changes anyhow.