Sunday, July 29, 2012

Replacing a Beard Trimmer Power Supply

Recently while using my beard trimmer it completely died.  Over the last couple of weeks I had noticed it getting weaker and thought that the batteries just weren't taking a full charge any more.  It was a year old after all.  Then I remembered that I hadn't seen the charging light come on for a while, which led me to believe that the power supply may be dead.  After checking with a multimeter I was proved right. 0 volts on the output.  The easiest way to fix it would be to get another power supply, but because of the way the charging station is designed that's easier said than done.

VS Sassoon VS7836A igroom
VS Sassoon i-groom

The charging station for the i-groom is just a holder for the attachments and is used to retain the end of the  power supply.

igroom base station
i-groom base station

Because the charging station uses the plug from the power supply as a integral part of the design, I can't replace it with just any power supply.  I would have to find an exact replacement or use the lead I had.  After looking around on-line and checking Cash Converters I came up empty.  My only option was to use the original cable and get another power supply.

igroom base station
Removing the plug from the base station

igroom base station
The plug that fits the base station

The requirements for a replacement were reasonably basic.  All I had to find was a power supply that could output 1 Amp at 3 volts DC.  I didn't have any power supplies on hand that fit the specs so I decided to buy a new one.

SW-030100AU power supply for igroom
Dead i-groom power supply

The easiest way to go about doing this was to go to Jaycar and buy a multi voltage power supply for $25 that could output 1 Amp.  $25 may seem like a lot to fix something worth $65, but I use these things all the time, so even after the beard trimmer dies the power supply will still get plenty of use.

Jaycar Multi-Voltage Switchmode Power Supply MP-3312
Replacement power supply

Getting the charger up and running again was the easiest part.  After cutting the lead off the old power supply I soldered an in-line socket on the end of it making sure to pay attention to the polarity of the wires.  The polarity isn't really that important, but I wanted it to be the same as the original.  Once that was done I selected the adapter for the power supply that fit my socket, set the output voltage to 3 volts and hooked everything up.  Easy

Repaired igroom power supply
The repaired set-up

If you've never used a power supply with a range of output connectors you may be unaware of a small problem that commonly arises.  You tend to lose the connectors you're not currently using.  I usually get them mixed up with connectors from other power supplies.  I've found that the easiest way to deal with this is to put all the excess adapters in a bag and cable tie it to the lead of the power supply.  Obviously if you're constantly changing adapters this wont work, but in a situation like this where I may not change the plug in the next year it's perfect.  Honestly, I don't know why there isn't a place on the body of the power supply to store the left over adapters.

Extra plugs attached to the lead of the power supply
Extra plugs attached to the lead of the power supply

Just to make sure I know what voltage to use in the future, it's a good idea to label the new lead.  One way to do this is to get a piece of heat-shrink, write all the details on it and use it to cover the in-line socket.  It gives good results and makes the final product look a little more complete. If you want to get really fancy, print the information on a piece of paper, place it on the lead or plug and use some clear heat-shrink to hold it in place.  I've used this method before when installing a network.  It allowed me to tell what cable went to what room.

Power supply information written on the heat shrink
Power supply information written on the heat shrink

Wednesday, July 18, 2012

Estimating AWG Wire Sizes

Sometimes when designing, you just want a quick estimate of a measurement.  It hasn't got to be exact, it could be 50% off, but at least it gives you some idea as to what you'll need and if your whole project is viable.  For example, let's say you have a sensor in a remote location and it draws a reasonably constant amount of current.  How do you go about sizing up the cable for that design?  What do you need to consider?  This is where estimation comes in handy.  If you can estimate the cable size quickly you can decide if powering the sensor remotely is feasible.  It may make more sense to power it locally and have a cable for just the data signal.  You can work through the actual maths of the situation later but at least you can make a fast informed on the spot judgement.  The following rule of thumb are useful in such situations.

