Author Archives: martinjonestechnology

Quick-and-dirty partition resize with Acronis True Image

A little embedded Linux magic comes in unexpectedly handy. Years ago, I started using Acronis True Image to back up my office PC. Other backup packages are available, as they say, but it’s worked well enough for me. This week I had reason to use it in earnest.

img_20180619_112420

The PC is set up with two main partitions on the disk. There’s one for the operating system (Windows 10) and applications, and another with data on it, analogous to the /home partition on a Linux system. Inevitably, it turned out that the boundary between these partitions was in the wrong place. The operating system partition was full, and things were starting to fail. Time to make sure the backup is up-to-date and then to restore to differently-sized partitions.

The operation fell at the first hurdle. Acronis True Image will create a ‘recovery’ USB stick from which the PC boots. This contains a small Linux distribution (Acronis Linux) and a GUI for managing the recovery operation. My backups are on a network drive, which happens to be an Apple Time Capsule. Would the Acronis recovery system connect to the Time Capsule? Would it ever. I couldn’t even persuade it to ask for the username and password, though it could see the Time Capsule on the network.

In Acronis Linux, pressing ctrl-alt-F2 in time-honoured fashion brings up a command line. Yay! Power! A bit of digging reveals a command called asamba which can connect to SMB shares. Using that, I could connect to the Time Capsule absolutely fine and mount it to the local filesystem. So why couldn’t the GUI do it? Annoying.

My next trick was to copy the backup from the Time Capsule to a USB hard drive using another Linux PC. It took a while for the several hundred gigabytes, but it got there. Acronis recovery will read USB drives, so the next step should be easy, right? No. My USB drive happened to be formatted ext4. Though Acronis Linux is perfectly capable of mounting ext4 filesystems, the recovery GUI only acknowledges the presence of FAT and NTFS discs. Aargh!

The solution was to mount the USB drive on my Linux PC, then share it using Samba. Acronis recovery found and let me log on to the Samba share, and could thus see the drive and backups.

Changing the partition sizes was the next problem. The GUI only allows you to shrink partitions or to grow them in to free space. My disk didn’t have any free space. It was all partitioned and in use. I thought that shrinking the data partition would create free space that the operating system partition could grow in to, but I was caught out by the presence of a 500MB ‘recovery’ partition which Windows had sneaked in between the two. I don’t know what it’s for but I didn’t feel like taking the risk of destroying it. There are no tools in the Acronis GUI for deleting partitions and starting again, so I was stuck.

img_20180619_113338

Command line to the rescue! Ctrl-alt-F2 again, and there’s a perfectly good copy of fdisk available. It was a moment’s work to delete the existing recovery and data partitions, then ctrl-alt-F1 to the GUI. Restart the restore process and there’s free space available for the operating system partition to grow in to, and plenty of room to create new recovery and data partitions.

img_20180619_112939

The restore took a few hours, as expected, but was successful. The only wrinkle was that Acronis recovery had marked the recovery partition as active rather than the boot partition, so the PC complained that there was no operating system. Another trip in to fdisk to mark the boot partition active sorted that out, and now I’m typing this very text on the PC restored to working order.

Footnote: there is another Acronis restore tool intended for restoring backups to dissimilar hardware. This may have handled the partition resizing more elegantly, but I didn’t try it.

Advertisements

Good accuracy from a low cost Real Time Clock

One product I work on has a built-in data logger. This helps us a lot if a problem occurs: we can see the history of any faults. Every log entry is time stamped, which is important. We need to know when it’s been used and how often. However, good timekeeping is a challenge. The product has no Internet connection, it gets stored and moved around a lot, and it’s nobody’s job to check or adjust its clock, so there’s a real problem with clock accuracy.

The real time clock is based on the Microchip MCP7940N chip. The chip uses a standard 32.768kHz crystal for its timekeeping. These crystals are fickle beasts, partly because of the very low-power oscillator in the chip. The oscillator frequency, which is critical for accurate timekeeping, is very dependent on the load capacitance, which itself can vary with different builds of the PCB. The heat of soldering during manufacture also affects the crystal. I’ve seen plenty which have failed altogether, and others whose frequency has shifted significantly. Note the soldering on the crystal’s load capacitors C9 and C10 in the photo below, part of an attempt to find the optimum load capacitance on a prototype board.

img_20180530_100756

All of these issues mean that just assembling the PCB and hoping for the best doesn’t work well. The frequency of an apparently working crystal can be anything up to 100ppm (parts per million) wrong. That doesn’t sound like much, but it works out to nearly an hour’s error per year, which is pretty bad.

