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
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.
OK, so it’s not the smallest computer ever, but at only 3mm long it is the smallest computer I’ve ever programmed. This is the PIC10F206 and yes, that’s the tip of my finger it is sitting on.
This little beastie has less than 1k of memory and only runs about as fast as an Atari ST but hey, it’s a real honest-to-god computer and if you only want something simple done, it can be real useful. Oh, and it only costs 70 cents, way cheaper than the Atari.
So what did I use it for I hear you ask? well, I just needed a 40kHz oscillator with some low frequency modulation to make an ultrasonic insect repeller. You could probably do that with a couple of CMOS chips and a ceramic resonator but this solution is cheaper, smaller, uses no external components and I even have a couple of spare I/Os left over to, I don’t know, flash a light or something.
I have been building audio amplifiers for one of my clients for a while now but we’ve been having some overheating issues so I decided to go high-tech, ditch the old-school linear amp and use a class-D amp.
A class-D amp works a little differently from a traditional analogue amp in that it generates a high-frequency square wave which is pulse-width-modulated. This square wave is then put through a low-pass filter to knock the corners off it and you end up with a wave the same shape as the input wave. This is very clever because a transistor is most efficient when it is either fully off or fully on. By avoiding the linear analogue section of the transistor’s range, the power efficiency is very much improved.
After some research I decided to use the TPA3113 from Texas Instruments. I wired this thing up according to the recommended application circuit and it works pretty well. TI claim this device has a power efficiency of 87% and no heatsink is required. I have yet to properly load-test it but my initial tests are very promising.
The only drawback with this part is it’s sensitivity to power supply noise. A little ripple in the input voltage can make for some very nasty buzzing noises so I’m going to have to add some DC filtering.
This picture is of the whole board. The chip on the right is the class-D amp, the other chips are… well, I haven’t got it all working yet so I’ll leave that for a future blog post.