Remembering wire sizes and resistances can be difficult, but this technique makes it a breeze.  You only need to remember the number 17.  I told you it was simple.  It turns out that copper cable with a cross sectional area of 1 square mm has a resistance of approximately 17 milliOhm per meter.  So the resistance of a cable is equal to 17milliOhm per meter divided by its cross sectional area in square mm.  Now by coincidence it turns out that 17 gauge wire has a cross sectional area of approximately 1 square mm.  Combine that with the fact that as you decrease the gauge by 3, the cross sectional area of wire doubles, you can come up with the following rule.



Rule of Thumb   Copper AWG 17 wire has a cross sectional area of 1 square mm and a resistance of 17 milliOhm per meter.  Doubling the cross sectional area of the wire will decrease the gauge by 3 and halve its resistance.



Using this rule will get you half way there.  You still need to make sure that the cable is capable of carrying the current you specify.  As a general rule, the absolute maximum you should pass through a copper cable is 10 Amp per square mm.  This would be for a single cable in open air. As soon as you have more than one cable or you enclose them in a conduit, you need to decrease the current in the cable to stop it from overheating.  A pretty safe amount of current to run through a cable is 2.5 Amps per square mm, but depending on the size of the cable and where it's placed you may be able to get away with a more or less current.  To show how to apply these rules to real world problems I've included an example below.



Example 1    I have a sensor at a remote location with 60 meters of copper cabling connecting it back to a base station.  The sensor draws a load of 100 mA and is connected by AWG 25 cable.  The supply voltage is 12 Volts but the sensor can work with as little as 11 Volts.  Is the design feasible?  If not, why?

Answer 
1.     Start by working out a scaling factor for the cable.  AWG 25 is 8 gauges away from AWG 17.  Every time you increase the gauge by 3, you double the resistance, so increasing the gauge by 8 is equivalent to doubling the resistance 2.66 times.  This gives a scaling factor of 2 raised to 2.66, which at a quick guess is approximately 6.

2.     Check if the cable can carry 100mA.  AWG 17 can safely carry about 2.5 Amps, applying the scaling factor means that AWG 25 can carry about 400 milliAmps.  Therefore the cable can carry the current.

3.     Check that the voltage drop in the cable isn't too high.  Calculate the resistance of the cable, remembering that there are 2 cables, one supplying the current, and one providing a return path for it.

AWG 17 cable is 17 milliOhms per meter.  Multiply this by 6 to give a cable resistance of about 100 milliOhms per meter for AWG 25

R = 2 x 60 meters x 0.1 Ohms per meter = 12 Ohms

Calculate the voltage drop in the cable

V = I R = 0.1 Amps x 12 Ohms = 1.2 Volts

This leaves only 10.8 Volts to power the sensor, which isn't enough.  To solve this problem a larger cable would need to be used.



As this is just an estimation tool, you'll still need to perform calculations to get an accurate set of numbers, but this will however get you in the ball park and allow you to know if your design is heading in the right direction.

Saturday, July 7, 2012

Sorting a Word List by Syllable with AWK

Download the Word List Files

Recently I've been thinking about changing my domain name to something more technology oriented and less personal.  I never intended to use my name for this site, my first priority was just getting something on-line, then I could worry about choosing the perfect domain name later.  There's only one problem with selecting a new site name, when it comes to things like this, I've got the creativity of a piece of mouldy toast.  So to help me along I thought I could use a bit of computer assisted inspiration in the form of a word list.

Before coming up with a name I already had a bit of an idea of what I wanted.  Preferably I'd like it to be 2 words, with a total of 3 or less syllables.  The last letter of the first word needs to be different from the first letter of the second word.  This prevents having a situation where double letters occur and makes it easier to communicate the site verbally.  For example if I said my site was "hot tech" would you type "hottech" or "hotech".  So basically I want a simple name that is unambiguous to type.  Perfect examples being adafruit, sparkfun, and makerbot.  These names are simple, have impact and hard to type incorrectly.  So that's what I'm trying to achieve.  I'm also trying my hardest not to do some lame rip off of something already out there, for example "arcjoy" instead of "sparkfun".

With these requirements in mind I thought that a good place to start would be a list of words that also indicated how many syllables are in each word.  The closest I could find was a word list from Project Gutenberg.  It's a list of words from the Moby Project with each word split into syllables by a delimiter character.  It's not perfect but it's massive and reasonably easy to work with.  The file does need to be processed slightly to make it more usable.

