Midi xylophone: different approach for scanning lots of inputs, could this work?

I am playing with building a midi xylophone, I have a prototype where I scan FSR's which are put in a matrix so I can use more keys than analog inputs. this works, however because the pulses are very short, with 3 octaves the system gets too slow.

The velocity I want to determine by using the analogread does not need to be very precise, If it can detect about 7 levels (ppp to fff for music dynamics) It is ok, so I came up with a different plan which i want to verify:

The output of the fsr goes into a voltage comparator like a LM339N, Using an analogwrite I set one of the inputs on the lowest treshold value, if the key is hit, it wil set a digital input to 1. in the next loop I set the reference input to the next level, if the signal is above this, I register this as the highest value etc

Is this a good approach and will it be faster?

Thanks,

Remco

The output of the fsr goes into a voltage comparator like a LM339N, Using an analogwrite I set one of the inputs on the lowest treshold value, if the key is hit, it wil set a digital input to 1. in the next loop I set the reference input to the next level, if the signal is above this, I register this as the highest value etc

AnalogWrite produces a PWM signal so it will need filtering first, but apart from that you have implemented what is known as a linear ramp A/D converter.

While this will work I can’t see where it gets you with scanning all your FSFs.

Grumpy_Mike:
While this will work I can’t see where it gets you with scanning all your FSFs.

You mean the matrix part?
It was inspired by this project, he scans way more fsr's

Grumpy_Mike:
AnalogWrite produces a PWM signal so it will need filtering first,

since I only need 7 reference values, maybe I can use 7 digital outs with different resistors or even pots to create the reference values

remcoh:
since I only need 7 reference values, maybe I can use 7 digital outs with different resistors or even pots to create the reference values

That just makes things more messy, just use an RC filter
See here about PWM PWM

Grumpy_Mike:
While this will work I can’t see where it gets you with scanning all your FSFs.

also, I could use multiple comparators and connect them to their own digital-in, there are many boards with lots of digital in's I can imagine this is better also because the comparators have time to "settle"

Yes you can have as many comparators as you want, you get four in each chip.

Settling time is very fast you won’t have any problem with that.

But why not just speed up the analogRead like he did in the video? It is a simple one line of code put in the setup function, that changes the pre scaler count for the A/D. Speeding up the A/D looses you some resolution if it is too fast but as you are only looking for three bits then I imagine you can go very fast with it.

Grumpy_Mike:
Yes you can have as many comparators as you want, you get four in each chip.

Settling time is very fast you won’t have any problem with that.

But why not just speed up the analogRead like he did in the video? It is a simple one line of code put in the setup function, that changes the pre scaler count for the A/D. Speeding up the A/D looses you some resolution if it is too fast but as you are only looking for three bits then I imagine you can go very fast with it.

I am not sure if I can do the same on the teensy board I am using, I tried setting the resolution to 3 bits but that did not bring much, about 10 percent faster which is not enough

I am not sure if I can do the same on the teensy board I am using, I tried setting the resolution to 3 bits but that did not bring much, about 10 percent faster which is not enough

Setting the resolution is not the same as altering the clock prescaller.
I am sure it can be done on a Teensy but the registers and contents will be different. You are best asking on the Teensy forum for how to do this.

This is a quick and dirty three bit A/D I did for the Raspberry Pi. That is a 3V3 system same as the Teensy so it should work. Just change the GPIO pins to suitable I/O pins.

Dirty A-D schematic.png