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....

0

The 470 capacitor mystery deepens

Posted by Chris on Sunday, April 26, 2009 in ,
A quick update with progress - the spanky new PCB etched a treat (I found out today that etching boards face down rather than face up takes about a tenth of the time - and if you heat the etching container in a bowl of warm water, the same way you use a bowl to melt chocolate, a full 100mm x 50mm board takes about four minutes to etch. 45 minutes is not normal etching time!)

I mounted the components onto it and soldered everything down.
It was the point of no return now - plugged the board into the USB on my PC and everything still works! It still detects the device as a native USB/HID device and I can enter a VID/PID combination and retrieve data from it. Brilliant.

But here's the weird bit.
I'd used a 470uF capacitor to tie Vusb to ground. Although this was using the wrong units, I assumed that there'd been a typo because on other sites and forums, 470nF was recommended.

Anyway, I bought some 470nF and some 470uF capacitors, as well as some 220nF caps (since some sources recommend 220nF capacitor for Vusb). The crazy bit is that the 220nF capacitor doesn't work: the device appears but Windows says that there's a fault with it. But if you use either a 470uF OR a 470nF capacitor to connect Vusb to ground, it gets detected as a valid USB device. Even though one capacitor is 1000 times the "size" of the other.

I still don't get it, but since 470nF works, and a lot of other sources recommend this value, that's what I'm going to stick with. I just don't understand why 470uF also works.....

0

Press-n-Peel rules!

Posted by Chris on Saturday, April 25, 2009 in ,
After finally getting my native USB device working (yay, still pumped about that one) it was time to redesign the schematic and PCB layout for the proposed project: after all, there's no need for any nasty, fiddly FT232RL chips any more!

The bit of extra board space I gained from removing the FT232RL was quickly taken up by the longer PIC chip, and the additional crystal and capacitors. My board has outputs going to transistors (to amplify the current) so I can switch relays on and off.
Relays = coils = inductance, so I added some diodes to the board as well. All in all, it's getting a bit cramped on there, but with some clever re-routing (and only one "jumper" where I had to break a trace and pick it up elsewhere on the board) I managed to get everything in a 100mm x 50mm space.

