How can I treat bass pedals as a matrix?

Started by David, March 24, 2006, 08:56:59 AM

Previous topic - Next topic

David

I had been working on a version of Thorsten Klose's "Floorboard" project at www.ucapps.de from October through February.  I had my PIC16F877 working just fine - except there was one function I just COULDN'T implement because I couldn't seem to add any more pushbuttons.  I had 16:  13 bass pedals and 3 selector pushbuttons straddling both PORTB and PORTD.  I was bogged down with case construction details.  Then my computer crashed --  fatally -- and took all my stinkin' code with it.  My PICS? Well, the last executable I burned into them was experimental and didn't work.  Yup, I'm startin' all over again.

Since that's the case, I thought I would take a shot at implementing ALL the functionality I want this time.  I want to have 13 bass pedals (C-C), 2 buttons for octave up/down, 1 button for harmony mode AND 1 or 2 more to send MIDI program change commands to my NanoBass so I can select the patch of my choice.

PORTC and PORTA are defined as outputs.  I tried using the RX pin and this really trashed the scanning logic.  I'm thinking a matrix is the way to go.  I've seen code snippets for handling a hex keypad.  Most of them expect a single button press.  I need to be able to trap the button release as well so I can send a MIDI "all notes off" if a note had been playing.  Now, on www.winpicprog.co.uk, Nigel Goodwin has a couple of projects to work with a hex keypad using a PIC16F628.  Tutorial 9, snippet 4 (I'm not going to post someone else's code -- sorry) is supposed to be an example of being able to hold down a matrixed pushbutton.  Could some PIC guru please look at this example and tell me if it would work -- and what I'd have to do to port it to a PIC16F877?  Please?

The other thing is that my bass pedalboard is set up so that all the pedals are wired for a common ground -- just like the Floorboard wants.  I would have to get rid of this and wire my pedals and my pushbuttons in the desired matrix pattern, right?  With 13 pedals and 5 selector pushbuttons,  I'm thinking I could just bump up the standard 4x4 keypad matrix to a 5x4 matrix and give myself 2 empty "slots" to use later.  Will this work, or am I missing something?

Dave_B

That's the way I've seen it done.  If you look at page 2 of this pdf, you'll see a pretty typical keyboard matrix.  Drop three of those lines and you'll have a 5x4.

Right now it sounds like you're reading the pins directly.  You'd need to add a scanning routine that would read the switches sequentially and put the results in three memory locations.  Once a scan is complete, you could use your existing code to look at those memory locations instead of the pins.  Unless I'm way off base, it should be a pretty simple mod.

I ran into a similar problem trying to light up a bunch of LED's sequentially.  I ran out of pins on my 16f877a.  I set the LED's up in banks of eight, switching the banks with 2n3904's. 

Does that help?

Also, can you try downloading the .hex file from your chip and disassembling it?  I've not done that, but it's worth a shot if you've made a lot of changes to the original code.
Help build our Wiki!

David

That matrix looks cool.  What's with the diodes, though?  Nigel's setup didn't have those.  He used pull-up resistors.  Oh, crap!  I would have to disable the internal pullups on PORTB, wouldn't I?

I thought about trying to disassemble the hex.  My assembler isn't good enough to reverse-engineer what I had.  I had my source documented and commented to a fare-thee-well so I knew exactly what was going on, anywhere, anytime.  That knowledge was hard-won, believe me!
And now it's gone...  for awhile...  but I am starting to remember what I did.

Dave_B

The diodes take care of what's known as 'ghosting.'  Basically, without the diodes, you can get erroneous data from the keys if you press multiple switches at a time.  Here's a page that explains it much better than I ever could.  Take a look at #6 Three Simultaneous Key Presses and Ghosting.

I'm not sure how the floorboard is coded but since you're re-writing it, is there a reason you need to keep the pull-up resistors enabled?  It's a pretty straightforward register change disable them if I remember right. 
Help build our Wiki!

David

#4
Let's both get on the same page of the choir book.  The way the Floorboard is implemented, the pushbuttons are treated as kind of a shift register.  If a pedal or button is pressed, the corresponding pin goes high.  I don't get it, but it works.  I went with it.  I just couldn't get it past 16 inputs.  It does not treat the buttons like a matrix.  The Floorboard is designed to utilize the weak pull-ups on PORTB's pins.  If I matrix my buttons, though, I don't need a pull-up on every input pin - internal or otherwise.