Fortunately the MCP7940N has a neat feature which helps a lot. One of its registers, called CAL, holds a value which speeds up or slows down the clock by a small amount, like the regulator on a mechanical clock. But how do we know what the error is, and whether it’s been successfully corrected?

The MCP7940N also has a pin which can output a 1Hz square wave derived from the oscillator. With a sufficiently accurate timer, it’s possible to measure the error in the crystal’s frequency this way.

Checking the correction is more difficult. Because the chip only works on whole oscillator clock cycles, it does the adjustment to the clock’s speed by adding or removing a few clock cycles each minute. It’s therefore necessary to measure the period of exactly 60 of the chip’s seconds to find out how long its minute is, and therefore how accurate the whole clock is.

Getting a sufficiently accurate timer is the first problem. My aim was to get the MCP7940N to be accurate to within 1ppm, or about 30 seconds per year. A useful rule of thumb in metrology is that the measuring instrument needs to be ten times more precise that the quantity being measured, so we need a timer accurate to 0.1ppm, or one part in ten million. To the rescue comes my trusty Hewlett Packard 5335A universal counter. It’s an oldie but a goodie. Mine is fitted with the optional oven-controlled crystal oscillator, an HP 10544A. I checked it and set it up against a Rubidium frequency standard about 8 years ago and it hasn’t been touched since. I checked it this month against the same frequency standard, and it still agrees to within 0.1ppm. Not bad, and certainly good enough for this job.

Measuring the initial clock error is easy enough: connect the counter to the MCP7940N’s 1Hz output and look at the error. The 5335A counter has handy built-in maths functions to make this easier, so it will directly display the difference between its idea of a second and the chip’s attempt.

To measure the corrected clock output over a minute needs a bit more trickery. The 5335A counter has an external ‘arm’ input, and can average a period reading over the length of the ‘arm’ signal. All that’s needed is to arm the counter for 60 seconds and the counter will do the rest. I couldn’t find a way to make the counter do this for itself, so I cheated and used a spare Arduino mini that happened to be lying around. All it had to do was wait for a clock pulse on a GPIO pin, take another GPIO pin high to arm the counter, count 60 clock pulses, then take the arm signal low. Simple.

The test setup looked like this. The scope is there for ease of probing (note the cable from its ‘sig out’ connector to the counter) and it also includes a Tektronix 7D15 timer/counter module connected to the chip’s output. The 7D15 is a lot less accurate (about 1ppm) than the 5335A but it’s good enough to give an idea of what correction is required. The Arduino mini is just about visible at the bottom of the photo.

img_20180427_171833

Here’s a closeup of the scope screen, showing the measured period of the clock’s 1Hz output, 999.9818ms. That’s just over 18ppm too fast.

img_20180427_171723

This the setup screen of the product, showing the 18ppm correction applied to the MCP7940N’s CAL register.

img_20180427_171715

Finally the error in the measured minute, calculated by the 5335A counter gated by the Arduino.

img_20180427_171823

It’s showing that the corrected minute is 301.3 parts per billion, so 0.3ppm, too fast. That’s as good as it’s going to get – about 10 seconds per year. With the clock set up using this process, it has a fighting chance of staying accurate in the real world.

Hacking child barriers

This post contains no electronics or software, just woodwork.

Our house is full of traps for the inquisitive toddler. There’s cat food and litter, an office full of sharp tools, a fireplace, and most tricky of all, a staircase descending from the corner of the living room guarded only by a coffee-table-height shelf.

Fortunately, there is a handy range of wooden barriers available from various sellers on allegro.pl (search for ‘bramka’ or ‘barierka’ to get started). It’s a sort of modular barrier system, with a basic unit 91cm wide, though other widths are available. The sections screw together with plastic couplings that allow them to hinge. Wall mounting brackets and feet are available, as are sections with a child-proof gate built in. They’re cheap and simple enough that hacking them for specific jobs is easy and worthwhile.

Here’s a set across the end of the living room, protecting the fireplace and cat flap to the garden. These are almost freestanding, but tied to the bannisters at one end with string and blu-tacked to the floor by the window.

IMG_20180311_144905.jpg

The steps up to the office are guarded by these two sections. I added the cat flap in one of them so that the cats can get to their food and litter tray.

IMG_20180318_152052.jpg

The stairs down from the living room are guarded by another hacked set of barriers, cut to length and with an aperture provided for our eldest son’s favourite bookshelves.

