Current Updates

This blog is an informal, and sometimes intermittent, record of my MEng project.

Tuesday, 24 January 2012

Hardware Homework, plus "Using the Right Tool for the Job" Lesson

This morning I actually looked at the gparted output from last week.  The 1.93GB used on the disk looks very promising if the system is to be transferred onto a 4GB compact flash card.



Memory
For those that are unaware, flash memory has a finite number of write cycles before the memory cells stop working reliably (everything wears out eventually, but flash chips will wear out noticeably quickly compared to traditional hard disks).  Operating systems (especially Linux) tend to do a lot of writing to files, for example logs, paging areas and temporary files.  This will cause quite a bit of wear to the flash disk, so I did a little digging, firstly to find out about swap space - primarily, how to stop using it!

When an operating system begins to run short of physical memory, it begins to 'swap' some memory pages out to 'virtual memory' on disk to make room for more data.  While ideally this won't happen until it really needs to, there is no guarantee against it unless the swap system is disabled.  Before making such a rash change, it's a good idea to understand what the system might do.

It turns out that linux can use swap files and swap partitions.  Swap files are ordinary files used as a swap area.  Swap partitions reserve a specific portion of the disk instead, which can make them more effective.  Additionally, the hibernation facility in linux can only work if there is a swap partition which is large enough to hold the entire RAM contents.  It's useful to know some of these things.

If 'free' is typed at a terminal, it's possible to see how much physical and virtual memory is in use, and a certain degree of detail is given - when I checked, the robot wasn't using any swap space.  When it's running some control software, it may be worth checking this again to determine what effect disabling the swap file might have.

Additionally, it's possible to change the behaviour of the virtual memory system - a 'swappiness' value controls how aggressively the kernel will swap memory out to disk.  This might be useful as a 'soft' test before actually disabling the use of a swap area.

On top of disabling the swap area, to work effectively on a flash disk it would probably be necessary to investigate the behaviour of other disk-intensive programs.  Looking up the workings of a Live CD might be a good starting point, as it allows the system to work from a read-only volume.

Microcontrollers and Motor Controllers
At last, I've finished looking at ICs (for now).  Comparing the ATmega series of AVRs (from Atmel) with the PIC18F series, the AVRs win every time, or so it seems.  One of the 'biggest' ATmega ICs is the 1284P.  It has 128kB program memory (I think that's 64k words), 16kB of SRAM, 6 PWM channels, 8 ADC channels, and 2 UARTs.  It's only £4.55 from RS, and clocks up to 20MHz.  Most register instructions take a single clock cycle, while memory operations take two.  This is in contrast to the PICs, which take four cycles for just about everything, and usually run about the same clock frequency.
Another difference worth noting is that the AVRs have 32 general purpose registers, and most operations are orthogonal with respect to these.  There are a few exceptions, but this really looks to beat the PIC's single working register into the ground on just about any operation.  Add to that the signed/unsigned multiplier (the PIC only does unsigned, and you need to write the values to special registers and read the result back again), and I think the AVR has already won.  At a glance, it also looks like it's not got any nasty surprises like the odd output-only or open-collector pin, like I've seen on some PICs in the past.  The pinout even looks sensible.  I think I'm getting this chip!

I've definitely settled on the L298 as the motor control IC.  It's more than capable of dealing with the 1.3A stall current per motor (it can cope with 2A per bridge, continuous), and has separate 'enable' inputs, so you get PWM control of all functions.  It's designed to be equipped with current-sensing resistors, and seems to be used by numerous projects that can be found online.  This came out somewhere around the £5 mark as well, and is available in vertical or horizontal Multiwatt-15 packages, or as a 'power' surface mount IC.

I had a glance at USB to serial (RS-232 at TTL level) converter ICs.  I think FTDI makes just about all of these, and they're about £4.59.  They need a few passives around them, and optionally a serial EEPROM to hold extra configuration information.  The idea here was to leave a space in the PCB for one, if I don't want to add one right away.  The TTL serial side gives the added bonus of removing the need for a level converter.

Using the Right Tool for the Job
It doesn't matter how many times you tell yourself or someone else this.  At some point, you will try using the wrong tool for the job, because you couldn't find the right one, and "it'll be fine".  In this case, it was for the new Mini-ITX mounting holes I was creating.
Originally, I'd intended to drill down about 5mm into the top of the chassis (not right through) at a 2.5mm diameter.  This could then be tapped to an M3x0.5 thread, which the posts would screw into neatly.  Drilling the holes wasn't a huge problem at all (though I don't think they were very straight: lesson part I - remove everything and use a pillar drill.  Don't wimp out and use a pistol drill, unless you're a pro).

When it came to tapping, however, I had a problem.  No 3mm tap in the set.  Couldn't see any obvious boxes with 3mm taps in them.  Solution: use a 3mm screw (it's only aluminium, it'll be fine...)  Screw gets hard to turn - use 5mm spanner and hex post.  Hex post shears off.  Drill hex post out.  Hole usable.  Now find a 3mm tap.  Success.  Insert tap carefully with fingers to protect thread.  Tighten with tap wrench, which is obviously far too big.  Pull threads out.

I managed two of the holes with threads intact.  I decided this wasn't good enough, drilled through the chassis at 3mm, and attached the posts with screws from the bottom.  Not quite so neat, but it'll do for now.

Lesson learned.  Again.

This does have the added advantage of allowing the entire board stack to be removed from the bottom, by undoing just four screws.  I didn't see this immediately, but felt quite let down that the original spirit of being really neat had gone.

No comments:

Post a Comment

Comments are moderated. Sometimes it might take me a long time to get round to it, so please be patient.