Tuesday, December 16, 2008

Switching Regulators, Boost Converters and The IBM Charger

A friend of mine (it would not be right to continue this post without a mention of her) recently gave me her busted IBM Thinkpad charger. Vidya (or nVidiya as I like to call her) said “Do what you want with it, and if you put it to good use, do tell”. The best resting grounds I can think of for damaged things is my desk, where these otherwise never-again-to-be-used-by-mankind objects serve one last noble purpose – be of some use to me! :-)

Let me begin by telling you that IBMs are some of the sturdiest and most durable laptops not just physically, but even in terms of their software; but don’t take my word for it: ask the wall in GH3(B)-108 (my old hostel room) whether it liked being whacked by a laptop; or ask Abhinand (a pal of mine) if his throwing more than two litres of water right on my laptop had any effect on it; you may also like to find out from the numerous girls, who sadly, are computer-not-so-literate (yes, this is chauvinistic, but hey! It’s MY blog), the several times I have rescued their crashed HDDs and run diagnostics of their systems using my trusty IBM R51. I use my IBM for absolutely everything, including my trysts with electronics experimentation, and its motherboard has silently and loyally borne the brunt of 15V to its parallel port, or Vccmax+5 to its USB hub. I love my IBM!

Anyway, after that completely wayward digression let me get back to what I wanted to post about. So this girl, nVidiya, graciously gave me her burnt out charger, which I dutifully took apart after some prying and poking with flat screwdrivers. Here are a couple of images of what the IBM SMPS (Switched Mode Power Supply) looks like from the inside.

In the second image you can see that the inside of the plastic casing is a sheet of copper for improved thermal conduction. You can also see the aluminium heatsinks. The third image shows the circuitry. Visible are the main transformer and some coils, which are all actually very small. The main advantage of switching power supplies is the way they control the average power to a device. The main element in such a power supply is a transistor (BJT or MOSFET or IGBT) that either turns completely ON or completely OFF. In the ON or OFF state the transistor dissipates very little heat, thereby causing very little power loss. Another plus for the SMPS is that it can generate almost any voltage – higher than the input, lower and even negative.

The fourth image shows clearly that the charger is deceseased; may it rest in peace (or, since it's on my desk - rest in pieces!)

So anyway, there's no black magic involved in all this increasing and decreasing of voltages; it is done using a coil. Depending on how the transistor and coil are connected, and where the output is taken from, all sorts of voltages and polarities are possible. Of course, it’s not all that simple. Switching PSUs are some of the most complicated devices, but particularly at high power outputs and in battery powered devices (where high efficiency is the norm) they provide such a huge cost savings as regards lost power that they are ubiquitous in computer peripherals, cameras, UPS systems and almost anywhere else you look.

Here’s the wiki on switching power supplies. Read and be amazed. If you have time do go through TI's very concise reference on switching PSU configurations.

With all these switching power supplies floating around I needed to make one myself. So I made a really simple one, and was thoroughly amazed at the results. It started because I am attempting to make a USB PIC programmer. It is an open source programmer, and details can be found here.

The programmer needs to generate 14V during programming, and with the 5V provided by USB, this would only be possible with a boost converter (which is one kind of switching supply). As its name suggests, the boost converter ‘steps up’ voltage. Do bear in mind that this is DC we are talking about. How do you ‘step up’ DC? Can’t stepping up and down only be done with AC? Aah, now that’s where the switching regulators come in.

Take a look at the circuit below. The transistor is a plain vanilla BC547 NPN. Its base is pulsed through the PIC; so the transistor turns ON and OFF. When the transistor turns ON it pulls current through the coil. The coil creates a magnetic field around itself. When the transistor turns off, the current in the coil rapidly decays; this causes the coil to generate a back EMF ‘kick’. The polarity of the voltage ‘kick’ is such, that it ‘tries’ to keep current flowing in the same direction as it was before the transistor turned OFF. Confused? Just read that line a couple of times. The ‘kick’ is a high voltage and causes current to ‘overflow’ through the diode into the capacitor. This ON/OFF cycle takes place many times a second charging the storage capacitor to many times the original supply voltage.

My circuit looks like this:

Voltage boosting is the very principle used by camera flash units. The Xenon flash triggers only at about 250-400V, and a standard camera has just two 1.5V AA or AAA alkaline batteries (1.2V for NiCd batteries). How do you get 400V when you have just 3V with you? Use a boost converter!

The simple junk-box components boost converter that I made ran off the USB’s 5V and was able to easily generate 60V when loaded with 1kOhm, and well over 130V unloaded (Caution: running an SMPS of any kind unloaded is NOT good practice!).

I have now started winding my own coils. Believe you me, this in NOT a fun task if you have many windings to make with thick wire. In the image below you'll see a few powered-iron toroidal cores.These cores are very good for high value inductances. You'll also see enamelled copper wire, and a few adjustable air/ferrite core coils (used for factory tuning in radio sets). Old radio sets, damaged mobile phone chargers, destroyed UPS systems, and non-functional florescent bulbs (the Philips CFL type) are a good source of coils and coil-making materials.

(If you’re wondering why my images are suddenly better in quality, the reason is that I’m at home, where I have access to my Sony :-) )

