Category Archives: Uncategorized

Class D Amplifier is Working

A few posts ago I mentioned that I was having trouble with my Class-D amplifier design. It’s been sitting on the shelf for a few weeks and I think it’s time to have another look at it.

It’s amazing how you can notice new things when you take a fresh look at something. The problem is obvious now. I was missing a ground trace which introduced some noise into the input. Also the input impedance was way too high which made the amp very sensitive to that noise. The result was some nasty buzzing and it had nothing to do with the power supply as I first thought.

So now it’s working. Yay! I also upgraded it to the Texas Instruments TPA3110 which is completely pin-compatible and has 15 Watts of power. My ears are suitably hurting after running some tests at full volume and it didn’t even get warm.

So next I need to correct the PCB in light of these changes and it is done.

Synchronize two video replays using Javascript

Here’s a quick Javascript I whipped up to make an HTML5 video object track a second HTML5 video object. I needed to do this because I had two videos from a talk – a video of the speaker and a video of his powerpoint presentation, both as MP4 files.

This script will trap events from one video window and pass them on to the other window so they stay in sync with each other. I’m posting it here because it may be useful to someone…





HTML5 Synchronize Video Test




UI Horror Story of the Day

I finally got around to upgrading to Dev Studio 2010 Express. It looks nice so far but I don’t know whether to laugh or cry at the number of fundamental UI mistakes they have made with the documentation system. Have Microsoft learned nothing about user interface and user experience in the 18-odd years they have been developing Windows? I’d like to take this blog post to list some of the issues with this software.

Now in previous versions of Dev Studio, if you wanted to look up the manual for a key word or library function, you placed your cursor on the name and pressed F1. So wanting to know how to create a fixed array in C#, I typed the word ‘fixed’ and pressed F1. Did I see the documentation? Nope.

What I did see was a dialog box asking whether I’d like to look up the documentation on my local machine or on the internet. I wish I’d taken a screen-shot of that dialog box because it was an absolute classic of bad design but I can’t make it appear again. Once I’d chosen, there was no way to go back to it and make a different choice.

UI Lesson #1: Let the user go back. People make mistakes, if it is possible to undo, then allow it.

 

The choices on the dialog were “YES” or “NO”. Um, does that mean yes, look it up on the internet or no, don’t look it up on my local machine? Heads I win, tails you lose. Bad choice of wording for the buttons.

UI Lesson #2: Label your dialog buttons with verbs – SAVE / DON’T SAVE is easier to understand than YES / NO

 

So I took a punt on NO which it turns out meant loading the documentation from the local machine. Well that’s OK, it should be faster loading locally right? But then again, should I care where it gets the documentation from as long as it gets it. Microsoft is interrupting my work flow. I just want to see the documentation, right now.

UI Lesson #3: Don’t interrupt the user’s work flow unless you have a very good reason.

 

So next it goes about setting up a small web server on my PC so it can serve up the documentation in my browser. Takes a few seconds but that’s OK, except – get this – it doesn’t work! I get a 404 error! I did take a screenshot this time:

 

So what this is telling me is that there is no local help! And the software was too brain-dead to realise it.

UI Lessage #4: If you can automatically check something, don’t make the user manually check it!

 

There is no way I am going to spend time installing the local help on my PC. Remember what I want to do is view the help, not dink around with my computer all afternoon. So of course I now choose to look for the help online. So I click the link and…

 

UI Lesson #5: Honestly, just think!

 

I cannot believe how utterly broken this is. I think I’ll go look up my keyword on Google.

 

Incompatible Objective-C types initializing struct

This bizarre iPhone compiler error message had me tearing my hair out this morning. I’ve finally figured it out.

Here’s the scene: You have two classes, each class has an init method with the same name and taking the same parameters. Here’s an example:

@interface myClass1 : NSObject { }

-(myClass1 *)initWithName:(NSString *)name;

@end

@interface myClass2 : NSObject { }

-(myClass2 *)initWithName:(NSString *)name;

@end

Now try to initialize an instance of the first class:

myClass1 *c = [[myClass1 alloc] initWithName:@"Fred"];

