gzweigle / DIY-Grand-Digital-Piano

Building a hybrid MIDI digital piano
https://www.youtube.com/@gzpiano88
GNU General Public License v3.0
40 stars 2 forks source link

On-board ADC usage? #56

Open szbergeron opened 2 weeks ago

szbergeron commented 2 weeks ago

Is there a reason for specificallly using an external ADC for the stem piano, instead of the two on-board ADCs on the teensys? I've been working on a stem-piano-inspired build with hall effect sensors, and wasn't sure if there's some hidden gotcha I haven't seen. So far, I've been able to push the sample rate high enough that even doing all 88 keys off of one teensy should be fine, but have planned in a leaf/hub architecture anyway just for some extra flexibility

gzweigle commented 2 weeks ago

Sounds like a fun and interesting project.

The Teensy ADC is probably ok.

This is because the ADC is likely not the dominant error source. There are many other error sources (I recently listed on the youtube channel).

As for stem piano, it streams all hammer positions over Ethernet. So, I like the 16-bit ADC because with offline processing I can use more sophisticated algorithms to analyze the waveforms. For what purpose I don’t know yet.

davidedelvento commented 2 weeks ago

As Greg said, the internal ADCs are probably okay, but using external, better ones frees more board resources and eliminate possible source of inaccuracies. Whether or not such inaccuracies matter is debatable and require studying. This is what Jay is doing at https://github.com/jkominek/piano-conversion/discussions/58

So to start your experimenting, you can definitely use the internal ADCs as I have done for example with https://github.com/davidedelvento/Mybrid/tree/main (and Jay has done with the STM32). That may turn out to be "perfect", or "adequate with some limitations" or "not good enough", depending on your goals. In my opinion, the goal of a project like this is to get the very best possible setup (ideally much better than commercial products) with an expense that is relatively inexpensive compared to commercial Hybrid pianos -- hence the use of an external ADC makes sense. If your goal is maximum simplicity or minimal expense, the internal ADC makes more sense. In either case, studying it is very appropriate, so please do share what you find!

szbergeron commented 2 weeks ago

Neat, I'm definitely tending toward an "opinionated and functional" thing more than something that gives me all the extra analytics. Using the dual ADCs in parallel I've found gives me about 16 keys (a "batch" to sample) per 40 microseconds or so, and with muxes and key attention I might be able to get this down to just a single teensy, said muxes, some op-amps, and my sensors on a few daisy-chained boards for all 88 keys and assorted controllers.

I'm not really doing this for money-saving, I'm just kind of a dumbass so the less EE work I touch the better. My goal is to do more magic in software to offset for simpler hardware. So far, doing a linear regression of the hammer velocity between let-off and when it "hits the string" with a buffer gap on either end gives me quite stable results, especially with 300+ samples in that distance at what I'd consider "fortissimo" with a single key and attention. I still want to improve SNR a bit so I'm going to try some op-amps to boost the input from the sensors, but that might just be vanity more than anything legitimately necessary

I am quite sensitive to latency, so the more I can bring down the time from physical contact to first sound from the speakers the better, even if I'm not going to completely max out the granularity you get from Midi 1.0 (let alone 2.0)

davidedelvento commented 1 week ago

To avoid reinventing the wheel, consider https://github.com/jkominek/piano-conversion/wiki/Analog-Stage-Theory-of-Operation -- Jay recently also commented that such an configuration is not giving the expected/hoped results, but I can't find that comment now, so you have to dig into the repo looking for his latest verbiage and check exactly what the sentence says, rather than trusting my second-hand report

szbergeron commented 1 week ago

My read is that the problem is the observed output impedance of the phototransistor in the CNY70? The 1302 sensors I'm using only have 5 ohm output impedance at 1ma, and is a powered device with internal amplification already. I'm no EE person, so I'm sorta trying to navigate the runes as I go, but my impression was that stacking op-amps was already relatively common so pairing the internal one with an additional stage should be "fine"? I'm sure I'd run into more issues if I tried to plop an optical sensor in place of hall effect, so my idea of being "sensor agnostic" probably goes out the window. Hall effect seems quite noise free when I use stronger magnets for each key though so fingers crossed I can double down and it turn out ok.

szbergeron commented 1 week ago

I also realized checking the datasheet for the a1302 again that it really wants a 5v supply, I tried a quick and dirty test and the half-range output at 5v (from 0 measurable field to magnet in contact with sensor) is a much more sensible range so long as I can limit the other side of the range from overvoltage. It does mean 2 power rails, but I can make that happen