gm02froe Posted October 26, 2007 Report Share Posted October 26, 2007 Hiis there a way to change the voltage range (instead of 0V...5V -> 0.4V...5V) that is translated into 127...0 values? Quote Link to comment Share on other sites More sharing options...
audiocommander Posted October 26, 2007 Report Share Posted October 26, 2007 http://www.midibox.org/forum/index.php?topic=10056.msg74922#msg74922else see the ACSensorizer, it's a specialized application for up to eight sensory devices delivering not exactly 0..5 VAn inverted signal is supported as well (127..0)http://www.midibox.org/dokuwiki/acsensorizer_04Best,Michael Quote Link to comment Share on other sites More sharing options...
gm02froe Posted October 28, 2007 Author Report Share Posted October 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
audiocommander Posted October 28, 2007 Report Share Posted October 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.