Author |
Message |
rhdf
Joined: Jul 11, 2014 Posts: 39 Location: Sweden
|
Posted: Fri Mar 24, 2017 2:14 pm Post subject:
Smooth parameter sweep with encoders? |
|
|
With a N pulses/Rev encoder you obviously get stepped parameter increments/decrements. What is the smartest way to get a encoder to act somewhat like a potentiometer?
Most of the parameters in my project I can live with some steps, like oscillators semitone and maybe detune. But for filter cutoff etc I would like to have some kind of more potentimeter-like response. |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Fri Mar 24, 2017 3:12 pm Post subject:
|
|
|
Easiest way would be to just slew the signal with an exponential averaging filter (for float values: NewValue = NewValue * n + OldValue * (1 - n) with 0<=n <1> no filtering, 0 -> frozen, no change).
Another possible thing to do, but more complex, is to measure the time between changes (and calculate the speed of change from that) and use this to do a linear interpolation between values - with this the changes will come trough a bit late, or some additional filtering will be needed (as to do real time changes would need a turning speed guess for the current step (from the previous one) which would never 100% correct). I've succeeded in making this working as well (for interpolation between sequencer steps) - but as said -more complex, and probably not worth the trouble here.
Then a 3rd way could be to use the first method and change n depending on the current rotation speed. I've never tried this one though, it just bubbled up as a possible way to do it.
For integer math it is also possible to use the formula for method 1, but it needs to be scaled up a bit..with 0 <=n<= SomeValue and then divide the result by SomeValue afterwards (your intermediates may need a typecast to long int then depending on the value of SomeValue and the range of possible values). NewValue = ( NewValue * n + OldValue * (SomeValue - n)) / SomeValue :: with 0 <= n <= SomeValue _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Fri Mar 24, 2017 4:23 pm Post subject:
|
|
|
While a filter or interpolation can remove the step-ness by sort of filling in the values between what would otherwise be steps, the output of such methods will still ultimately be quantized. That is, with a filter or interpolation, given an input that goes from 43 to 44, can go 43, 43.1, 43.2, etc. until it reaches 44, but the value cannot be made to stay at 43.5 for example - it is quantized. To mitigate that, you will need to increase the resolution of the counter driven by the encoder. If you currently use 256 steps (with an 8 bit counter), you could increase the counter to say, 1024 steps. Then each step can represent 1/4 of the voltage difference that it previously represented. With enough resolution, you don't even notice that the steps are there and no filter or interpolation would be necessary. Of course, doing such a thing means that you now have to turn the knob 4 times as many turns to get the same result. I've had this problem myself (for an FPGA project). The encoder I had on the board had a knob that both turned the encoder and could be pushed. I used the button to tell the board whether I wanted coarse or fine control. Pushed in, each click of the encoder bumped the counter by 16 and unpushed, it bumped by one. So if I wanted to move the value quickly, I would push and turn until it was close to what I needed and then released the button and used fine control to get the precise value I wanted. Of course, it isn't required that the encoder have a such a pushbutton knob, alternatively, you could use another switch to select coarse/fine action. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Fri Mar 24, 2017 5:39 pm Post subject:
|
|
|
Ah yes Scott, true that . .and then you could use the accelerated mouse trick .. when moved fast it could go faster through the steps .. so no need then for a fine coarse selector. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Fri Mar 24, 2017 6:59 pm Post subject:
|
|
|
ah, yes, so you'd just twist a bit faster to go into coarse. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
|