Unsurprisingly, this task is most efficiently done using the Linux command line and awk, a tool that can read files 1 line at a time and allows you to process them by breaking them up into fields.  So let's get started by downloading the file.  I'm going to demonstrate the commands using a small 10 line snippet from it.  When processing the actual file, commands were redirected to files.  Firstly we'll run a command to display all of the non printable characters.  This will show the line ending and delimiter characters.

cat -v mhyph.txt

linux cat command
display non-printable characters

The first thing you may notice is the ^M ending of the lines.  This is the control code for a carriage return and indicates that the file is formatted for windows.  To process the file with awk it needs to be converted to UNIX format, which only has a newline character at the end of a line, Windows files have a newline and a carriage return character.  If the carriage return isn't removed awk will interpret it to be part of the last field.  Printing this field would then return the cursor to the start of the line, leading to unexpected results.  The sub command of awk can be used to find and replace the carriage return characters at the end of lines (which can also be represented by \r) with nothing.

awk 'sub("\r$", "")' mhyph.txt

linux awk command
removing the carriage return character

We'll now run the cat command again to inspect the delimiters.

cat -v mhyph_unix.txt

linux cat command
Identifying delimiters

The documentation states that the delimiter is represented by the ASCII character 165.  This can be identified in the file as as an M code with the characters M-% representing ASCII character 165.  Calculating an M code can be done by adding 128 to the ASCII value of the character after the dash, in this case the ASCII value of % is 37.  Adding 128 to 37 gives 165, or 0xA5 in hex.

I'd like the format of the final output file to use only readable characters, so I'm using different field separators.  Each line will contain three main fields separated by an underscore character.  The first field will be the number of syllables in each word, the second field will be the actual word, and the last field will be the original word split into syllables using an equals sign as a delimiter.


The next step is where we actually process each line and is reasonably complicated.  In the "begin" part of the command we set the field separator to 0xA5, this lets awk know how to separate the input.  The output record separator is also set to nothing instead of the default new line character.  If this wasn't done a new line would be inserted after every print statement.  The next part of the command prints NF followed by an underscore, this is the number of fields in the input, which is the number of syllables in the word.  A for loop is then run which prints each field in the input. This prints the word, but removes the delimiting characters. An underscore is then inserted.  Next another for loop is run which does basically the same thing, except it prints and equals sign after each field except the the last field.  A new line character is then printed to finish off the line.

awk 'BEGIN{FS="\xA5"; ORS="";}{print ((NF) "_");  for (i=1; i<=NF; i++) print $i; print "_"; for (i=1; i<NF; i++) print ($i "="); print(($NF) "\n"); }' mhyph_unix.txt

linux awk command
Processing the file

Now we have a file that contains a list of words with their syllable count, along with how the word is broken up.  Using the sort command we can sort the file by the number of syllables in the word while preserving order.  The -t option indicates the field separator, -k1,1 tells sort to use only the first field to determine rank, -s makes sure that order is preserved, and -n specifies that when sorting, treat the field as a number.

sort -t _ -k1,1 -s -n mhyph_count.txt

linux sort command
Sorted file

The following command will filter the previous results for words with 2 or less syllables as this is all I'm after for my application.  Using awk, we set the field separator to an underscore character and print the second field if the first field is two or less.

awk -F _ '$1 <= 2 {print $2}' mhyph_count_s.txt

linux awk command
Words with 2 or less syllables

To increase the usefulness of this file and to aid creativity it would be better to randomise the file.  That way similar words will be split up and adjacent words will be dissimilar.  This can be done simply with the sort command and the -R option to randomise the sort order.

sort -R 1n2.txt

linux random sort command
Randomised word list

There you go, a randomised list of words with 1 or 2 syllables.  Easy as that.  I don't know if this will help me in my search for a domain name, or inspiration will just hit me and I'll come up with something.  I not even sure that I'll change it yet.  It's a bit of a hassle.  Even if this doesn't help I can still see uses for this list in other places, maybe coming up with pass phrases or even generating a random Haiku.