Jump to content

AIN range change


gm02froe
 Share

Recommended Posts

http://www.midibox.org/forum/index.php?topic=10056.msg74922#msg74922

else see the ACSensorizer, it's a specialized application for up to eight sensory devices delivering not exactly 0..5 V

An inverted signal is supported as well (127..0)

http://www.midibox.org/dokuwiki/acsensorizer_04

Best,

Michael

Link to comment
Share on other sites

thank you for the hints. I solved it the following way:

unsigned char Math_Scale10BitTo7Bit(unsigned int v, unsigned int min10Bit, unsigned int max10Bit, unsigned char min7Bit, unsigned char max7Bit) __wparam
{
	// scales an 7-bit (0-255) value between min & max
	unsigned char scaled = 0;
	unsigned long promille;
	if(min7Bit <= 0){min7Bit = 0;}
	if(max7Bit > 127){max7Bit = 127;}
	if(min10Bit <= 0){min10Bit = 0;}
	if(max10Bit > 1023){max10Bit = 1023;}

	if(min10Bit <= v && v < max10Bit && min7Bit < max7Bit){
		promille = (unsigned long)(v);
		promille = (promille - min10Bit) * 1000 / (max10Bit - min10Bit);
		scaled = (max7Bit - min7Bit + 1) * promille / 1000 + min7Bit;
	}else if(min10Bit > v){
		scaled = min7Bit;
	}else if(max10Bit <= v){
		scaled = max7Bit;
	}
	return scaled;
}
this way I can call the method like this:
void AIN_NotifyChange(unsigned char pin, unsigned int pin_value) __wparam
{
  // a pot has been moved, send CC#<pin-number> at channel 1
  MIOS_MIDI_BeginStream();
  MIOS_MIDI_TxBufferPut(0xb0); // CC at channel 1
  MIOS_MIDI_TxBufferPut(pin);  // pin number corresponds to CC number
  MIOS_MIDI_TxBufferPut(Math_Scale10BitTo7Bit(MIOS_AIN_PinGet(last_ain_pin), AIN_10BITMIN, AIN_10BITMAX, AIN_7BITMIN, AIN_7BITMAX));
   MIOS_MIDI_EndStream();

  // notify display handler in DISPLAY_Tick() that AIN value has changed
  last_ain_pin = pin;
  app_flags.DISPLAY_UPDATE_REQ = 1;
}

and not to forget:

AIN_DEADBAND  = 5 (I dont really understand how deadband really works, this value is experimental)

plus http://www.ucapps.de/mios/mios_libsdcc_v2_5_0.zip - which is the library for my humble java-like calculations.

Link to comment
Share on other sites

Hi t0gg1e4u,

although your code seems mathmatically correct, one should add that the heavy use of unoptimized divisions (and to some extend multiplications) may introduce various codesize and timing problems;

surely not if you just turn slowly one knob at a time, but I'd expect strange behaviours under heavy load (many quick changes on multiple inputs).

Please understand this as a final comment: if it works for you, it should be fine  ;)

Best,

Michael

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