DIYstompboxes.com

DIY Stompboxes => Digital & DSP => Topic started by: David on March 24, 2006, 08:56:59 AM

Title: How can I treat bass pedals as a matrix?
Post by: David on March 24, 2006, 08:56:59 AM
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?
Title: Re: How can I treat bass pedals as a matrix?
Post by: Dave_B on March 24, 2006, 09:27:25 AM
That's the way I've seen it done.  If you look at page 2 of this pdf (http://www.sowa.synth.net/midi/midi4bcplusman.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.
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on March 24, 2006, 09:36:04 AM
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.
Title: Re: How can I treat bass pedals as a matrix?
Post by: Dave_B on March 24, 2006, 10:00:37 AM
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 (http://www.dribin.org/dave/keyboard/one_html/) 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. 
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on March 24, 2006, 10:16:02 AM
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.
Title: Re: How can I treat bass pedals as a matrix?
Post by: Dave_B on March 24, 2006, 11:38:16 AM
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.
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on March 25, 2006, 07:52:42 AM
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!
Title: Re: How can I treat bass pedals as a matrix?
Post by: Dave_B on March 25, 2006, 01:44:16 PM
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).
Title: Re: How can I treat bass pedals as a matrix?
Post by: 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.
Title: Re: How can I treat bass pedals as a matrix?
Post by: 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.

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.
Title: Re: How can I treat bass pedals as a matrix?
Post by: Dave_B on March 26, 2006, 11:29:18 AM
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.    :)
Title: Re: How can I treat bass pedals as a matrix?
Post by: Dave_B on March 26, 2006, 11:48:21 AM
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...
Title: Re: How can I treat bass pedals as a matrix?
Post by: Maneco on March 26, 2006, 01:18:49 PM
http://tomscarff.tripod.com/bass_pedal/midi_bass_pedal_1.htm


code:


http://tomscarff.tripod.com/downloads/mbpe_877.zip


;)
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on March 26, 2006, 09:59:05 PM
I knew about Scarff's unit.  It looked too intimidating to me.  Klose's unit was friendlier and simpler.
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on August 14, 2006, 01:21:06 PM
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...
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on August 14, 2006, 03:12:56 PM
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.
Title: Multiplexing inputs and outputs on PORTB
Post by: David on August 15, 2006, 12:56:03 PM
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...
Title: Well, screw multiplexing PORTB...
Post by: David on August 17, 2006, 11:33:26 PM
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!!
Title: Almost got the circuit and code
Post by: David on August 29, 2006, 12:08:30 PM
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.
Title: Re: How can I treat bass pedals as a matrix?
Post by: toneman on September 28, 2006, 10:02:46 PM
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
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on September 29, 2006, 08:43:19 AM
Quote from: toneman on September 28, 2006, 10:02:46 PM
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

Actually, I've had a PIC programmer for over a year.  I snagged a PG2C off Evilbay for about five bucks.  It works just fine for both 628s and 677s except I have to use it with a desktop so that means traipsing upstairs to program a PIC.  I had bought a pedalboard from a small spinet organ about the same time.  It's really a bunch of normally-open momentary-contact pushbuttons that are wired to a common ground.  What I'll need to do is separate them all from the common ground and wire them into rows and columns.  Shouldn't be hard, but I have to be careful, so it'll be time-consuming.
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on June 29, 2007, 09:31:43 AM
It's been quite a while since I've done anything with this.  It went into stasis because of other, higher-priority items...  you know the drill.  In addition, a lot of pressure got taken off to get it done because we actually have some bass players on our worship team.  I know, however, that the day will come when I'll need this puppy, so I'm trying to pick up the threads of where I left off and get ready for a big push to get it finished.

When I left off, I was ready to give up on the 16F628 because I was out of pins and needed more functionality.  It was easy enough to step up to the 16F877, and I figured I was going to do that when I resumed work on this project.  Something kept holding me back, though.  I guess it was not wanting to monkey around with interrupts.  Also, the prospect of dealing with all those pins seemed daunting somehow.