You get Incompatible Objective-C types initializing ‘struct myClass2 *’, expected ‘struct myClass1 *’ which doesn’t make any sense because the initializer never even mentions myClass2.

The thing is that the program will run fine, it just gives this warning at compile-time because the compiler can’t tell the difference between two different methods with the same signature. I like my code to compile with no errors and no warnings because I’m very fussy. So even though this warning could be safely ignored, it still bugs me and I have to get rid of it!

So to shut the compiler up, I need to cast the object so it explicitly knows which method to call.

myClass1 *c = [(myClass1 *)[myClass1 alloc] initWithName:@"Fred"];

Casting always looks ugly to me but that’s the way around it.

NMEA Checksum Calculator

I’ve been doing a lot of GPS work lately. Here’s a little utility I wrote which I’d like to share with you all. It’s an NMEA checksum calculator written in PHP.

Try it out here: http://siliconsparrow.com/demos/nmeachecksum.php

Here’s the source code:


NMEA Checksum Calculator

// Simple NMEA Checksum calculator by Adam Pierce
// Created 12-Jan-2012.
// This code is public domain. Copy & share it all you like for any purpose.

if(array_key_exists('nmea',$_REQUEST))
{
$nmea = $_REQUEST['nmea'];
print "

Calculating checksum for: ".htmlspecialchars($nmea)."

rn";

$checksum = 0;
for($i = 0; $i < strlen($nmea); $i++)
{
$c = substr($nmea,$i,1);
$n = ord($c);
if($c == '$')
$checksum = 0;
else if($c == '*')
break;
else
$checksum ^= $n;
}
print "

Checksum is ".dechex($checksum)."

rn";
}
?>

Enter an NMEA String:


Replicating ASCII Database to UTF-8 in PostgreSQL

Well here’s a curly issue I blundered into today. I was trying to replicate a Postgres database from an old server to a new one using pg_dump/pg_restore and found some errors like this:

invalid byte sequence for encoding "UTF8": 0x92

After some investigation it turns out the older version of Postgres defaults to ASCII encoding of the data wheras the new version of Postgres defaults to UTF-8. Of course I would much prefer to use UTF-8 but shouldn’t those two encodings be compatible anyway? UTF-8 is supposed to be backward-compatible with ASCII.

What happened is a few non-ASCII characters got into the database. 0×92 is not a valid ASCII code. It is a code from Latin-1 encoding. This was in the database thanks to my business partner who was entering some crap into the database using a Macintosh which wasn’t following the ASCII standard so much.

So how to solve it?

First I did a plain-text export of the database on the old server

pg_dump -Fp my_database > mydatabase.sql

Then I converted the encoding to UTF-8

iconv -f 8859_1 -t UTF-8 mydatabase.sql > mydatabase.utf8.sql

Finally I imported the converted data into the database on the new server
createdb my_database
psql my_database -f mydatabase.utf8.sql

And then I wrote a blog post so I’d remember all this next time the issue comes up.

Macro Photography with a Phone Camera

Here’s a real easy way to do close-up when you’ve only got a phone. All you need is a loupe which is a magnifying lens inside a tube, they are used a lot by jewellers, artists and well, people who work in micro-electronics like me. Just plonk it over the lens of your phone’s camera and away you go! Use lots of light to get a good sharp image.



Here’s a frozen pea! well, why not?

And of course, the real reason I want to do this – closeups of circuit boards.

Boxes boxes boxes

I’m developing a couple of new electronic products and once again I am infuriated by the lack of suitable enclosures. Don’t the enclosure making people understand what I want?!

Take a look at these fairly typical boxes from Hammond Manufacturing:

A lot of the boxes produced by Hammond and such companies tend to have small front panels and a long body. But the reality of modern electronics is the circuitry is very small. It is the connectors, display and controls which take up the most room, so what you really want is a short body and a large panel. When I use these boxes, I end up wasting a lot of space as you can see in this photo of one of my prototypes, more than half the space in the box is unused because I need a front panel large enough for all the connectors.

I have spent days searching through the websites of every box manufacturer I can find but they are all more or less the same. I am currently investigating the economics of getting some custom plastic boxes made. I’ll post more here as I make progress.