Since I seem to be limited to using only PORTB and PORTD as input registers, I figured I'd better matrix my pushbuttons.  I don't understand how I would use standard keypad scanning since I have to trap both "key pressed" and "key released" events.  I thought about setting a flag if notes were playing.  That way, if the keyboard scan showed nothing was pressed and the flag was set, the pedal would supposedly have been released and I could issue the "all notes stop" message.  I'd rather not use such a hokey method, though.  Nigel's tutorial 9, program 4 is designed to be a TV remote and is supposed to be able to handle buttons being held down.  That's why I thought it might be a good candidate to borrow code from.

Don't get me wrong.  I appreciate the help.  It's just that this kind of communication takes so frickin' long to accomplish anything and I have so little time to work on projects.  I'm tired of this bass pedal controller now.  I just want to get it built and move on to something else.

Dave_B

I understood, you.  I didn't know if there were other pins that required the pull-ups.

Like I said, all you really need to do is write a subroutine to scan the ports and dump the results in memory.  You should be able to modify your existing code to read those locations in memory (instead of reading the pins directly). It can happen at least several hundred times a second, so for all intents and purposes, you will be setting flags if notes are playing.   The flags will be cleared when you release a switch.  A panic button is always nice to include, but you don't need to issue an all-notes-off as a fail safe.

I realize this is for footswitches, but you might want to look at the code used for synth keyboards instead of remote controls.  The synth code is obviously designed to handle multiple keys at the same time.  That can be important if you accidently step on two at once.  It will sound wrong, but at least you can know what to expect.
Help build our Wiki!

David

Dave:

Found some synth code.  I'll compare it to Nigel's.  I guess the trick is just in the repetetive scanning.  Seems too simple to me, but if it works...
Sure would be nice to get that extra functionality!

Dave_B

That's the thing.  Some of this stuff is deceptively simple.  Keyboard matrixes are one of them.  You're right though, it's not easy working through this kind of thing on a forum.  Conceptual conversations have their place, but sometimes you just want the freakin' code so you can be done with the thing.   ;D  I wish I had the time (and a functioning PIC programmer) to help, since it can also be applied to other things (like remotely controlled rackmount effects).
Help build our Wiki!

David

Quote from: bellyflop on March 25, 2006, 01:44:16 PM
I wish I had the time (and a functioning PIC programmer) to help, since it can also be applied to other things (like remotely controlled rackmount effects).

Ummm...  I found mine on eBay.  Spark Fun Electronics also has the PG2C available cheaply.  Self-powered through a DB-9 connector.  Doesn't work well with laptops, though.

R.G.

QuoteConceptual conversations have their place, but sometimes you just want the freakin' code so you can be done with the thing.
Yep. That was one of the advantages of PICs that I listed - there is a ton of pre-existing code you can just pick up and use.

For keyboard scanning, check the PIC list reference that I listed before.

At the risk of being repetitive, you can get a PIC programmer kit for $35 that plugs into and is powered by the USB port. It programs all the flash PICs except perhaps the newest ones, needs no external power supply, and comes with a free program for doing the actual programming.

Yes, sometimes you're tired of the conceptual and just want it to work.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

Dave_B

Quote from: David on March 26, 2006, 07:04:45 AM
Quote from: bellyflop on March 25, 2006, 01:44:16 PM
I wish I had the time (and a functioning PIC programmer) to help, since it can also be applied to other things (like remotely controlled rackmount effects).
Ummm...  I found mine on eBay.  Spark Fun Electronics also has the PG2C available cheaply.  Self-powered through a DB-9 connector.  Doesn't work well with laptops, though.
Right.   ;D  The problem is, I've just spent $100 on Atmel stuff, so I'm focused on that at the moment.  I was using the PG2C on my desktop until it stopped working a couple of months ago.  I actually coding something similar to what we're talking about.  I need to control my two delays and I don't want seven cables running from the pedal board to the rack.  I just got the switch code to work the way I want, so I'm a ways off.    :)
Help build our Wiki!

Dave_B