Wednesday, November 26, 2008

Of Scopes and SMDs

I've always loved electronics for its 'minuteness'. I'm fascinated, even today, by how small consumer electronics can get. Have you ever opened up your cell phone or iPod and seen the myriad tiny chips and resistors and capacitors and whatnot? And do you realize that what you see is actually not small; it is HUGE when compared to what is on the inside of those silicon chips.

With Intel, using the 45nm process to manufacture its current processors, now talking about switching to the 30nm, and progressing to the 10nm fab, everything is set to get very, very small. The SMD resistors on your Nokia motherboard seem gargantuan in comparison.

Anyway, I absolutely needed to get myself a piece of this deliciously small pie. So in the past few months I've stared working with surface mount devices. Naturally, if I've reached the level where I'm working with SMDs, I would also have reached the level where I would need the services of an oscilloscope. Problem is, an oscilloscope, even a government-office-used, second-hand, two channel, 100MHz scope - the minimum demanded by any respectable hobbyist - costs about 10 grand. 10 grand is something I would like to have, but sadly, I don't. A new plain-jane CRO-oscope is about 25-30K, while (drool) Agilent DSOs start at a prohibitive 70K. Even cheapo entry-level USB oscilloscopes are a minimum of 10K, and to make matters worse, they aren't available in India.

So, like any other respectable hobbyist (all respectable hobbyists have what is called 'electronics-ego' - some may call it a touch of madness, others, an obsession, and yet others, an incurable disease; to hell with you, you vile naysayers! May you all burn!). Umm, yes, where was I? Aah, as I was saying, like any other respectable hobbyist, I decided to go the DIY way, and build my own scope.

The advantages of building your own scope - it's dirt cheap, and you learn a ton of other stuff (analog layout design, ADC nitty-gritties, USB firmware coding, and host data-handling to name just a few).

The scope would follow this kind of layout:

(Analog front end) --> (Data packaging for USB, on the PIC) --> (Host data display)

(Buffer) --> (PGA) --> (Hardware AA) --> (High speed dual-channel parallel-out ADC from MAXIM/TI)

(PIC 18F4550)
-> (8Mbit memory from Cypress, for deep capture)
-> (External trigger sources)
-> (USB2.0 Full speed @ approx 1.2MBytes/sec bulk transfer)


(LabVIEW software frontend)

Upto now I've built, and tested various parts of the AFE - I still need to throw everything together, and see if I actually get the desired results (this, without a doubt, is the biggest thorn in any engineer's side; everything works perfect in the lab, it works well as individual modules, and then, when you try to put stuff together, it all just falls apart. You start swearing and tearing your hair out in frustration; that's the reason why I'm.....uuh, forget it).

Last night (in Sid's words, and CCS-C) I was on cloud [unsigned int8 cloud 0b00001001]. I got USB bulk transfers to work with LabVIEW, albeit, in a crude way. Nevertheless, it worked, pleasing me tremendously. LabVIEW makes development super-easy. Easy, in a way that makes you feel dumb. Amit Sabne, who I've been brain-storming with, puts it very concisely - "Yaar, feel hi nahi aati!" - which is kind of true. The chaps at NI have done a great job of making hardware interfacing a snap. Wait for your USB device to enumerate, enter its VID and PID (device/manufacturer specific 'serial numbers'), throw a few icons and VIs here and there, and voila! You have délicieux transferts de USB bulke, served hot! (yes, translate.google.com is most helpful). The NI engineers have robbed hardware-software hackers from the trials and tribulations of mind-messing driver-writing, back-breakingly long hours of prouring over hardware, and sleepless red-eye-rubbing nights. Damn! Where's the joy and satisfaction if you can do something in 10 minutes, what used to otherwise take hours?

Now that I've got a rough and dirty implementation of PIC to USB transfers to work, what remains is putting it all together. Gimme a few days, and I'll upload the PIC firmware in CCS-C, and the LabVIEW VI here for you to use, enjoy, redistribute!

Monday, November 17, 2008

My वायरलेस प्रेसेंटर

Wow! Hindi transliteration on blogspot! That's an interesting feature! :-) Useless, but interesting, nonetheless.

Just a small point to note: I'm typing these first few lines from 15 feet away, using my wireless presenter. (Big smile :-) )

Naturally, you scoff, "How can you do that? Oh! You have a wireless keyboard! Umm, hang on a sec! You said वायरलेस प्रेसेंटर . How are you typing text?" (Bigger, mysterious smile :-) )

