Jump to content

Recommended Posts

Posted

Hi! I'd like to add a pot calibration feature to my project. When a pot is turned to max position (1023 or less if smaller operation range for pot is wanted), the MAX value is stored. Also MIN value (0 or whatever the value is) is stored. Then after the calibration, A/D conversion values between MAX and MIN scaled to 0-127. Is this possible in assembler?

Posted

Hi,

it's difficult, but not impossible.

Basically the formula is: (128 * (POT_VALUE-MIN))/(MAX-MIN)

This has to be calculated in fixed point arithmetic.

Let's check the required value range for the worst case (MIN=0, MAX=1023, POT_VALUE=1023):

dividend: 128*(1023-0)) = 130944 (thats a 17 bit value)

divisor: (1023-0) = 1023 (thats a 10 bit value)

To calculate the dividend, a multiplication with 128 is required. This can be done by leftshifting (POT_VALUE-MIN) 7 times. In addition, we have a 16bit substraction.

The divisor has to be calculated with a 16bit substraction as well.

The divison will be 24/16 bit

I've an example here: http://svnmios.midibox.org/filedetails.php?repname=svn.mios&path=%2Ftrunk%2Fapps%2Fsynthesizers%2Fmidibox_sid_v2%2Fsrc%2Fmath_div24_16.inc

In the MBSID source code you will also find many examples for a 16bit substraction and for leftshifting values if required (I don't know your knowledge level, unfortunately you forgot to introduce yourself!)

Best Regards, Thorsten.

Posted

Thank you for your answer! That looks difficult indeed, but I'll study this method and see if I have enough skills. Actually I had some thoughts that apparently went to the right direction, but I couldn't build up any formula to do this. I've been programming pics in assembly for a year now, and I have learned a lot.

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...