Showing posts with label relays. Show all posts
Showing posts with label relays. Show all posts
0

Blog posts are just like buses...

Posted by Chris on Saturday, May 09, 2009 in , , , , , ,
...you wait for ages for one, then three come along at once.
Just a quick note to say that, despite there being no blog updates for a while, it's not all ground to a halt here at Nerd Towers.

After the success (mostly) of the USB relay switching device I've been inspired to help out with a project for Steve at www.botbuilder.co.uk, which is a USB-driven multiple-servo controller.

Simply put, to drive a servo, you need to send a signal pulse to the servo every 20ms or so (50hz) the duration of which must be between 1ms and 2ms.
A 1ms signal means "0 degrees" (or -90 if your zero position is half way between the two extremes). To move the servo to 90 degrees (or its mid-point) a signal of exactly 1.5ms must be sent, and a signal of 2ms represents "fully extended" or "180 degrees" (or 90 degrees if you're working from -90 to 0 to 90).

Many PICs have a PWM (pulse-wave-mode) module built into them, and some even have two or more. But very few (if any) can support up to 16 servos.
Allowing for errors, and a signal pulse time of 2.5ms per servo - remembering that each servo must have a signal sent to it every 20ms at most - the maximum number of servos that a PIC can control, serially, is 8.
(servo 1 takes 2.5ms, followed by servo 2, another 2.5ms, followed by servo 3 etc...)

8 x 2.5 = 20m/s.

And on top of all this, your PIC is running at 100% capacity - there's no room in there for receiving data requests to update the position of the servos.
So I'm trying to recreate PWM using an 18F series PIC, but using timer1 to create interrupts to drive all servo pins high at the same time, then use some form of offsetting to drive them low again after a period of time between 1ms and 2ms.

Look out for some Oshonsoft PICBasic code shortly (if I get it working!)

0

My first project - finished! (nearly)

Posted by Chris on Wednesday, April 29, 2009 in , ,
Well here it is, my first USB-driven device, all soldered up and ready to go.
In case you're wondering, it's a (USB-driven) relay switching device but also has the facility to receive switching instructions via serial communication (so it can be connected to a PC serial port or perhaps even a radio receiver).


Almost there - a few terminals to connect to the common and NO/NC switches on the relay, and some decoupling capacitors to keep the supply voltage from dipping, and I think we're done!


After quite a bit of discussion on a couple of electronics forums, and some help from electro-tech-online, I discovered a couple of interesting things about switching relays. First off, PIC microcontrollers aren't powerful enough to drive a relay coil - you need to use a transistor to provide power to the relay, and use the PIC signal to switch the transistor "on" and "off". Secondly, when using transistors like this, the switching should be done on the 0v side of the coil - not as I had originally done, on the 5v side of the coil. Because relays can generate back-emf when the coil is switched off, it is also necessary to include a "flyback diode" to stop reverse voltage spikes from frazzling the other components on the board, when the relay is no longer energised.

One of the most important things I learned was that I'm rubbish at soldering component parts, but not bad at soldering DIP holders and chips (with plenty of liquid flux thrown around the place). So for each relay that was to be switched, I eventually (after three/four different PCBs were made up and soldered - badly) discovered the ULN2803A chip, better known as a relay-driver. This includes the transistors and reverse diodes as part of the package so simply put, you can send a PIC signal to one pin and connect the relay contact directly to the other side - no need to mess about with any other component parts. This not only reduced the component count on the board (reducing cost to make!) but made the PCB layout quite a bit simpler - and the finished soldering look much, much neater!


Soldering the pins on IC chips is a doddle - quick and easy does it. Soldering little fiddly things like transistors and diodes can be a pain. Stick to IC (integrated circuit) blocks were possible!


Another important lesson was the difference between "sink" and "source" switching.
The ULN2803A can only sink voltage - i.e. it must be connected to the 0v rail - each of the relays is permanently connected to the 5V supply voltage and the relay-driver chip connects the relay coil to ground. It simply doesn't work the other way around: if it took 5V and switched it to drive the relays on and off, this would be "sourcing" and not "sinking" the voltage.

All in all, quite a lot learned. Most of it, to be honest, relearned: I'm sure I learned a lot of this in school, many years ago - but the old adage holds true - use it or lose it. I'm quite enjoying rediscovering things that at the time I thought were a waste of time and useless!

Following on from this, I think I'm shortly in for another whole world of hurt, after reading this post about switching 240v appliances. I know that my board needs A LOT more decoupling, but it's nice to hear the faint click-clack of the relays in response to a few bytes of data sent from the PC. Maybe I'm just a few days behind everyone else working on a similar idea....

whos.amung.us

Copyright © 2009 .Nerd Club All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive Supported by Blogger Templates.