How to implement digital logic with diodes?

Status
Not open for further replies.

CyberGene

Member
I'm working on a MIDI controller that has 352 digital outputs with active-low logic (high = non-active, low = active). I need to group them into 22 groups (each having 16 outputs). So, I will use 22 Teensy digital outputs to select a group (they will be mutually exclusive, e.g. there will always be only one output that will be low). And I will use 16 Teensy digital inputs to read from the MIDI controller.

So, my question here is what diode scheme should I use so that I can "select" a group of MIDI controller signals through one of the Teensy 22 outputs and thus only that group signals will flow to the Teensy 16 inputs?

To me it seems I will have to OR each of the 22 outputs with each of the 352 inputs but that's an awful lot of diodes (7744 diode). I probably miss something simple here. Another option is to use Quad OR IC gates.

Any advice would be appreciated.
 
I'm very confused by your question, mainly by the use of words "outputs" and "inputs".

I can't even tell if you wish to create 352 signals where Teensy receives MIDI messages and generates the signals (what would commonly be called an "output" from Teensy or any MIDI controller) or if you have 352 signals that represent on/off buttons or keys that you wish to connect to your Teensy, which would them presumably send MIDI messages when any of those signals change (which would commonly be called "input" to Teensy or a MIDI controller). Your question asks for narrow technical advice without explaining what you're really trying to accomplish, and you use so much ambiguous language (at least it seems ambiguous to me) that I just can't figure out what you really want.

Maybe this page can help? Scroll down to "Connecting Many Buttons & Knobs/Sliders". This is by far the most commonly requested circuit for use with MIDI controllers.

https://www.pjrc.com/teensy/td_midi.html

If you wish to actually create 352 signals from your Teensy (eg "a MIDI controller that has 352 digital outputs"), perhaps shift registers would be useful? 74HCT595 and 74HCT164 are popular choices.

To answer specifically about your question relating to diodes, I would advise against using diode logic. In general diode logic has terrible noise margin problems which require careful design to make things work reliably. It's a tech trade-off that made sense in the 1960s when transistors were very expensive. In today's world, there's pretty much no reason to use diode logic for almost any project. Sometime "open collector" logic makes sense, but diode logic, not so much.

If this didn't help, maybe try to explain what you really want to accomplish. We can help you much better if you give us some context to understand your question. Also consider explaining what you really mean by "input" and "output"....

Also knowing which Teensy model you are using would help us to give you answers that more directly apply.
 
Last edited:
Let me clarify. I am creating a MIDI controller from a real 88-key grand piano action. I have sensors at the hammers and at the keys. I need sensors both at the hammers and keys in order to know not only the velocity of the hammer but also how long the keys has been held and with what velocity it has been released (software pianos use all that information).

I am using Vishay CNY70 sensors that measure proximity. So, I have 2 x 88 CNY70 sensors = 176 sensors. It would be madness to feed analog signal to Teensy, so I've attached a comparator to each sensor and by using two different reference voltages (through two trimpots) I produce two digital inputs corresponding to two discrete distances from the sensor. By measuring the timing between these two position I can calculate velocity. Thus, 2 x 88 sensors will produce a total of 2 x 88 x 2 = 352 binary inputs.

I've created a POC for one such sensor:

I'm using Teensy 3.5 in the video but I also have 3.6 and will be using it in my finished project.

Now, I've researched how commercial MIDI-controlelrs are implemented. Here's a diagram I found for a very popular MIDI-controller:


As you can see, they use 3 decoder chips in order to decode a 5-bit signal into 22 binary controlling signal lines. Since I have the Teensy with plenty of digital inputs/outputs I thought why bother with decoders, I can directly use 22 digital outputs in mutually exclusive mode to do the same. So far so good. (The diagram you see is actually pretty close to mine because in that controller they have 3 sensors per key registering three discrete positions of the key and calculate velocity. In my case I will have 4). Then in that diagram you can see that they have grouped 4 keys for a total of 22 groups. Each group has 4 keys x 3 sensors = 12 inputs (which will be fed to the Teensy in my case and I will have 16 instead of 12). So, they use diodes to implement OR-logic: depending on which of the 22 controlling lines is active, and reading one of the 12 sensor lines, using a table one can always know which of the sensors produced value.

So, I need to translate that into my design. I will also have 22 controlling lines (22 digital Teensy outputs) and I will have 22 groups of notes. Each group will have 4 notes x 4 binary sensor input values.

And here goes my question. Since I don't have simple switches but instead I have 352 distinctive sensor "lines" (inputs in terms of Teensy), I need to be able to apply similar grouping OR-logic.
 
Last edited:
If you are going to follow that diagram, notice that the logic simply involves how the grounds to the switches are wired. You can do the same thing by wiring your 22 lines to the cathode of the emitter diodes in your sensors in groups of 12 ( or 16 in your design ). That will probably be too much current for the Teensy, so you will need some FET or transistor drivers/buffers between the Teensy and your sensors. The addition of buffers will invert the logic on the 22 enable lines.