IMG_20180311_144822.jpg

I used the leftover upper and lower rails from the segment I’d cut down in length to make a rail to hold the ends of the uprights above the bookshelves. There’s a join in the middle done with one of the plastic hinge pieces and a not inconsiderable amount of wood glue.

The barrier is held up using zip ties through plastic corner blocks screwed to the underside of the wooden shelf top, so the screw holes won’t show when we eventually remove it. Felt pads on its feet stop it scratching the wooden floor.

RIAA phono preamp for Tascam M-1B Line Mixer

In the workshop I have a couple of these Tascam M-1B line mixers. They’re a very useful box: they have eight inputs, each with a level control and pan pot, which are mixed together and fed into a master volume control. There’s also a pair of headphone outputs with their own volume control driven by a headphone amplifier with enough voltage swing to drive 600 ohm headphones properly. Into the mixer I typically feed the sound output of my PC, other audio sources such as a cassette player (yes!), and a spare cable lying around on the workbench ready to connect to whatever I’m working on, or my phone. The output is connected to the workshop speakers. With this setup I can hear all the sources at once without fiddling around, switching anything or unplugging anything.

IMG_0608.jpg

Tascam M-1B Line Mixer

The workshop I set up a couple of years ago turned out to have space for a new audio source: a turntable. Great! I can listen to vinyl (not ‘vinyls’, please). I had a spare turntable on the shelf, so I put it in place. The trouble is, the turntable has a magnetic cartridge which can’t be connected straight to the line inputs on my trusty mixer. It needed amplification and RIAA equalisation. I could have just gone and bought an off-the-shelf preamplifier, but where’s the fun in that? Looking at the back of the Tascam mixer, there’s a blanking plate which looks perfect for adding a preamplifier, neatly built in. No worries about trailing cables or yet another power supply to plug in. Now to find a suitable circuit.

IMG_0609.jpg

A quick web search pulled up an application note from National Semiconductor for their LM833 audio op-amp which shows a simple preamplifier circuit. It then goes on to describes the circuit’s deficiencies and how a two-stage design can improve on it, but I decided to stick with the simple version.

I didn’t have any LM833 op-amps in the spares box, but did have some NE5532s, which are not only an excellent audio op-amp but live two to a package. Finding the passive components in the spares box also proved to be a challenge. Getting the right component values is one thing, but finding two identical ones of each proved to be impossible. However, all was not lost, so I thought. The RIAA equalisation curve needs three time constants, of 75µs, 318µs and 3180µs. I found pairs of resistors and capacitors that gave the same time constants as R1C1 and R2C2 even if their values weren’t what the original design specified. Here’s a circuit diagram with my substitutions marked in red.

riaa-schematic-modded

I built up a small piece of matrix board and tried it out. It worked, but didn’t sound quite right: there was a noticeable lack of bass. I decided to check the frequency response. The application note shows a useful table of the RIAA response at various spot frequencies, so I had something to compare my results with. I used the ARTA STEPS program with a PC sound card to measure the frequency response of my circuit. It took a bit of fiddling with the levels to get good results, since the phono preamplifier has a lot of gain, but the result looked like this.

response-first-attempt

The curve looks convincingly like the RIAA curve, but it should be +17dB at 50Hz (relative to 1kHz). In fact it’s more like +13dB in my version, so I’ve lost 4dB of bass. At the other end of the spectrum it’s more accurate: at 20kHz it’s at almost exactly -20dB as it should be. (Note, when taking readings from the plot, that the level at 1kHz is about -3dB. It’s the relative levels that are important).

What I’d neglected in my component value calculations was that the relative values of the two RC networks are also important. The National Semiconductor application note actually goes on to explain more about this, but I hadn’t read any further than the circuit diagram. Rather than delving in to the maths and risking discovering that I needed more components I didn’t have, I started playing with the values I actually did have. Here’s a plot of the before-and-after empirical results.

response-first-and-second-attempt

The green curve is the modified version. The level at 50Hz is now +17dB relative to the level at 1kHz, as it should be. Below 50Hz there’s a bit of a rolloff, but that’s not something I’m worried about – my speakers don’t go down that low and it makes for a useful rumble filter. The modified circuit is shown here.

riaa-schematic-modded-v2

I had to change both RC networks to get a good result. The time constant of one of them (11k/6n8) is still 75µs, but the other (180k/22n) is more like 4000µs than 3180µs. I suspect it’s interacting with the time constant of R0C0 to give roughly the right result.

