Jump to content

resistor question


squeal
 Share

Recommended Posts

So, due to the peculiarities of the guitar synth resistive fretboard shenanigans, I am looking at a design where the output voltage from the fretboard would be between 2.5 and 5 volts.

Is there a way to fix this in the code? I would want 2.5V to send a 0 CC value, and 5V to send a 127(max) CC value. Linear scaling in between.

I did look at the example at the bottom of this page:

http://www.ucapps.de/mios_c.html

but it seemed that that would only change the max and min midi values. I want to change the max and min AIN input values.

Does this make sense?

Link to comment
Share on other sites

what about something like

if (pin_value >= 64) then {

pin_value = (((pin_value-64) /63) * 127)

}
or uhmmm
if (pin_value >= 64) then {

pin_value = (((pin_value-64) *2 )

}

Or something

You can optimise this a LOT if needed. I haven't applied much thought to this so uhm... it probably doesn't make sense ;)

Link to comment
Share on other sites

not sure what you mean by "the code", so I expect you code your own app in C:

if you have exactly 2.5 to 5 Vs that's quite easy:

Get the value as 10bit...

0-5 V = 0..1023

2.5-5 V = 512..1023

...and you just have to bitshift the signal (divide by 4) to get a range between 0..127 =>

[tt](v - 512) >> 2[/tt]

no need for complex divisions or multiplications...

best,

Michael

Link to comment
Share on other sites

Heh I knew you'd have the answer on this AC, I was thinking as I typed "I'm totally rushing this and I'm sure AC will come along in 5 minutes with the right answer anyway, maybe I should hit CTRL+F4" ;)

no need for complex divisions or multiplications...

Definitely not. My post was more intended to demonstrate the concept, I wasn't sure if squeal is familiar with bitshifting and it's advantages? Anyway it could be:

pin_value = ((pin_value-64) <<1 )
The compiler will optimise *2 to <<1 anyway, but it's better to specify it. Problem is, because we are scaling up from 63 to 127,we are generating 7bit from 6bit, so there's a loss of resolution.
Get the value as 10bit....and you just have to bitshift the signal (divide by 4)
pin_value = ((pin_value-512) >>2)

Much better that way!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...