Quote from: R.G. on March 26, 2006, 08:52:28 AM
QuoteConceptual conversations have their place, but sometimes you just want the freakin' code so you can be done with the thing.
Yep. That was one of the advantages of PICs that I listed - there is a ton of pre-existing code you can just pick up and use.
That definitely true, especially with regard to assembler.  AVR's seem to emphasize C, so it's not been a smooth start for me. 

IMO, once you learn how to configure the damn things, the rest can be learned pretty quickly regardless of brand.  If I'd known on Thursday I also needed an "SEI" command to enable interupts...
Help build our Wiki!


David

I knew about Scarff's unit.  It looked too intimidating to me.  Klose's unit was friendlier and simpler.

David

Answer:  very carefully...   ::)

One issue is that much of the keypad code I looked at only checked whether you pressed the button.  It couldn't process how long you pressed the button or when you let it up.  In a bass pedal application, you would expect the note to continue as long as you hold the pedal down.  OK, so now you have "pedal down" and "pedal up" events to check.  For note generation, this is easy.  If you also have keys assigned to modify functionality, it's not enough to just know one of them was pressed.  You have to remember which one was pressed and then wait until the next time the matrix is idle to process the key depression.  That's how I see it, anyway.

I'm simulating a bass pedal/function button matrix with a matrixed hex keypad.  I simulate playing notes by assigning a number to keys 1-13 and displaying that number with LEDs as long as the key is held down.  I can detect when a "note" or a "function" is pressed, and which one is pressed.  My code to execute the function(s) has been proving...  interesting.

I'll check back periodically...

David

Another thing is that a lot of the keyboard code I've researched since beginning this quixotic quest uses interrupts -- which I wanted to avoid as much as possible.  I hoped to handle my scanning purely by polling.  So far, I'm getting there.  However, I haven't tried anything with displaying data on LED digits or sending MIDI data yet.  At the rate I'm going, it'll be the end of this week before I'm using LED digits - which doesn't bother me because I've learned a lot just from displaying data in binary on LEDs.  Multiplexing PORTB between the keypad and the 4511s could prove...  fascinating.

David

My keypad post-processing came together amazingly fast.  I got it working last night.  I'm now working on the code and circuitry necessary to link the first 4511 to my PIC to display the currently-selected octave number.  After that comes the selected harmony mode.
Stay tuned...

David

Multiplexing PORTB was a total bust.  Fortunately, it looks like I won't have to do it.  Two things happened in the meantime.  I figured out how I could use another 628 as a display processing slave.  I could have used this and this alone to display 2 digits if I had chosen this approach.  I think I'll keep it in my back pocket.  Could come in handy.  The other thing is that I was able to generate a MIDI note at 4MHz.  This means I get two more pins on PORTA because I won't have to mess with an external crystal.  Even better, I figured out how to send the MIDI data on RA4.  I stuck a pullup resistor to get around the open collector issue and boom!  MIDI!  Not much, but it's a start.

OK, so I have the keypad stuff working (once I pull out the multiplexing crap), I can send MIDI data on RA4 so I won't waste any pins and I don't need a crystal so I can use RA6 and RA7 as digit enable lines for the 4511s.  I can put the BCD data for the 4511s on RA0-RA3.

Oh, yeah, I also have to rewire my bass pedals as a matrix.  Could be interesting!  Down the road yet, though!

This is starting to be fun!!

David

I plug away on this thing a little bit each day.  I can now trigger notes with my keypad.  I can successfully change octaves up and down.  I have a button I can use to select no harmony or two notes that are an octave, a fifth or a third apart.  My code is substantially cleaner than it was when I started.  Unfortunately, I introduced a bug when I converted the most-repeated blocks of code in my program into two macros.  As a result, it would handle the function buttons just fine, but continue playing the first note pressed ad infinitum until another function button was pressed.  Oh, well, easy fix.

Next are the steps I've been dreading:  Converting the pedals and function buttons into a matrix, and building some kind of a box around the electronics.  I was thinking about just using some pieces of quarter-inch Plexiglas or Lexan and just leave them clear.

toneman

Hey D,  U didn't build the PIC programmer that came with The Book??

I used mine to easily burn F84A's;  don't know if it can burn F628's,
but, i'll bet The Book's web page has some updated software(?)
Reguarding encoding a keyboard, see Friendy Stories byJohn Simonton.

T
  • SUPPORTER
TONE to the BONE says:  If youTHINK you got a GOOD deal:  you DID!