Edit: Or maybe better, you could wire the 22 lines to the emitters of the photo transistors. If the currents are low, you may not need drivers.
But I guess the comparators complicate everything, so maybe you will just need 16 of those and do the wired OR logic in the inputs to them?
 
Last edited:
^ Thank you for the advice. How about using CMOS OR-gates? I posted that some time ago in the other thread I created, but anyway. What do you think of this:


NU1 stands for a "Note Unit" and simply encapsulates two sensors with 4 inputs. So, I will have 22 groups, each having 4 note units. Each note unit will be connected to a Quad OR gate, thus I will have 88 NOR gates. I guess they will also act as buffers and won't load the Teensy outputs.
 
See my edit in my other post about using 16 comparators and doing the wired OR on the inputs. You wouldn't even need diodes as the collectors of the photo sensors could simply be wired together. I think it might be able to be made to work that way.
 
Thanks again! I will have 88 quad-comparators like this:


I think I can somehow wire or the emitters indeed. The comparators expect voltage that is higher than the set reference, so if I manage to somehow pull it down when not selected, that would work. Not sure how I should do that though... Sorry if my questions are dumb, I am a real newbie in electronics.
 
With that diagram, I am back to the idea of wiring the 22 enables via driver FET's to the cathodes of the photo diodes. The wired OR would be on the emitters. You would need just 4 quad comparators instead of 88. The 4 quad comparators give you the 16 input signals as in the other diagram. You would consider the 4.7 k resistors part of the comparator and would just need 8 of those.

The wired OR will be 22 connections to each of the 4.7k resistors. ( if I visualize this correctly ). The concern would be noise pickup on all that wiring attached to the input of the comparators. It may not work. But it would be the simplest to wire up.

If you want to stick with your original plan of 88 note units, you may want to look at Paul's link. The signals could be muxed down to a reasonable number of signals after the comparators where noise is not an issue. You would not need the 22 select lines at all and that would give you more available input pins. There would be more wiring, but probably a greater chance of success. You probably didn't think his diagram would apply to you. But you can mux your 452 comparator outputs down to a reasonable number of inputs to the Teensy. In your case, instead of the mux being connected to switches, it would be connected to your comparator outputs.
 
My humble opinion is that an I2C solution would be way too slow to determine timing of when each comparator changes state.
 
rcarr, I’ll probably still need all the 88 comparators because I might need to individually trim all reference voltages note by note since hammers are in different size and shape and since it’s a real action there are some tolerances. The idea about muxes is good I believe. What I’m concerned is if I will be able to switch and read all the sensors in a reasonable time. To my understanding I need to be able to scan the entire keyboard with at least 11kHz, at least that’s the frequency which the linked commercial solution works at.
 
Guys, thank you for your answer so far, however I am still confused.

First of all, I am not sure if using decoders/multiplexers is the way to go, since from the example given by PaulStoffregen it seems each select should be followed by a delay of 50us and that's an awful lot of delay for 22 groups. For a single keyboard scan that will equate to 1ms and for piano playing that's unacceptable delay. An entire scan of the keyboard from all 352 inputs should take no more than 90us.

That is why I need to use as many Teensy outputs and inputs as possible to avoid decoders and multiplexers.

I've drawn a picture above where by using diodes I might be able to draw the phototransistor emitter current down but as Paul mentioned, diodes might be noisy and that particular emitter voltage is the one that I use to measure hammer and key positions so I am afraid any noise or instability added to it would defeat the purpose of my project to have a very precise and high-quality grand piano action controller.

So, to me the problem still seems unsolved, unless I stick to my initial plan with using 88 OR-gates. As I said, I am a newbie in electronics and I try to compile ideas I get from Internet but I lack any practice with (I am a software engineer by profession) so any help and advice would be appreciated.
 
OR gates are not going to work as you can't just tie the outputs together. Take a look at 74LVC245 parts. They have tristate outputs, so you can tie the outputs together ( but be very careful to only enable 1 at a time ). They are fast, 5 nano second typical delay. They will solve your next issue of converting your 5 volt system to 3.3 volt logic for a Teensy 3.6
 
OR gates are not going to work as you can't just tie the outputs together. Take a look at 74LVC245 parts. They have tristate outputs, so you can tie the outputs together ( but be very careful to only enable 1 at a time ). They are fast, 5 nano second typical delay. They will solve your next issue of converting your 5 volt system to 3.3 volt logic for a Teensy 3.6

I had to read that a few times and I researched what a transceiver is. Then I read the datasheet and again your answer and finally I got it! You’re right I can’t use my OR-gate idea because the outputs can’t be tied, thanks for noticing that. And that transceiver idea is great, thank you very much. Being octachannel also means I can use “only” 44 of them.
 
It depends upon how you gonna ask this question. Because digital logic and diodes has no concern. Output and input can be in the form of information that you normally have about it.
 
Status
Not open for further replies.
Back
Top