Jump to content

Fast Scan Matrix 4


robinfawell
 Share

Recommended Posts

I'm having some problems in trying to use a rotary switch to change the the Midi Channel.

There are some unused Shift Registers locations that I refer to as BANK 0 and BANK 1. See attached Table

I have allocated pins 80, 81, 82, 83 to the pins of the the HEX switch and had hoped to generate values (1 - 9) and (a - f).

I have used pins 84 and 85 to connect to the soft pedal and the sustain pedal switches.

The code for both is shown

	

	//non-key switches 

	if((column >=0 && column <=7 ) && (row >= 10 && row <= 11)){

	pin = 8* row + column;

	if(pin == 84 && pin_value == 0) { // send  soft pedal CC   

  MIOS32_MIDI_SendCC (KEYBOARD_MIDI_PORT,KEYBOARD_MIDI_CHN,  67, 	127 ) ;}

   if(pin == 84 && pin_value == 1) {

  MIOS32_MIDI_SendCC (KEYBOARD_MIDI_PORT, KEYBOARD_MIDI_CHN,  67, 	0 );}


   if(pin == 85 && pin_value == 0)  {// send  sustain pedal CC 

   MIOS32_MIDI_SendCC (KEYBOARD_MIDI_PORT,KEYBOARD_MIDI_CHN ,  64, 	127 );}

   if(pin == 85 && pin_value == 1)  {

   MIOS32_MIDI_SendCC (KEYBOARD_MIDI_PORT,KEYBOARD_MIDI_CHN ,  64, 	0 );}


   //channel select

   //uses pins (80 - 83) with 16 bit rotary Switch to give (0 - 9, a - f) 



	"Red Code"

	if (pin == 80 && pin_value == 0) { w = 1;} //lsd bit

	if (pin == 80 && pin_value == 1) { w = 0;} //lsd bit

	if (pin == 81 && pin_value == 0) { x = 2;} 

	if (pin == 81 && pin_value == 1) { x = 0;} 

	if (pin == 82 && pin_value == 0) { y = 4;} 

	if (pin == 82 && pin_value == 1) { y = 0;} 

	if (pin == 83 && pin_value == 0) { z = 8;} //msd bit

	if (pin == 83 && pin_value == 1) { z = 0;}	//msd bit

	//Chn = (w + x + y + z);

        "End of Red Code"


 	MIOS32_MIDI_SendCC (KEYBOARD_MIDI_PORT,(w + x + y + z) , 30 , 0);// 30 (0x1e)undefined, 0 arbitrary


	}

	//right hand keys

The system does change the midi channel but the code in red does not work. I get only get a few channel values.

I suspect that the switch is no compatible and that the scan matrix is not suitable.

Is this suspicion correct?

I also think that I may be able to use a rotary switch where only only one pin of (say) 8 pins is connected to 0V at any time. (break-before-make type.) I think that any bounce would be tolerable. (giving multiple midi channel requests for the same channel)

Does this make sense.

Should I use the MIOS32 Encoder Functions with rotary edge hex switches?

Thanks

Robin

After I sent the above I read about the use of encoders with J5. These inputs configured as digital inputs will hopefully allow me to use three rotary hex switches without any more SR's. Three such switches will allow me to control the Midi Channel No and the other two will be used to adjust the keyboard_delay_fastest and

keyboard_delay_slowest variables.

Is this the way to go?

Connectin Diagram MIOS 32 Fast Scan with extra switches.doc

Edited by robinfawell
Link to comment
Share on other sites

Dear All

I have moved on a little since the previous message. One thought is to use J5 A,B and C pins. It seems possible to use the 12 pins, 8 pins could be configured as digital inputs and up to 4 pins as digital output.

The combination could be used with diodes to provide a 4 X 8 diode matrix. This would provide more than enough scanned pins for my current needs needs.

I will use Tutorial 5 and 6 as a starting point.

I'm not too sure about the integration with Thorsten's Fast Scan Matrix example and the RTOS aspects.

More later.

Robin

Link to comment
Share on other sites

I have progressed a little using Tutorial 006 RTOS and have programmed the behaviour of the hex and other switches to J5 inputs. I used a lead connected to OV as the ""row enable" for my 2 X 8 matrix using J5.

I then tried to use pin 8 and 9 of J5 as outputs. I have initialised the pins as follows

 MIOS32_BOARD_LED_Init(0xffffffff);


  // initialize  pins  0 - 7 of J5A, J5B and J5C as inputs with internal Pull-Up

  int pin;


  for(pin=0; pin<8; ++pin)// only 8 Inputs - leaves 4 Outputs

    MIOS32_BOARD_J5_PinInit(pin, MIOS32_BOARD_PIN_MODE_INPUT_PU);

	for (pin=8; pin <12; ++pin)

	MIOS32_BOARD_J5_PinInit(pin, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);

and have programmed the output pin to be 0V as follows.
//s32 MIOS32_BOARD_J5_PinSet	(	u8 	pin, u8 value)	

//set J5 pin 8 to 0

	MIOS32_BOARD_J5_PinSet	(8, 0);	 

