So, the PCBs came. Only after I’d unpacked it to have a peek did I realise the sheer mountain I had to climb. Well, perhaps mountain is the wrong word, because mountains are big. The main microcontroller is tiny. It’s a quad flatpack, 100 pins, 25 a side, on a 0.5mm pitch. That’s tiny when soldering by hand!. I tried a tactic I learned as a student engineer at Seprol. Which basically boils down to coat everything in sight with solder, then wick off the excess with braid, and then gently touch each pin in turn to melt what’s left and ensure a proper bond. After I’d done all 100 pins, I left it for a while. A few nights later, I did all the support components, including the voltage monitor / supervisor, power supply, crystal and RS232 port. So far so good, and special thanks to Gill and Keith for letting me borrow a super duper magnifier to check out the QFP.
With that much soldering done, I decided it was time for a test run, so I hooked up the power supply, and connected it to my PC, and loaded the flash programmer. I was absolutely heartbroken when it didn’t connect, then realised I hadn’t set the PC serial port up in Memtool. After I’d done that, everything worked fine. I could connect to the bootloader on the chip, and erase the flash memory.
Over the coming days, I soldered more bits and pieces down, including a couple of LEDs and a few MOSFETS. One of these, a tiny SOT23 device, is to drive a cooling fan. The idea was to use the CAPCOM unit on the XC164 to drive the MOSFET, so the fan is speed controlled. After writing a short test program, I managed to get the fan to spin at varying speeds. I’ve just tarted up the code a bit, and put upper and lower limits on the speed so that you can’t go past maximum or under minimum. The under minimum is important so that the fan doesn’t stall, but the maximum?
Well, the PWM works on two registers and a timer in the CAPCOM unit. The first register is a reload value and the second is a match value. When the timer overflows, it flips an output pin, and reloads from the reload register. This reload value is calculated to give a period of 1 millisecond. The second register is compared against the timer, but a match only flips the output pin, rather than reloading the timer. So it’s important to ensure that the flip register isn’t set past the flip and reset register, or it won’t work. You can use it to generate interrupts as well, but since I’m only bothered about the fan (and therefore the output pin), I switched the interrupts off.
The advantage of this method is that the modulation is all done in hardware. No software whatsoever, except to turn the fan on and off, and change the speed.
More tomorrow, but I have to go into work for an emergency lighting test, and it’s a 1 hour one… what a waste of time that will be. Might leave the car at the valet place.