Shopping Cart

Your Cart is currently empty.

Home The Insider Blogs Electronics 102
Electronics 102

So you did put all your inputs in tri-state mode and you double checked it? OK, let's connect something to those pins then. You want to connect a pushbutton and read from your Digit-LS if somebody is pushing it? Yeah, why not... So let's say you connect a pushbutton like the schematic below.

Looks allright, doesn't it? So if you push that button, it will connect 5V to pin RA0 and if you read out PORTAbits.RA0 from your firmware, you will read a '1'. Correct. And if you release the button, it will go back to 0V and if you read PORTAbits.RA0 from your firmware, you will read a '0'. Correct? Well, not quite. If the button is not pushed, pin RA0 is not connected to anything. You would be easily tricked into thinking that that means it is effectively 0V but it isn't. It can be a lot of things when it's not connected and it can even change instantly if you move your hand nearby. So when the button is NOT pushed, you will read '1' and '0' values at random. Not quite what we want, is it?

So we should need some kind of double action pushbutton that will connect 5V to the pin if pushed and 0V to the pin if released. Something like this:



Would that work? Yes, it would. There are two issues with this, though. The first one is that there is a bit of cyberstate between the fully pushed and fully released position of your pushbutton. If you happen to read out the value just while the button is in the process of being pushed or being released, you would get random values again. In real life, that will most likely not be an issue. The pin was about to change from '1' to '0' (or just the other way around) so whatever random value you read will either reflect the previous position or the new position, but whatever happens, the next read action will put it right.

The other issue however is a bit more serious. Once you go shopping for these 'double action' pushbuttons, you will find them to be hard to get and expensive. And in electronics, we don't like the word 'expensive' for our parts. So instead, we will put Ohm's law to work to help us out. Without getting into it too deep, I'll just show you the schematic:



 Now what happens here is that if the button is not pushed, the pin is still connected through R1 to 0V. So your pin will read '0'. But if you push the button, the pin will be connected to 5V and it will read '1'. And R1 sitting between GND and our pushbutton will prevent the button to short circuit the 5V to ground.

Too technical? OK, you can also look at R1 as some kind of spring. Normally the spring will pull pin RA0 to GND, as in 0V. But if the pushbutton is pushed, the 5V connection will pull up the pin to 5V. Once the button is released, R1 will pull it back to 0V again. Now guess why electronic engineers call this a 'pull-down resistor'...

But most people call electronic engineers 'weird'. Amongst others because they like to do things upside down. See, you need to know that for historical reasons, TTL electronics used a lot of 'active-low' signalling. This means that a signal on a pin is supposed to be considered active when it is at 0V. Which also means that the pin being at 5V means that no action needs to be taken. And even though the reasons behind that might have lost significance, still a lot of TTL electronics work this way. For instance the reset pin of the Digit-LS microcontroller is an active low pin. So normally it will be at 5V and when you push that reset button on the device, you will actually bring it down to 0V which will cause the microcontroller to reset. So the same application with a simple pushbutton and a resistor in the traditional 'active-low' configuration would produce the following schematic:

Still almost the same, but now the switch will pull down pin RA0 to GND and when released, the resistor will pull it up to 5V again. And guess what, electronic engineers call this a 'pull-up resistor'. One pro of this configuration is that on a PCB you will usually always have some ground plane nearby so it is easy to route the tracks to your button. If it would have to be connected to a 5V line somewhere, it whould have been less easy to find.

Now if this bit of theory just brushed off the dust on your electronics knowledge, you can start soldering your own electronics now and hook them up to the nearest Digit-LS. But if you are still flabbergasted with this stuff, then you might want to just connect anything we put on a pcb for you or maybe very thoughtfully build something up from a schematic you got from a qualified engineer. And before you start making your own, read a good book about electronics. Or just create a lot of smoke and order a new Digit-LS after that Cool

Now your insider will be VERY BUSY developing and fixing issues found in testing, so my next blog might take a few weeks to appear. So long!

The Insider





Last Updated on Monday, 20 July 2009 16:34
Copyright Sofrides IO