IMG_0616.jpg

It fits neatly in to the slot in the back panel of the mixer. The toggle switch connects the output of the preamplifier to inputs 1 and 2. Switching it off leaves those inputs available for normal line-level use if desired. There’s also an earth terminal.

IMG_0617.jpg

Time for some testing. What were the skies like when you were young?

IMG_0621.jpg

The Euroquadruped, or the solution to wall wart Tetris

Having relocated from the UK to Poland, the change in mains plugs has never quite been resolved. All the equipment that came from the UK has 13A plugs on it, and all the local sockets are the CEE 7/5 type. Then there are locally-acquired bits and pieces  which generally have two-pin Europlugs. No matter how many adapter cables and extension leads I make, or change the plug or socket on, there’s always something that doesn’t fit, or won’t reach the nearest compatible socket.

Of particular annoyance are various chargers and wall warts. They’re all bigger than a standard Europlug, and there’s no standard for which way the ‘lump’ of the charger will be attached, so connecting several of them in to a multi-socket extension lead doesn’t work well. Often one charger will obscure one or more sockets in such a way that all the things you need just won’t fit, or the whole assembly becomes so big and unwieldy that things start falling out under their own weight.

It is therefore with some relief that I announce the debut of the Euroquadraped: one 13A plug with short cables to four Europlug sockets. It reminded me of an octopus but only has four ‘legs’, hence the name.

IMG_20180211_221335.jpg

Getting all four cables in to the 13A plug was a bit fiddly, but choosing a roomy plug helped. The little Europlug sockets are neat. I’ve only seen them here in Poland. The finger ring to discourage pulling on the cable is a nice touch, and doubles as a cord grip internally. They even (finally) have safety shutters on the socket holes, roughly 60 years after shutters became standard on the British 13A socket…

The great advantage of this thing is that each socket is independent of the others and can find its own equilibrium with whatever electrical carbuncle is plugged in to it.

IMG_20180211_221527.jpg

It’s trivially simple, but it’s going to save a lot of frustration in the workshop.

Canon S100 Shutter Button Fix

This is my Canon S100 digital camera. After long, somewhat arduous service, the shutter button started playing up: it would focus but not take the photo. Eventually I got a mobile phone with a better camera and quietly forgot about the Canon. The S100 has been extensively frozen, boiled, soaked, rattled and trodden on, so I figured that the shutter button problem was just due to the abuse. It doesn’t owe me anything. However, it’s still useful for some things the phone camera won’t do: it fits a tripod, and has good long exposure and manual control facilities including a handy neutral density filter.

IMG_20180204_165606.jpg

Trying to use it to take some tricky oscilloscope photos the other day, the shutter button got really annoying. I searched on line for the problem and discovered that it’s quite common. That sounded like an interesting problem to me. Here’s my attempt at fixing it.

Before we start, don’t try this unless you’re used to dealing with annoyingly tiny things and have the tools to match: jeweller’s screwdrivers, tweezers, a very fine soldering iron and either amazing close-up vision or a good magnifier.

The camera comes apart surprisingly easily. There are six little black screws on the outside: two on each end and two on the bottom, close to the tripod mount. Take those screws out. The back comes off very easily – take care not to lose any of the buttons though.

IMG_20180204_165751.jpg

The front also comes off easily, though there’s a little FFC connector to the setting ring round the lens. Unplug it carefully. It doesn’t have a locking bar so the flex PCB just pushes in and out. There’s also a foam gasket round the lens and the plastic cover for the HDMI and USB sockets. They’ll fall on the floor.

IMG_20180204_165854.jpg

The shutter button and other controls are underneath the top cover. There are two more screws to remove: one on the front near the lens and one on one end. They’re different lengths so take note of where each came from. Before removing the top, there’s one more FFC to unplug. This one connects to the microphones. Again it has no locking bar so just pull gently. It’s the middle of the three FFCs in this photo.

IMG_20180204_170148.jpg

With the top cover off, the controls themselves are revealed. On the left here, the function selector rotary switch, then the shutter button and zoom switch, then the power button, and on the right the big square thing is the GPS antenna.

IMG_20180204_170233.jpg

If you put the battery back in, the camera actually works fine in this dismantled state, so it’s easy to try experiments. I prodded and poked the shutter button. Sometimes it worked, sometimes it didn’t. I doused the button with my favourite contact cleaner (DeoxIT D5) to no avail. I looked on the web for replacement buttons: “double action tactile switch” seemed to be the best thing to search for. There are lots out there which might fit, but they’d take a while to get hold of and would be really fiddly to solder, especially with the zoom switch so close by.