Well, I made my own Wireless Presenter-cum-Keyboard-cum-Mouse. (Biggest smile yet :-) And, in Sheldon's words - TBBTS02E07 - Muaa-hah-hah). Here are the details.

This project originally started off beacuse I used to get exceedingly irritated with the abysmal lack of dexterity afforded by standard keyboards. This lack was / is felt, most painfully, when getting fragged in a fast-paced game of CoD. "I need my grenade! Where the hell is the 'G' key. Dratted keyboard." My rifle! My rifle! '1'! '1'! '1'. Shots fired! Duck! 'Q'! 'Q'! 'Qqqqqqq....!'. I'm sure you get the point. I also do a lot of 3D modelling in AutoCAD, and image editing in Photoshop. My mouse, which would ordinarily be considered reasonably good, fares pathetically at this zoom-in-zoom-out-click-to-do-this-tap-to-do-that kind of stuff. Wouldn't just be great to have an additional fully customizeable keyboard? It would have a zoom slider, a wonderfully sexy scroll wheel (much like the iPod's), multiple buttons, and special keys which have several keyboard buttons bound to one (so to press 'Ctrl-Alt-Del', I'd just need to press one key on this keyboard). The mouse would be integrated into this device, and would have similar useful features.

I can, of course, buy such a device, but that would mean shelling out absurd quantities of cash - something that I don't have much of! Making one would mean I'd save potloads of money. I have been reasonably successful; hence this post.

So far, I've only made a Wireless Presenter, but this same device can be adapted to do all the stuff I mentioned above. A little effort, some pain, and a couple of milk-and-cookies-filled all-nighters are all that are necessary.

Without going into the overly-technical details of the device I'll tell you what the system consists of:
- a full speed USB PICmicro (the 18F2550) (free from Microchip);
- a TSOP1738 IR detector (Rs.10);
- a cheap roadside SONY TV remote (Rs. 60);
- a USB cable (free from an old mouse), crystal (Rs. 4), capacitors (Rs. 4).

The SONY remote sends IR data to the TSOP, which is connected to the '2550. The PIC decodes the IR signals (which are in SONY's SIRC format). The '2550 then sends this data through USB to the PC. Now, I've programmed the PIC to enumerate as a USB keyboard-mouse combo device. So my PC, for all practical purposes, thinks that it has a second keyboard and mouse. I have mapped certain keys of my laptop keyboard to keys on the remote. So pressing the 'Program +' key on the remote, is equivalent to pressing the 'Right Arrow' key on my keyboard. Pressing the 'Power' button on the remote is like pressing 'Esc' on the keyboard.

This is the nice thing about putting software (firmware) onto a microcontroller - you can fiddle around, and map virtually any key combination to any remote key!

I use this device to control MS Powerpoint slides from upto 30 feet away. I've mapped most of the Powerpoint keyboard shortcuts to buttons on the remote. The 'Contrast' button is 'F5', the 'Program Jump' button is 'Enter', and so on.

For a full listing of the source code go here .

I've made this using a PIC, but if you get the logic and code right, I'm pretty sure you could use any processor.

