Jump to content

How to Offset and Scale an Analog Input


Duggle

Recommended Posts

When interfacing a Joystick, Modwheel or Pitchbender it is sometimes found that the voltage range on the potentiometer output is well inside the range of the Core ADC input.

This can often be overcome with digital calibration in the firmware (e.g MIDIbox KB) in some cases there is extreme loss of resolution.

Presented here is a circuit to overcome this to give the ADC the full range (in this case 0..3.3V) even though the range of the potentiometer is well inside this.

The design process is very easily done following this app note:sloa097.pdf

I've done a spreadsheet to make it even easier!Scale Offset.zip If you don't have MS Excel, you can use it with free tools Google Docs, or Open Office.
To use the speadsheet you enter numbers into the blue fields. The input range at the top as measured on your pot. In preparing the examples, I played with the value of Rg2 so that Rg2+R1 came close to 10k. This allowed to replace them with a 10k trimpot as in the example circuits. It was just as well, as the trimpot did require some tweaking away from the calculated values, I found.

I chose LM324 op amp as it's output goes down very close to 0V. It's maximum possible output with a Vcc=5V is about 3.5V which should be quite safe with a 3.3V Core ADC such as LPC17 MBHP Core.
There are 4 op amps in this device, so 4 scaling/offset circuits can be implemented with 1 chip.

Here's the circuit with 2 worked examples:
gallery_3440_57_56775.jpg

Here's the test (input on left, output on right) showing 3 points (Modwheel example):
gallery_3440_57_231579.jpg

Here's another test (input on left, output on right) showing 3 points (Pitchbender example):
gallery_3440_57_53502.jpg

Edited by Duggle
  • Like 1
Link to comment
Share on other sites

That's good. What software did you use for the simulation?

Can you access the spreadsheet and pdf file attachments o.k? (I don't have 2 forum accounts to test it.)

[edit] I can now see there have been a number of downloads.

Edited by Duggle
  • Like 1
Link to comment
Share on other sites

Hello Duggle.
With pdf files and excel I have never had problems with downloading, only the pictures are not unloaded. now all ok.
As a simulator I use NI Multisim.
tomorrow I build the PCB of your project so let's see how it works in life.

thank you very much!

Link to comment
Share on other sites

One more thing:

from playing with the speadsheet, it looks as though Vref can be equal to 5V rather than 3.3V. 

This means one less connection to your PCB. 

If you do this the position of the trimpot will be a little different and the gain is less by 1 or 2%. Which should be fine, the most important thing setting up this circuit is to make sure the ADC does not saturate, (i.e make sure 0.0V<Vout<3.3V across the range of your modwheel.)  Then do final calibration in firmware. 

Link to comment
Share on other sites

Make sure you use an IC socket, because MC33079 (according to my reading of the data sheet) outputs >1.0V above  GND at minimum output. This is common with op amps.

Thus, I don't think MC33079 will work well.

This is why I specified LM324.

Don't worry, they're pin compatible, easy to swap.  

Link to comment
Share on other sites

hello! I used LM324 and I managed to get the correct volts.
there a problem with pitchbender. trying with Midistudio, I saw that modwheel never stands still at zero, it always turns. I tried using the potentiometers without your circuit and behaves the same. I think there still to be done on the software.

 

thank!

Link to comment
Share on other sites

  • 2 weeks later...

Hello Duggle!

As I wrote above I built the circuit with lm324 and I managed to get the right volts. problem and that there too much sensitivity in software midibox kb regard to the potentiometers. This thing or noticed even in MIDIO 128 V3 with potentiometers. Do you think that the programmer can do something to improve this problem?

 

THANK!

Link to comment
Share on other sites

TK does say that the LPC17 analog inputs (as implemented on the core PCB) are very jittery and instead recommends AINSER solutions for pots etc.

I've used the LPC17 Ain on my MIDIbox KB modwheel and pitchbender and they seem o.k to me for that purpose.

Link to comment
Share on other sites

I use MIDIBOX kb, with varranger software, since I enabled Pitchwheel and modwhwell my varranger and become crazy. when I have time, I'll make a recording. In my opinion, too many midi commands sent from midiboxkb makes them dizzy.

Link to comment
Share on other sites

Thanks for the reply! I have already drawn Ainser for 20 pot. Saturday prepare the pcb, after I tell you if that's okay. still remains the problem of pitchweel and modweel.
It might be possible to connect the pitchweel and modweel of ainser64?
THANK!

Link to comment
Share on other sites

It might be possible to connect the pitchweel and modweel of ainser64?

Correct!

Remember to recalculate the resistances for 0..5V output (hint: use the spreadsheet, let me know if problematic, change the values so that only one resistor need be re-soldered, if any)

You may be lucky and just a tweak of the trimpot(s) is all that is required. 

Link to comment
Share on other sites

hi !  I think the correction is not a problem.

MIDIBOX KB supports Ainser 64?   I just need 2 pot.

thank!

Not sure what you mean, I thought you were planning on using the same modwheel and pitchbender which have limited range, and hence the scaling and offset is still required.

 

[edit] I forgot that the op amp requires a +ve rail about 1.5V higher that the maximum desired output voltage. For a 5V output, this implies a required +ve supply of >6.5V which may be inconvenient. It might therefore be appropriate to go back to just digital calibration, given that the ADC reading with the AINSER converter will have better resolution ( as well as less jitter).

Edited by Duggle
Link to comment
Share on other sites

hello Duggle.
I took pictures. so see the messages that sends modwheel.
I noticed that when I move modwhell, the processor of the computer increases the workload of 8-10% so my varranger slows the song.
I also use a Korg 01/wpro as a master keyboard, but does not give me problems.
I also tried with another computer, and I laid out the problems.
thank!

post-11336-0-21355000-1366758295_thumb.j

post-11336-0-02610100-1366758307_thumb.j

post-11336-0-03882900-1366758320_thumb.j

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...
×
×
  • Create New...