I've had differing levels of success with the toner-transfer method of producing PCBs, but none of them 100% successful. Apparently it's all down to the paper type but I've tried four or five different photo papers and all of them leave broken tracks and need touching up afterwards.
Having invested in some Press-n-Peel (blue iron on paper) and reading mixed reviews (some people say it's no better than photo paper) and I pleased to report that it is the dog's doodies. There's no messing about, guessing at when your board is done. You don't need to have the iron on full heat and you certainly don't need to press and press and press for twenty minutes or more!


The image transferred perfectly, leaving a crisp, clean image on the copper board. The camera had problem focussing on the board because of the reflective surface, but the final image is much clearer than this!


Simply print onto the dull side of the paper, cut to size, clean the copper board and iron on as normal. As each of the tracks is transferred onto the copper, it turns a dark black colour on the top (the surface you're ironing over). So it's really easy to tell when the entire image has transferred. It's also easy to see which tracks need a bit more heat, so you can concentrate the iron in just the right places.
When you're done, a quick quench under the cold tap until the whole board is cool, then peel the plastic-coating backing off the board.

The image was beautiful and sharp. There were no broken traces and everything was just as it should be. The backing that came away was a perfect negative image of the board design.


The backing came away easily and was a perfect negative of the image transferred.


I'd read some reviews that said Press-n-Peel was just as hit and miss as other toner transfer methods. The one thing I know is that after tonight, there's no way I'm going back to messing about with scorched worktops and soaking paper for hours and hours: I'll happily pay £1.50 per sheet, knowing that from now on my boards will work first time, every time!


The final etched board.

0

Shadow Robot Company talk at RobotBrighton

Posted by Chris on Friday, April 24, 2009 in
Graham Wiseman from Shadow Robot came to Hove last night, to give a robot talk about robots. And very interesting it was too.

He demonstrated how someone can have an idea, make a series of decisions - in this case, to build a robotic hand using pneumatic pumps to replicate the action of human muscles - only to have each decision reversed, as practical applications are applied! Shadow Robot actually have two types of robotic hand - a pneumatic version (using patented muscle technology) and an electronic version (using motors).

The original idea was to replicate human muscle action, and the pneumatically-driven hand was built. But when third parties started to take an interest, alternatives had to be invented. For example, after getting interest from NASA about sending Robot Hand up into space, it was quickly realised that it's behaviour in a vacuum was unknown! (How would a pneumatically driven muscle operate in a vacuum?).
Instead of going for a hydraulic solution (potential for leakage and maintenance costs I suppose) Shadow built an electronic hand, with an array of tendons driven by 16 motors. Brilliant! That solves that problem. But it caused the project to deviate from the original idea of replicating human-muscular action, and demonstrates how practical applications can dilute even the most brilliant of ideas.
Then when the clever bods from the nuclear industry started sniffing about, they wanted something that could be used in hazardous environments - not something with exposed electronics and nasty sparky stuff. So it was back to the pneumatic hand to supply them with a solution.

It was a shame we couldn't see the hands powered up and actually working, but then again, not everywhere is kitted out with an industrial air compressor - the Werks certainly isn't!

The two hands were passed around and everyone got to push and pull the digits and make the tendons flex. Apparently the robot hands are just as (if not more so) dexterous as a real human hand. I still couldn't get one to hold a barre chord shape.
The weird rubbery surface was warm but clammy to touch - just as if someone had licked their entire hand before offering it to shake.
It was very good of Graham to let the rabble play about with his robots - especially considering that each one is worth £80,000-£100,000. And he also brought the original prototype with him - a fantastic wooden effort, covered in Polyfilla and operated with bits of string. Sellotape and blu-tack held things in place: it looked just like one of my own contraptions!

It must have been quite a scary train ride for Graham, coming from Islington to Brighton on the train, with about a quarter of a million pounds worth of hardware stuffed into his rucksack! Thanks for coming anyway!

0

Would you Adam and Eve it?

Posted by Chris on Friday, April 24, 2009 in , , , ,
After attending the Robot Brighton Shadow Robot Company Talk I had just a few minutes from getting home to retiring to bed (it was gone midnight after all!).
I'd asked around and managed to blag a 470nF capacitor from Kind Steve (and borrowed a PIC programmer from him, just in case mine was playing up: I still didn't know if it was burning hex files onto the 18F series of chips properly) and thought I'd shove it into my breadboard and see what happened.

As I pulled it from it's little plastic bag, I realised he'd given me a 470uF not a 470nF capacitor. It was a big black cylindrical thing, not the little round disk I'd been expecting.

I was about to call it all off and go to bed, when I decided that there'd be no harm in giving it a try anyway, what with him having taken the time to dig one out and bring it with him. So I did. And then plugged in the USB cable.

Nothing happened.
And then this came up:



Wahoo! I finally had a native USB device working!
And just to make sure, I ran the test app that came with the PIC 18 simlulator called hidterminal.
What is does is generate a random 8-byte string and send it to the device.
If you read through the sample code, you'll see that it decreases each value in each byte of the feature code by one, just before the data is sent back to the host (and increases the i/o report by one). From the screenshot below, you can actually see this in action:


The vendor ID was changed to 1221 just to see that a USB device with
any VID/PID combination would be recognised


And all this without having to use a different programmer.
It seems that mine does work with 18F chips, using DonkeyProg after all.
Here's the final schematic for anyone trying to get a native USB device working from a PIC18F2455 controller - don't skimp on any of the parts: they're all critical!



How exciting!
Tomorrow I might just lay out a PCB for it....

0

All those fiddly components are there for a reason you know

Posted by Chris on Thursday, April 23, 2009 in , ,
After several attempts of modifying code and getting nowhere, I followed the schematics on the Oshonsoft website exactly and copied and pasted the example code and burned it all to my 18F2455. I even included the 22pF capacitors across the crystal (not something I usually bother with) just to make sure that the code and hardware exactly matched the working setup.



The only thing I didn't have was a 470nF capacitor to connect the Vusb pin to ground. But then again, it's only a capacitor to ground: it's obviously not that important. Here's the schematic that I sent to Vladimir, author of Oshonsoft's Pic Simulator:



I sent the diagram to Vlad, pleading for help.
What could I have possibly done wrong? It all looks perfect and still my Windows PC can't detect the device (it recognises that something has been plugged in but keeps saying that there's been an error with the device)



I got this reply from Vladimir:

Please take a look at the schematics published on the web site.
There is one critical component missing on the schematics you sent
to me. It is 470n cap from Vusb pin to ground. According to the
datasheet it should be at least 220n value, and its presence is
critical. I hope that fixing this will lead to success!

Good luck and best regards,
Vladimir


I couldn't believe that something as insignificant as a tiny capacitor - which simply connects to ground - would cause the device to run, but not enumerate properly. I did some digging about on the 'net and came across this forum post; it's almost exactly the same problem I was having