Future modifications include adding an accelerometer to provide intuitive mouse support (right now I'm pressing 'Mute' and the 'Volume / Program +/-' buttons for mouse-like action). Maybe I'll even port the whole thing to RF (Zigbee, or MiWi); it's running IR now - the great thing about IR is that its laughably cheap and easy! RF would involve additional cost and effort (protocols, and other crazinesses). For now, this is good. Anyway, in the beginning you had asked (well, alright, I had made you ask) how I was typing out text using my वायरलेस प्रेसेंटर.....I think you have the answer now.

I will be, at some point in time, making the gaming device I talked about earlier, but until then, I'll have to amuse myself with this :-) If anyone is planning on building something similar drop me a mail - I'll be glad to help.

Thursday, November 6, 2008

I Don't Want To Forget

So I’ve been doing some thinking. About many different things. Things important to me, and things not so important to me. About family and friends. About electronics and cars. About my past and my future. Most of the time these thoughts have been narcissistic and self-glorifying. But there have been a few times I have thought along other lines as well.

There’s a lot playing on my mind of late, and applications (to universities for graduate programs) are not at all helping my case. There are so many confusing forms to fill out; so many queries in my mind. There are times when I feel like ditching the whole process – who cares! Aargh! I don’t want to study within the constraints of the system. I want to learn. How can someone tell me what to learn? Why should I follow a fixed and defined path? After all there’s so much more to life than text book knowledge, right?

Consider this - a friend of mine recently lost a relative. When someone loses another person close to them what do you say to them? Do you say anything? What does social protocol demand of you?

“Hey, I believe you lost so-and-so. I’m so sorry.”

Is that enough?

Are you really sorry? Or are you just doing what is customary?

Can you take away that person’s pain? And maybe I should have led with this – is it right to take away that person’s pain?

Maybe the mourner doesn’t want to forget. Maybe the mourner just wants to hold on to the beautiful memories a little longer.

Life’s tough. Hang in there buddy.

Tuesday, October 28, 2008

The Party Never Ends

I guess this is my first non-electronics post. Sorry, I can’t help it. I obsess about things; electronics is one of them. Most of the other stuff I think about is either too personal or rude to post to a blog. I’m not the kind of chap who would post his life on a blog. Hell, I barely tell my friends everything. Do I want to be all dark and mysterious? Do I want people to keep guessing about me? Nah, that’s not it. Its just that I don’t voice my feelings too often. This has a flipside though. Not telling people what you feel can have either of two equally bad consequences. The first being that people think you’re deliberately hiding something from them; they get angry with you – “why can’t you be more open?”, or, “Hey, why don’t you talk to him/her/them about it. It’ll be good for you.” And the second penalty that you may need to pay is that you don’t learn how to communicate with people.

I can communicate with people at an intellectual level pretty easily. Its just that things get tough for me at the personal level. Parents, sis, relatives, friends, crushes – well, with each category of individuals, the situation is different. Naturally, you would understand that with each group of people you would have different things to talk about. So what is it that makes it so hard for me to communicate with others? The raw answer – I don’t have the faintest idea! But I’ve introspected several times. Vaguely, I would say that it’s probable that I feel it’s better to let bygones be bygones, or that the matter of concern is too trivial to bring up and sour the conversation. So do I forget about the problem? Hmm, Yes and No. The thing is, that the particular group that I’m having the problem with has got to help me with that problem, for me to tide over it. So what’s the difficulty? My ego. Most of the time I’m too proud to admit I'm in a ‘situation’ and I need help. I can offer some advice – the only group that can effectively help you out with the problem you’re facing is the very group you have the problem with. This puts you into a right spot. How the eff (yes, that’s a four-letter all-purpose sentence modifier. It’s a wonder grammaticists haven’t included this ubiquitous word into the English lexicon as one kind of ‘god-word’, capable of doing anything and meaning anything!). So again, how the eff are you supposed to talk to the very people you just dissed (Google that) or with whom you have a problem? Umm, don’t ask me; that’s entirely your problem; see, I d-o-n’-t t-a-l-k a-b-o-u-t p-r-o-b-l-e-m-s.

There was recently one time I did. And I can tell you, it’s been the most rewarding thing. As with a lot of guy-problems, this one too, was created and promulgated by none other than a member of the fairer species. They are so different from humans that I consider them a completely different species. (I may have added certain justification here for this, but since this blog is in the open domain, it may be construed as rude)by some right-wingers). I had a humongous crush on this girl. And, as most crushes are prone to do, it created problems for me. Lots of problems. Many many problems. Super-big problems. I’ve run out of adjectives. I used to think of this girl day and night, putting myself (and her, of course) in fantastic and fabulous situations, and I would come to her rescue; be her proverbial knight-in-shining-armour.

What came of that relationship? Nothing. Zip. Zero. The only thing I walked away with was a brilliant friend, who understood me, and who has stood by me. She continues to do so, and I am proud of that. A few nights back I talked to this girl, and told her everything, right from how it started. We laughed about all the silly little things we did. I have many amusing anecdotes, which I promised her, would contribute to the central story of my debut romantic-comedy movie, if my engineering career bombs. It was very comforting talking to her, and I understood now why I had liked her so much. The brilliant thing is that we were both so comfortable chatting with each other – there was nothing put on or stilted about the conversation. No awkward silences. Just simple, joyous freely flowing emotions between good friends. I guess talking to her was liberating in some kind of way, and I still have a soft spot for her. That I could still talk to someone who I had such a deep crush on, and though things didn’t work out, yet be at total ease, is what I would call one of life’s little miracles.