I have checked all 4 output pins they are all 3v.

I have looked at the code on MIOS32_BOARD .c but can not see that I have overlooked anything.

It seems to me that I should be able to use J5 pins to make a small diode matrix. I have assumed that it is possible to have 8 inputs and 4 outputs. Perhaps I am mistaken or is it a coding problem?

Please help.

Robin

I now realise that I can change the pin polarity of any J5 pin programmed as an input and that I don't need to have outputs to do this! Sorry!
Edited by robinfawell
Link to comment
Share on other sites

I sent this message before. After sending it, I thought that I could program the input to the input using "J5 set" It may well have this effect, internally but it will not drive my diode matrix.I need a Digital output.

Have a look at the initialisation code.

Can you mix the 12 pins between inputs and outputs? Also is the output mode pp the correct one? For that matter is the input mode correct?

I have progressed a little using Tutorial 006 RTOS and have programmed the behaviour of the hex and other switches to J5 inputs. I used a lead connected to OV as the ""row enable" for my 2 X 8 matrix using J5.

I then tried to use pin 8 and 9 of J5 as outputs. I have initialised the pins as follows

 MIOS32_BOARD_LED_Init(0xffffffff);


  // initialize  pins  0 - 7 of J5A, J5B and J5C as inputs with internal Pull-Up

  int pin;


  for(pin=0; pin<8; ++pin)// only 8 Inputs - leaves 4 Outputs

    MIOS32_BOARD_J5_PinInit(pin, MIOS32_BOARD_PIN_MODE_INPUT_PU);

	for (pin=8; pin <12; ++pin)

	MIOS32_BOARD_J5_PinInit(pin, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);

and have programmed the output pin to be 0V as follows.
//s32 MIOS32_BOARD_J5_PinSet	(	u8 	pin, u8 value)	

//set J5 pin 8 to 0

	MIOS32_BOARD_J5_PinSet	(8, 0);	 

I have checked all 4 output pins they are all 3v.

I have looked at the code on MIOS32_BOARD .c but can not see that I have overlooked anything.

Perhaps I have a coding problem?

I have tried many variations but I cannot manage to change the state of the the output pins 8 and 9. I'm very frustrated!

I will appreciate any help.

Robin

Edited by robinfawell
Link to comment
Share on other sites

Ooofff.. sometimes you're doing challenging projects ;)

Pin #8 and #9 should work as outputs with your initialization routine.

I just have doublechecked this on my board.

You could measure the voltage directly on the pins of the STM32 chip (see schematic), just to ensure that they are correctly soldered.

To the original problem (connect the switch to the scan matrix, first topic of this post):

did you already add some debug messages just to check if and when the routine is executed, and what are the results in w/x/y/z on any switch movement?

Such messages are really helpful to get a better understanding of the internal processing

Best Regards, Thorsten.

Link to comment
Share on other sites

Thanks Thorsten

It was useful to have the confirmation that J5 could have a mix of inputs and outputs.

I looked at the connections again and found that I had transposed 2 of the 3 cables to the small J5 diode matrix board. Silly me! At this point in time I have proved that MIOS32_BOARD_J5_PinSet works for both pins 8 and 9.

Now I need to program these operations sequentially.

Once this task is completed I need to integrate the modified 006 RTOS tutorial into the Fast Matrix Scan Example.

You will recall that I initially tried to use the Fast Scan Matrix Example with the 2 Pedals and 3 hex switches. The Pedals are made by the keyboard manufacturer, Fatar. They seem to be using the same type of switch for the pedal as they use for the keys ie a membrane switch; this type seems to have little or no bounce. It worked fine with the Pedals but gave unpredictable results with both types of hex switch. The Midi Channel switch will be fitted on the small console is a Cherry type Series E (0-9, A-F). The other type will be used to control the Delay variables to alter the velocity response. These will not be on show, They are a small pcb type and are are mounted on the J5 Diode Matrix board.

The problem I think is that the Fast Matrix scan program deals with detecting 1-0 transitions. The hex switches rely on 4 wipers making contact with pcb tracks arranged to produce a parallel 4 output Hex code. There is an inherent lack of precision whereby the final contact should produce a 1 but is preceded by a 1-0 transition. The 1 state will not be detected. Hence an error is made.

For these reasons I decided to opt for the J5 matrix approach.

Many thanks again.

Robin

Link to comment
Share on other sites

You could do the same with the matrix approach by implementing some kind of "low pass filter".

Just define a global counter, and a second variable which stores the state of the hex switch.


u8 hex_switch_counter = 0;
u8 hex_switch_state = 0;
[/code] In BUTTON_NotifyToggle change the state according to the pin change, and set the counter to a certain value - let's say 50 Don't react immediately on this change (e.g. don't send a MIDI event) Instead, add following routine to TASK_MatrixScan()
[code]
if( hex_switch_counter ) {
--hex_switch_counter;

if( !hex_switch_counter) { // counter reached 0
// do something with hex_switch_state...
}
}

In other words: whenever the hex switch changes it's state, wait for 50 mS before doing something with the new state.

Best Regards, Thorsten.

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