Anyway, if you've read this far, you're probably just the person I need.  I'm revisiting the idea of using the '628.  I've decided that this chip will work if I go back to my idea of offloading the display processing to 4511 chips to drive each LED digit (I plan to use four).  I was bumping my head on the limitations of key matrix size and digit handling.  I still am, especially with wanting to add functionality to select the MIDI channel AND preselect some patches.  All right, down to cases.  I'm going to use PORTB and pin RA5 for my 4X5 combined foot pedal and function button matrix.  RA5 is selected because it's input-only.  I'm using RA4 for my MIDI output.  This leaves me 6 output pins.  Well, it turns out that I only have to display digits in the range 0-7, so I only need 3 output pins to drive the 4511 digit inputs.  I can force the high-order bit to 0.  That leaves me with a bit of a problem with enabling the proper 4511 chip, and I'm finally down to my question(s).

It looks like I should be able to use a 74LS138 (thanks, Jordan Petkov!) to select the appropriate 4511 because it drives an output pin low depending on a 3-bit input, and the 4511s need the enable pin to be driven low in order to display the digit on the input lines.  Neatly enough, I only need to connect my PIC to two of the 138's inputs because I'm using 4 4511s.  I would think I could just force the high-order input on the 138 low like I'm planning to do with the 4511s.  Hey, cool!  This would implement the functionality I need (except for playing predetermined chords, but I'm saving that in case I ever do a larger version of this circuit), and I even get a pin left over!

Does this sound workable, or have I missed something stupid?
Title: Re: How can I treat bass pedals as a matrix?
Post by: Dave_B on June 29, 2007, 11:18:10 AM
It sounds workable.  Have you ever considered the 74hc595?  That thing is hot stuff for adding outputs to a µC, and there's some documentation on the Web for using them with PICs.  You can string them together so (for example) three '595's will convert three µC pins into twenty-four outputs. 

I'm working on a circuit that uses two '595's to control 20+ LED's and 3 7-segment displays.  The first chip connects to the Anodes, the second chip grounds the cathodes sequentially.  From there, it's the same concept as your input matrix.  With the '595, you can easily end up with more outputs than you need.   :)
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on June 29, 2007, 11:24:58 AM
Quote from: Dave_B on June 29, 2007, 11:18:10 AM
It sounds workable.  Have you ever considered the 74hc595?  That thing is hot stuff for adding outputs to a µC, and there's some documentation on the Web for using them with PICs.  You can string them together so (for example) three '595's will convert three µC pins into twenty-four outputs. 

I'm working on a circuit that uses two '595's to control 20+ LED's and 3 7-segment displays.  The first chip connects to the Anodes, the second chip grounds the cathodes sequentially.  From there, it's the same concept as your input matrix.  With the '595, you can easily end up with more outputs than you need.   :)

Yeah, I did get some suggestions about that chip, and they were VERY seductive.  Especially after R.G. indicated that bit-banging MIDI was sufficient qualification for serial output coding.  I just couldn't do it, though.  I understand parallel outputs and have those working.

Check in with your toy once in a while.  It sounds real interesting!
Title: Re: How can I treat bass pedals as a matrix?
Post by: Dave_B on June 29, 2007, 10:31:10 PM
It's a metronome, so it's barely interesting. ;D  I know, I know, you can buy one of those.  I want one where the LED's are arranged in an arc and flash back and forth like a traditional mechanical metronome.  That works better for me as a drummer, since I can't hear the 'blip' when I'm playing.
Title: Re: How can I treat bass pedals as a matrix?
Post by: David on October 03, 2007, 11:16:47 AM
This project hasn't died, but it's been comatose for an awfully long time...

I haven't done anything but research on it for months.  That and trying to find the time to rewire the switches into a matrix...
...with diodes, in true Jordan Petkov fashion.

I have, however, significantly managed to simplify and add much functionality to the design at the same time.  I am now going to use two PIC16F648As in a master/slave configuration.  The master will handle the inputs, figure out what needs to be played and send out the necessary MIDI data to the selected synth (I'm going to use two, maybe three).  It will also send data to be displayed over its USART to the slave, which will receive the data via its USART and then display it on a 20x4 LCD screen.  More info, more features, way less work.

This will allow me to output to multiple synths, and preprogram some patches for each one that I can select on the fly.

It's a ways off, but not as far as it used to be.