You should try it out some day. It’s superb emotional therapy. Forget the psychologist or counselor. Your best friends are your best counselors.

Note to the aforementioned girl, if she happens to go through this blog: Drop me a mail or an offline, please, telling me what you think. Thanks for everything. You are a gem of a girl, and you can always count on me. I’m just a phone call / SMS / mail / offline away :-) .

My current Gtalk status message is

“‘Life isn't black and white, it’s in various shades of grey”, people say. But my life is 32 bit true colour!”

Live life to the fullest – it’s too short. You know how sometimes you’re so busy organizing something that you forget to enjoy the party? What do you do then? Has it all been lost forever? I don’t think so. Almost all parties have an after-party, where you can sit and savour the fruits of your hard work. You have all the time to figure out what went wrong during the party, and think of what you could have done to fix it. The problem is – you can’t fix it anymore. The party’s over! So instead of wasting time thinking of how to fix stuff that can’t be fixed, have no regrets for what you did. Yes, there may have been things that you did wrong, or things that you could have done better. So learn from those mistakes. Take with you only the experience and knowledge you got from the party. Yeah, and don’t forget to remember the fun – that’s what made it a party in the first place, right?

Thursday, September 25, 2008

My 'do almost anything with it' kit

Hey all,
I'm a student, and I have (very) limited access to money Razz (people, be kind and donate to the Help-Rohit-Fund. Donations for this noble cause will not be taxed...I promise Smile Anyway, since most of you are students as well, and are in a similar state of monetary paucity, I've made up a list of tools/components that you must have. In fact, I carry the stuff mentioned below everywhere I go....if my trip to a place is more than 4 days long, this stuff goes with me. The list is by no means comprehensive, or complete - its simply what I find most useful. If I dont have something, I do a bit of jugaad. Smile

1. Simple multimeter - MAS830, Rs325 (no fancy stuff, no capacitance meter, or inductance measurement,etc, etc - this add heavily to the cost)

2. 25W soldering iron - Soldron, Rs120 (dont compromise on this .you do get cheaper imitations for 35-80 bucks, but its not worth it.it doesnt heat up fast, tips are useless, coil burns out super quick; buy a pointed tip with the soldering iron; you'll find it useful after you get the hang of soldering)

3. 60/40 SnPb pre fluxed solder wire, Rs30 - I usually have the standard 0.05" dia wire, as well as the fine SMD solder wire

4. Wire stripper/cutter, crimper (Rs20)

5. Smooth file (Rs 10)

6. Wire - I carry around single strand hookup wire (Rs3 per m) for use on solderless bread boards, and multistrand ribbon cable( Rs6 per m) for prototyping

7. Breadboards - two solderless (Rs, 60 each), and two DM2030 (Rs 7.50 each) (this is the VIsha Electronics part number, they're just veroboards)

8. My Microchip PICKit2 USB programmer - Rs.2000, - this is one of my most useful tools. It programs the entire PIC range of controllers (10,12,14,16,18,24,30,33,PIC32 - thats over 500 controllers), plus loads of memory EEPROMS, it can acts as a Logic output, a Logic analyser, a USB to Uart converter (no need of the MAX232), a 2.5 to 5 V power supply, etc etc

9. Some LEDs (Re1 each) and push buttons (Rs2 each)

10. A homemade 3Amp, 1.2 to 21V variable power supply (Rs150)

11. A 16x2 character LCD based terminal UART that I whipped together for Rs130.this way I dont need access to a PC for RS232 based debugging

12. A few resistors, capacitors, molex headers, pots (potentiometers) - not more than Rs30

13. Chips, circuits that I'm currently working on

The total cost of the above stuff is around Rs3000, out of which the PICKit2 is 2 grand. I find most of this stuff indispensable; you may have a slightly different kit-out depending on what electronic stuff you work on.

Coming up next.my wish-list.(this is where the Help-Rohit-Fund comes in ) Smile haha


So this is my first attempt at blogging, but it definitely is not the first time I'm posting online. I do most of my 'blogging' on technical forums, Microchip and CCS are the most common. I also post to my University's forum. I'm gonna simply do a copy-paste of my post on the BITS forum. This blog will be a largely BITS-centric blog (naturally, since I'm a devout BITSian!).