http://www.picbasic.co.uk/forum/archive/index.php/t-3724.html

I re-read the datasheet for the 18F2455 and searched for "Vusb". There were references there to tying Vusb to D+ or D- and in a lot of the diagrams it showed Vusb connected to ground through a capacitor (but curiously no capacitance value is shown).
The datasheet does indeed mention 220nF but in his forum post, Robert says:


Robert Hedan - 6th July 2006, 17:14

Thanks to everyone!
I just received my order from DigiKey this morning. The 220pF caps didn't work, despite what the datasheet says. :( But the 470pF worked beautifully, man I'm happy I ordered a set of each, just in case. The device is recognized, YAHOO!!!

Robert
:D


I'm assuming that it's a typo in the forum post and that Robert actually meant 220nF and 470nF, as all other entries talk about nano- not pico- farad capacitors. Time will tell. So it looks like yet another trip to Maplins to try to find some 220nF/470nF capacitors.....

0

Haven't we been here before?

Posted by Chris on Tuesday, April 21, 2009
I bought my full licences for the Oshonsoft PIC18 simluator today and got the version that has USB support. I was a bit sceptical about spending about £70 on something that has a few questions hanging over it, and since yesterday morning have installed, tried and failed to get some code to compile in about four different compilers.
I really like the Oshon software and decided that, for the cost of a pre-build programmer and test board, it should take a lot of the pain out of USB development.
If the examples are anything to go by.
If they work....

I contacted Vladimir and he sent over the USB-enabled version in a few hours.
I compiled the examples from the Oshonsoft website and prepared the hex files for burning to my fancy new 18F2455 chip(s).

Then it all started to fall apart.
I've never had a ROM error before, nor an EEPROM error when writing to the microchip, but got both of those when trying to write to the 18F2455. I found an updated firmware for my programmer (it's a DIY 149-BC off eBay which is suspect might be a chinese clone, but as I bought it second-hand, I'm not sure where it came from). Anyway, for whatever reason, I couldn't get a the hex file onto the PIC18F.
I tried using fixhex2.exe (which comes bundled with the DIY programmer, v2.5) which apparentl is necessary for a lot of C-compiled code which has been targetted for the 18F series. No difference. I tried lots of different code from different sources, using different compilers.
To be honest, I didn't really know what I was doing, but as long as I managed to build a hex file with no errors (and correct fuse settings of course) I figured it should be good to go. But there was no way I could get the hex file to burn.

I lot of hunting around - it's taken two days in total - and I finally came across Donkey Prog which adds 18F support to the DIY programmers.
It even includes a special version of the software for USB-only programmers (which apparently are nothing short of a nightmare to use and write code for) which has special timing code or something which works with some DIY programmers.
Given that the alternative was to abandon the programmer I'd waited so long for, I decided to give it go.

The software didn't work straight away, but the archive zip came with a firmware update - so using my current app microbrn.exe to copy the dprog.hex file onto a blank 16F628A (phew, lucky I'd bought a few of those instead of the beefier 16F877A variants) I disconnected the programmer, whipped out the PIC that was onboard and replaced it with this new one.

Yay! The software recognised the programmer, dropped by sample hex file onto the 18F2455 chip and validated it a treat. I loaded a new file into Oshonsoft 18F simulator, a simple LED blink program, and burned this to the chip.
It worked a treat! So I now had a way of getting hex files onto my 18F2455 chip!

So just give me a couple of minutes and I'll have some USB up and running, surely...
...not quite so fast there cowboy.
As you can imagine, it was not to be - I took the example code from the Oshonsoft website (which Vladimir assures me works) compiled it and burned it to the 18F2455 chip. When you plug in the USB cable, the output LED comes on, the power LED comes on (so I know that the code is running on the chip and the board is getting 5v from the USB port) but Windows fails to recognise the device.
Not in a "ooooh nearly there" kind of way - when it says something like "Device not recognised". I got nothing. Zero. It didn't even bother to throw up an error.
I swapped the D+ and D- wires (that's a sure way to raise a USB error when working with the FT232RL usb-to-serial chip) and plugged it in again. Still nothing.

I suspect it's something simple, like a fuse setting, or an incorrect oscillator setting (or something equally as daft, like a watchdog timer reset, or the mclr not tied to 5v). But for now, it's off to bed again, still without a working USB-based device.
Here's hoping that tomorrow proves to be a little more fruitful.....

whos.amung.us

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