HawThorn Posted May 4, 2006 Report Share Posted May 4, 2006 Hello,Before working with the mios, I want to be sure that it can do what I want. So, is it possible to program a large translation map?I receive a CC, depend with the second value, I send a half sysex message. And with the first value, I send the other part of my sysex message.Is it possible?ThanksLaurent Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 5, 2006 Report Share Posted May 5, 2006 I think that sounds possible but it's not so clear what you're trying to do... Perhaps if you could share a little more information? Quote Link to comment Share on other sites More sharing options...
HawThorn Posted May 5, 2006 Author Report Share Posted May 5, 2006 Yes, a little bit more explanation:The sysex look like: F0 7F 01 02 01 01 YY 00 XX 00 F7So the first part of the sysex is like that: F0 7F 01 02 01 01 (3Z 3Z ) 3Z 00And the second part of the sysex like that: (3Z 3Z) 3Z 00 F7For YY (the second value of the control): it’s the value scale to 1-101, translate in ascii code, and put in the sysex.Some examples:0 ---> 1 ---> 3119 ---> 15 ---> 31 3560 ---> 48 ---> 34 38107 ---> 85 ---> 38 35127 ---> 101 ---> 31 30 31For the XX (the first value of the CC): it’s just the value translated in an ascii code and increase by 1Some examples for XX:0 ---> 1 ---> 3115 ---> 16 ---> 31 3649 ---> 50 ---> 35 3087 ---> 88 ---> 88 88103 ---> 104 ---> 31 30 34127 ---> 128 ---> 31 32 38So for exemple if the value CC 13 120 is coming in,the value sysex F0 7F 01 02 01 01 39 35 00 31 34 F7Or for the value CC 109 35, the value sysex F0 7F 01 02 01 01 32 38 00 31 31 30 00 F7Other for the value CC 16 49, the value sysex F0 7F 01 02 01 01 33 39 00 31 37 00 F7For the variable Y in the first part of the sysex, I can have an error of 2%.Well, actually, I use MIDI-OX to translate my CC and to be sure I have 256 entries. 128 for the first part of the sysex and 128 for the second part.Exemple :*,Ctrl,*,*,0,0,Y,0,*,SysEx,F0 7F 01 02 01 01 31*,Ctrl,*,*,28,28,Y,0,*,SysEx,F0 7F 01 02 01 01 32 32*,Ctrl,*,*,112,112,Y,0,*,SysEx,F0 7F 01 02 01 01 38 39*,Ctrl,4,4,*,*,N,0,*,SysEx,00 35 00 F7*,Ctrl,34,34,*,*,N,0,*,SysEx,00 33 35 00 F7*,Ctrl,114,114,*,*,N,0,*,SysEx,00 31 31 35 00 F7Well, I think, I must program it like this:If you receive the second value 00 from a CC then send 7F 01 02 01 01 31…if than you receive the second value 75 from a CC then send 7F 01 02 01 01 36 30… etcIf you receive the first value 00 form a CC then send 31 00 F7…if than you receive the first value 101 form a CC then send 31 30 32 00 F7… etcAnd perhaps clone the CC when it coming in…I hope I’m not too unmethodical in my explanations, if you can help me… Quote Link to comment Share on other sites More sharing options...
HawThorn Posted May 5, 2006 Author Report Share Posted May 5, 2006 Can I use a think like this? It’s not really beautiful, but...void MIOS_MIDI_Init(void) __wparam { if (evnt2 == 0x00) { // send the MIDI event F0 7F 01 02 01 31 00 MIOS_MIDI_BeginStream(); MIOS_MIDI_TxBufferPut(0xF0); MIOS_MIDI_TxBufferPut(0x7F); MIOS_MIDI_TxBufferPut(0x01); MIOS_MIDI_TxBufferPut(0x02); MIOS_MIDI_TxBufferPut(0x01); MIOS_MIDI_TxBufferPut(0x31); MIOS_MIDI_TxBufferPut(0x00); MIOS_MIDI_EndStream(); } //etc, etc, etc... for each my 128 values if (evnt1 == 0x00) { // send the MIDI event 00 31 F7 MIOS_MIDI_BeginStream(); MIOS_MIDI_TxBufferPut(0x00); MIOS_MIDI_TxBufferPut(0x31); MIOS_MIDI_TxBufferPut(0xF7); MIOS_MIDI_EndStream(); } //etc, etc, etc... for each my 128 values }on my network I can received only CC, so it’s not important for my to do a detection of event Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 5, 2006 Report Share Posted May 5, 2006 You can certainly do what you're trying to do with a MIDIBox :)I don't know if that code above this post is the best way or not, but I will leave the best method up to you :) Quote Link to comment Share on other sites More sharing options...
HawThorn Posted May 5, 2006 Author Report Share Posted May 5, 2006 Well, but is my code correctly programmed?If I send it (with the skeleton) in the MIOS, is it working? Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 5, 2006 Report Share Posted May 5, 2006 I don't think that it will work as above, no... I'm sorry but I don't have much time on my hands for writing code right now, and what you want to do is not trivial, so I think I should leave it to you. Quote Link to comment Share on other sites More sharing options...
TK. Posted May 5, 2006 Report Share Posted May 5, 2006 It will work with MIOS, and your code is a good starting point, because it will send something - so you will be able to debug this!However, checking for evnt2==0 is propably not correct, I'm missing the check for "evnt0==0xb0" (CC CHannel 1), etc... but I'm very sure that you will be able to complete the program by yourself once you've worked with the core module. Just try it, get some first experiences, and once you face a problem and you are not able to solve it by yourself, ask in the forum.Just two additional hints (beside of the missing evnt0==0xb0 check): use MIOS_MIDI_BeginStream() and MIOS_MIDI_EndStream() only once, not several times within a SysEx messages. For the beginning you could left it out, these functions are only required for the MIDIbox Link function (when several core modules are chained)Binary->BCD conversion: if this is really required, use MIOS_HLP_Dec2BCD, it's the simplest wayBest Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
HawThorn Posted May 6, 2006 Author Report Share Posted May 6, 2006 ok, thanks, I will test... It's the better way...Just a last question... about the memory of the PIC. How can I know if my programming code is too big for the memory without sending it in the PIC? Quote Link to comment Share on other sites More sharing options...
TK. Posted May 6, 2006 Report Share Posted May 6, 2006 When you are typing "make", you will see the allocated blocks after the linking phase (they are displayed be the hex2syx script). 0x7fff is the maximum on a PIC18F452. The linker will exit with an error, if this boundary is exceededI guess that you program currently doesn't allocate more than 2k, and by doing clever programming (e.g. use subfunctions for frequently repeated code, use data tables for a better oversight), you won't need more than 4k, so there will still be about 16k free for much more stuffBest Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
HawThorn Posted May 11, 2006 Author Report Share Posted May 11, 2006 Hello again,I finished the program. Well, not exactly. I do not understand perfectly how to use function which scales a value. Programming is hard for me :'(...I can use this :unsigned char Scale_7bit(unsigned char evnt2, unsigned char min, unsigned char max) { // scaled value is (<8-bit random> * ) >> 8 PRODL = evnt2 << 1; // 8bit value PRODH = max-min+1; // range __asm movf _PRODL, W mulwf _PRODH, 0 __endasm; return min + PRODH; } and evnt2 = Scale_7bit(evnt2, 0x01, 0x64);but I can't understand how it's working.I can't test actually, my PIC arrives in 2 week.So with the minimum value 0x01 and the maximum value 0x64... If I understand, when evnt2 have a value of 0x00 it become 0x01 and for a value of 0x7F it become 0x64. Other example, for 0x55 it become 0x44. The fonction stretch the value ?ThanksLaurent Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 11, 2006 Report Share Posted May 11, 2006 Let's see if I can get this right :)unsigned char Scale_7bit(unsigned char evnt2, unsigned char min, unsigned char max){ // scaled value is (<8-bit random> * ) >> 8 PRODL = evnt2 << 1; // 8bit value This shifts the contents of the first variable one digit to the right. This is to treat the 7 bit input as an 8 bit input. The last bit is filled in with a 0. PRODH = max-min+1; // range This subtracts the minimum from the maximum to determine the range that the input value (evnt2/PRODL) can span. __asm This is a marker to signal the beginning of code written in PIC ASM assembly code (Not C) movf _PRODL, W This moves the value in PRODL to the working register W mulwf _PRODH, 0 This multiplies W (the input value which has now been converted into 8 bits) with PRODH (the range between min and max) * See below for details! __endasm; This is a marker to signal the end of code written in PIC ASM assembly code return min + PRODH; This adds the minimum to the PRODH (The multiple of the input and the range)}*From the datasheet:MULWF Multiply W with fSyntax: [ label ] MULWF f [,a]Operands: 0 ? f ? 255a ? [0,1]Operation: (W) x (f) ? PRODH:PRODLStatus Affected: NoneEncoding: 0000 001a ffff ffffDescription: An unsigned multiplication is carriedout between the contents ofW and the register file location ’f’.The 16-bit result is stored in thePRODH:PRODL register pair.PRODH contains the high byte.Both W and ’f’ are unchanged.None of the status flags areaffected.Note that neither overflow norcarry is possible in this operation.A zero result is possible butnot detected. If ‘a’ is 0, theAccess Bank will be selected,overriding the BSR value. If‘a’ = 1, then the bank will beselected as per the BSR value(default) Quote Link to comment Share on other sites More sharing options...
HawThorn Posted May 12, 2006 Author Report Share Posted May 12, 2006 Thanks for this explanations… it’s become more limpid in my mind… Now I can use it, and I can understand it... Quote Link to comment Share on other sites More sharing options...
HawThorn Posted June 1, 2006 Author Report Share Posted June 1, 2006 Well... it's working... and making what I want... I'm happy ;D Quote Link to comment Share on other sites More sharing options...
stryd_one Posted June 1, 2006 Report Share Posted June 1, 2006 Nice one :)It'd be nice if you could share the code on the wiki, you could make yourself a user projects page :) 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.