I wondered about a mechanical solution, extending the plastic rod from the outside shutter button that presses the switch to give it more poke, but sometimes the switch just refused to work no matter how hard I prodded it with a screwdriver, so that probably wasn’t worthwhile.

Given that it wasn’t worth spending a lot of time on what’s effectively a life-expired camera, an alternative engineering solution was called for. The first stage of the shutter button, the half-press to lock the focus and exposure, still works reliably. What if I just wired it in parallel with the shutter release contact? Then there would be no way to lock the exposure and focus, but at least the camera would take photos.

Some fiddly soldering with a fine iron bit and some polyurethane-insulated mod wire later, the two opposite corner contacts on the button are connected…

IMG_20180204_172823.jpg

…and the S100 lives again. It’s not a full fix, call it a workaround, hack or bodge, but it’s good enough for me to take pictures. Oh yes, and assembly, as somebody once said, is the reverse of disassembly.

Garage door opener life extension

This little thing is really annoying. It’s the remote control for our electric garage door, and I use it several times a day to get my bike in and out. Luxury, pure luxury. Or it would be, if it worked properly. The trouble is that about half the time after pressing the button, it locks up, stuck either on, with its little red LED lit, or off, so it won’t open or close the door, and drains the battery. The only way to fix it is to pull it apart, take out the battery, and put it back in without losing any of the bits of plastic. You can imagine how much fun that is with gloves on, in the rain, when you’re in a hurry. Yeah, yeah, first world problems, I know. But there doesn’t seem to be any way of opening our garage door manually, which is a nuisance.

IMG_20171215_155448.jpg

Inside is a little PCB containing a PIC12F635 microcontroller and a simple 433MHz transmitter circuit using a couple of transistors and a resonator. I did all the obvious things: replace the battery, clean the board with solvent, all of that. Nothing helped. It seems there’s a bug in the PIC’s software which makes it prone to locking up. The switch under the button is rather worn and thus suffers from contact bounce, and I think that’s what’s upsetting it.

I tried filtering the signal from the button to the PIC with an RC network. That didn’t help: the PIC didn’t even respond to the button any more. Presumably it needs a fairly quick risetime to trigger an interrupt, or something similar.

There is a second button which is less worn. It transmits a different code which doesn’t seem to do anything on our garage door, but it never crashes the PIC. I considered swapping the switches over, but they’re surface-mount and glued down, and the chances of removing both of them and successfully soldering them down again undamaged were slim.

I wondered about rewiring the PCB so that the input to the PIC is always active, and the button just switches the power to the PIC. A quick test by adding a blob of solder and removing and reconnecting the battery showed that wasn’t going to work: the PIC just didn’t transmit. It needed to have the power applied and then have the button activated.

There was another issue to address. The button, when it worked, was prone to getting pressed by accident as the bunch of keys rattled around in my pocket. That led to the garage door opening itself at odd times, which wasn’t great for the security of our bikes. Somehow modifying it to be less prone to accidental operation would be nice. 

Design changes were called for. Since the second button is redundant, I decided to convert it in to a power switch, so it has to be held down while the real button is pressed, and releasing it will guarantee that the power is cut from the PIC so it can’t remain locked up. I cut the power track to the PIC and took advantage of the PCB layout to add a P-channel MOSFET in series with it, then cut the track from the second button to the PIC’s input and wired it to the MOSFET’s gate. The buttons both have one terminal to battery negative. A pullup resistor between gate and source completes the circuit.

IMG_20171215_155001.jpg

Here’s the modified board. You can see the remnants of some of my previous repair attempts, and the extra MOSFET and pullup resistor at top right. Now, to open or shut the door, I have to hold down the button on the right and press the left button, rather like using a shift key on a keyboard.

It seems to work reliably now, so leaving the house and returning are considerably quicker and less stressful. 

Incidentally, I did the repairs and modifications in the office, which is several miles away from the offending garage door. To check that the remote was actually transmitting properly, I used my Tektronix 7912AD programmable digitizer with 7A29 vertical plugin. Originally intended for high-speed laser and nuclear physics research, it’s kind of overkill for testing a garage door opener, but its 700MHz bandwidth is plenty fast enough to get a clear picture of the transmission using just a loop of wire connected to the input. Analogue technology at its very finest. Here’s its TV output connected to a little LCD monitor showing the 433MHz signal from the remote.

IMG_20170814_130325.jpg