NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Questions re: debouncing input switches, switch matrix, and latching outputs

December 21, 2009
by iamtheari
iamtheari's Avatar

First off, some background on the project I am hoping to put together. This is the whole reason I ordered the Nerdkit - because using a Z80 would have become too much hassle with all the supporting hardware, when the Atmel chip can do it all on one IC.

I am a guitarist. I want to build a remote effects-switching system, because nothing on the market does it quite the way I want. Plus, it'll cost less and be a lot more fun to do it myself! Here are the basic requirements for the two-unit system, each unit having its own MCU:

A. Remote Control Unit: 8-16 footswitches, SPST momentary. The MCU should be aware of the event of a switch being pressed and be able to determine which switch was pressed. Each switch will act to toggle one relay in the Rackmount Unit. If possible, it should also have talkback LEDs, one per switch, to inform the user which relays in the Rackmount Unit are on and off. The Remote Control Unit will receive power from the Rackmount Unit and send commands to the Rackmount Unit, all through one cable (I am thinking of using Cat-5 because it's cheap and easy to get in any length, but a MIDI cable is also acceptable.) A serial protocol can be used for the communication.

B. Rackmount Unit: 8-16 audio relays, DPDT. The MCU should be able to switch just one relay at a time, but should have a way of knowing which relays are turned on (I am probably okay with making the assumption that a command to turn a relay on will keep it on until it is told otherwise, even though that is less robust than a feedback of some sort to the MCU). It will receive commands from the Remote Control Unit over the serial cable that tell it to turn on or off a particular relay. The relays would be controlled by MOSFET transistors or something.

The things I have no idea how to do at present: 1. Debounce the input switches.

  1. Have 16 inputs for the Remote Control Unit. The best I can think of is to encode using a 16-to-4 encoder for the switches and have every switch also activate a "there is a switch pressed" pin, for a total of 5 input pins on the MCU. But maybe there are better ways to do this. Also, will I need to use DPST switches to be able to also have the alert pin, since I can't just tie that pin to all of the inputs of the encoder?

  2. Have 16 outputs on either of the two units. Then using flip-flops or some kind of latching circuit to control the LEDs, after a 4-to-16 decoder with an additional "time to toggle an LED" pin for a total of 5 output pins. Is there a better way to do this part that I'm missing?

  3. Long-cable serial communication. Should I worry about using an optoisolator? Obviously I will have to do that if I go the MIDI route, since I think that's part of the spec. MIDI does have the advantage of ease of testing, since I can connect either unit to my computer and send/receive MIDI messages to experiment. But the cables are so much cheaper if I use Cat-5, and I can use the LCD to test either unit since I'm only talking about using 11 data pins on the Remote Control Unit (5 inputs, 5 outputs, plus TXD for the USART) and 6 on the Rackmount Unit (5 outputs plus RXD).

Thanks to anyone with thoughts or guidance on this. :)

December 28, 2009
by hevans
(NerdKits Staff)

hevans's Avatar

Hi imatheari,

It sounds like you have a very interesting project in the works, and it sounds like you have a great idea of how to start. My suggestion is try it! You will learn along the way, and post any issues you come across. Debounceing in software is not very difficult - it is merely a matter of checking the state of the pin several times, and not counting a button press if it toggles too quickly. There is an example of a debounced button on the Motors and Microcontrollers Tutorial. There is no thorough explanation, but the source should be enough to help you get started.

Let us know if you run into any problems, there are plenty of people here willing to lend a hand.

Humberto

December 29, 2009
by iamtheari
iamtheari's Avatar

Thanks for the response. That video was very helpful, indeed, and I will take a look at the code later. (I have plenty of programming experience so I'm sure I'll be able to dissect it just fine.) One problem down, a few to go. :)

December 29, 2009
by iamtheari
iamtheari's Avatar

Update: I have done some shopping online and have come up with the following ideas:

  1. Use only SPST momentary switches on the remote control unit
  2. Use an 8-to-3 encoder with an output enable pin that indicates whether any line is active (Mouser part #595-CD4532BE)
  3. Use one 8-channel relay driver to run the relays in the switching unit and another one just to run indicator LEDs on the remote control unit (Mouser part #595-TPL9201PWPR )

The relay driver I found has a serial interface that requires 3 data lines (enable, clock, data). So I'm using 4 data pins on the MCU for the switches and 3 pins for the outputs. I am putting the inputs on PB0-PB3 and the outputs on PC0-PC2. I can easily double this up later to use PB4-PB7 and PC3-PC5 to control twice as many relays. PD0 and PD1 are used for the USART, leaving PC6 and PD2-PD7 on both units entirely free and PB0-PB7 free on the switching unit.

Now, who wants to teach me metalworking to build the enclosures for these things? ;)

December 29, 2009
by iamtheari
iamtheari's Avatar

Correction, the relay driver part number is 595-TPL9201N for the DIP package.

Post a Reply

Please log in to post a reply.

Did you know that an electroluminescent backlight for an LCD panel requires hundreds of volts AC to run? Learn more...