Ebay Classic organs

Collapse

Announcement

Collapse
No announcement yet.

Help programming an arduino to work with MOS2 Allen circuits

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help programming an arduino to work with MOS2 Allen circuits

    I have been doing a lot of self study trying to understand the Arduino programming language, so that I can rig up my Allen 225-HTC to work with Hauptwerk. I think I understand the basics, and feel confident I can program a sketch to work as a midi controller. However I am nervous about running the sketch with the Allen keyers working at the same time. Specifically, I’m worried if I switch a pin to Output, then low to activate a column when the Allen column isn’t low, that I will damage that pin. In theory, if the Allen column is low, then I shouldn’t need to put a pin in output, then low. However, the Allen circuit is running at 2.5 v, so an input pin on my arduino Mega wouldn’t sense it. I would have to put it in input pull-up, but then I’m worried about the current load on the Allen. Is my thinking right, or am I worrying about nothing? The Allen seems to be putting out about 20 milli amps of current, so in theory the Arduino should be able to handle it, even in output mode, but I’m worried my logic isn’t right and I damage the board.

    The other thing I’m having trouble with is figuring out how to synchronize the Arduino sketch with the Allen circuits. From reading John Kinkennon’s post about his Allen conversion, I’m guessing the Allen has 11 columns shared by all the manuals and pedal, then starting when the Allen is switched on, each column is activated starting with the right hand most one, moving left, for 57 microseconds each, then pausing for 627 microseconds between reading again. I know how to try to match the scans with benchmarking and delays, but I’m not sure if there is an initialization time before the scans start that I should be factoring in? As well, as above, when the Allen column is low, what pin settings should I use to read the rows?

    I suppose I could program a sketch to measure the timing of the second part, but I’d still like to be sure what pins are safe to use before I do that. Usually I would just hook everything up, test it, then troubleshoot, however I don’t want to risk damaging my hardware. Any advice from those who have been here before? Thanks!

  • #2
    For an Allen organ with the original matrix still operating, all Arduino pins will be inputs. The operation of the matrix columns are monitored just like the rows and it's a matter of sensing when is the right time to read the value of the rows. I'm attaching my Teensiduino code which is virtually identical to what would run on an Arduino. I have not tried this code with a MOS-2 organ and it is almost certain that the matrix size will be different, perhaps 22x12 instead of 16x16. Also the speed is likely to be a little different but you will find the timing and delay offsets that worked on the ADC. Kudos for diving into this tricky programming!

    The zip file: MIDI_Matrix_16x16.zip

    John Kinkennon
    Attached Files
    http://www.kinkennon.com

    Comment


    • #3
      Thanks John, that’s very helpful! Much appreciated. It gives me the confidence to go ahead with testing. First I’m going to run a test sketch to figure out which columns go low when, and for how long. I just finished the wiring the keyboards and pedals, so I will run the sketch with them attached. Thanks for posting your code, it is very useful. I plan to use a very similar delay once I find out how exactly this matrix works. Thanks again!

      Comment


      • #4
        Hi John, I finally got everything wired for the Arduino, and plugged all the leads in. I found the Arduino works very well, though I haven't been able to get the Midi to work yet. Running a test code, it looks like each column only runs low for a few microseconds (10 at most) every 300 microseconds or so. Oddly, if you hold down a key wired to that column, then you get a second low just before the low, about 60 microseconds before the low I mentioned. I got these numbers by running a simple program that measures the state of the pin every 10 microseconds. I think that means that the circuit only drops the current for about 10 microseconds about 3 times per millisecond. What I plan to do is have a loop that only writes to that column/row if the column is low, and then delay 100 microseconds. Hopefully, over the course of 30 or so loops, it should cover every column. I found as I'm sure you did, that if I run the program too fast, there are output errors in the serial (all of this was at 9600 baud). I'll finish programming and try the Midi program today, and let you know how I did. Thanks again for your help!

        I forgot to mention, another interesting tidbit is that when I plugged the leads from the switches into the Arduino, I found that the keys of the Allen stopped working! I unplugged the leads again, and the Allen keyers worked perfectly again. My hypothesis is that the impedance of the Allen circuits must be higher than the Arduino, so all the current is getting drained towards the Arduino. I plan to add some 1/4 watt resistors to the Arduino leads, testing different resistances until the Allen circuits start working again. Any advice on other ways to do this would be appreciated!

        Comment


        • #5
          One very important point that I had forgotten. Be sure that every pin connecting to the key matrix is truly at a high impedance and that the Arduino or Teensy is a 5v model. I used the Teensy 3.5 as anything newer is 3.3v. Additionally I had assigned pin 13 to a matrix column, but pin 13 also connects to an LED on the Teensy which caused the key matrix to hang up. It turned out to be easier to remove the LED from the board than to rework traces on my PCB.

          The timing on an ADC is described in this paragraph from my other thread about the ADC-8000:

          Here is what I have observed without the benefit of any Allen documentation. The same 16 columns appear on each manual and presumably on the pedals. They are normally in a high state at a bit less than 5v. More about 5v to 3.3v later. Column 1 goes low for about 47 to 48 usec. At that point it goes high and column 2 goes low. These column signals continue sequentially through column 16 which takes 760 usec total. This is followed by a delay of 760 usec before the matrix is read again. So the matrix is read every 1520 usec which is 1.5 ms. I typically read a matrix 3 to 5 times that fast so long as the cable capacitance (bit settling time) allows.

          Probably other Allen matrix sizes ran at slightly different speeds. I had the benefit of an excellent old Tektronix scope that I found for 100 or 200 dollars, don't recall which. Sure helps with figuring out the timing!
          http://www.kinkennon.com

          Comment


          • #6
            Thanks! I uploaded a sketch where all the relevant pins were set to Input, yet still the Allen keyers didn't work. Also, both my Arduinos are 5V models, the Mega and the Nano Every (only using the Mega for now).

            I've been hard at work this morning trying to figure out the output from the matrix. What I found is that there is a fair bit of noise in the keys when I set the pins to Input. However, setting them to Input_Pullup solved the noise problem. With Input_Pullup enabled, the columns go low once in a while, whether the key is depressed or not, whereas the Rows go low once in a while, but only if the key is pressed. The exact timing is difficult to figure out, because I don't know how long the read and serial print steps take. Still, I'm pretty sure that that they go low for less than 47 to 48 microseconds, it looks like these columns go low on the order of 1-5 microseconds. I think this because even if I don't implement any delay, there is only ever one 0 separated by a long stream of 1's being read by the pin.

            Having no way to figure out the exact timing, what I did was set the pin to Input_Pullup, then only read the rows if the column is low. Then I implemented two variables, one which monitors what the last key state was, and one that debounces the "off" note. I found that this worked! (at least for one key). Now to try and get the whole keyboard working. Thanks for your help! Any other ideas how to get the two matrices working together would be welcome.

            Comment


            • #7
              Well, I spent the better part of one day trying to get it working, and I'm happy to report I am very close! After modifying and running my test sketch, I found that the columns on the Allen appear to have 4 low pulses per column, that go sequentially through the columns, with the pulses on the individual columns about 10 usecs apart, and the columns much longer apart (at least 60 uSecs, it's hard to tell without a scope). The columns going low register as 4 "0"'s on the Arduino pins. The only problem is that sometimes I only get 2 or 3 "0"'s instead of the usual 4 (but most of the time it is 4). If the key is depressed when the column goes low, then there is a concomitant "0" in the row with the "0" on the column. I programmed the Arduino so that if the column pin reads 0, it reads the row pins, and if they are both "0", then it registers the note. This worked very well, except I believe I was somehow getting induction in adjacent pins, so that sometimes I would get "0"'s in adjacent pins at the same time (so two notes would sound at the same time when the key was depressed). I solved this by implementing a filter, that if two adjacent columns were read as "0" at the same time, it set the one that was likely getting induced to "1". I also eliminated all debouncing from the code! The reason for this is with the program implemented this way, I found the latency from key press to registering the note was too long. Removing all debouncing solved the problem. I didn't program any delays, and serial is set to Midi speed (31250), so I believe that the debouncing is handled by the fact that there is quite a long time between the columns going low, which is when the bouncing would happen. After a note is detected, I have a line of code and a data byte that prevents the note from being retriggered until an "off" note is detected, so in general that prevents retriggering. There are a handful of notes, however, that constantly retrigger (on/off/on/off... etc.) as long as the key is held down, but I believe this is a problem with the key contact (I went through the code multiple times looking if I made any mistakes!). I'm going to deoxit all of the key contacts to see if that fixes the problem. Once I get all the manuals and pedals working I will post the code to the Arduino site, and post a link here. A lot of work, but it sure sounds good playing this organ with Hauptwerk! I'm sure there is a better way to program it, (the Allen keyers have no problem with the dirty contacts!), but it is the only way I could get working for now. My knowledge of C is very rudimentary, and I still have trouble wrapping my head around timing/benchmarking circuits and for() loops, so as I grow in knowledge and experience, I'm sure the program will improve! I'm going to look into getting an oscilloscope, so I can time the circuit better, and I'm sure that will help to make the code more reliable. I have an uncle that might be able to help me, so I will email him. The other project is figuring out how to measure the impedance in both circuits so I can calculate what value of resistors to use so I can use both keyers at once. I'll post back with my progress.

              Comment


              • #8
                You are doing a lot of things right to get as far as you have! You might try putting 10k pullup resistors on the rows as they will help the rows respond faster and will not interfere with the Allen keying. You could try connecting just one column to the Allen at a time and see if there is a point at which the Allen keying stops working. I'm just throwing ideas out sort of at random here. It's also possible that you need to run through the columns once, process the results, and then wait for perhaps 200 usec (more or less) before scanning the columns again. Good luck!
                http://www.kinkennon.com

                Comment


                • #9
                  Thanks for your input John! I have been working on the code, and I have been having quite a bit of trouble. As I said, I managed to get it working fairly well, except a handful of keys have the problem that they retrigger if you hold the note down. I have tried all manner of different ways of coding it, but so far nothing has solved those retriggered notes. I agree with you that it makes sense to connect resistors between the circuit and the Arduino, but I feel like I still should be able to read the keys without them. I posted an example code on the Arduino site, maybe you can take a look as well? I have tried introducing a delay, but it doesn't seem to help.

                  https://forum.arduino.cc/index.php?topic=719741.new#new

                  On the other hand, perhaps your idea of connecting the resistors will help with the coding problems as well. My thought is I can desolder some of the leads, and measure the resistance from the Allen row to both the Allen column, and the Arduino column, thinking that the difference in resistance is the resistance value I have to connect between the Arduino and the Allen keyer. I will have to order the resistors, as I don't have enough for the whole project currently.

                  Thanks for any other help you can provide!

                  Comment


                  • tbeck
                    tbeck commented
                    Editing a comment
                    Are you using the Arduino debounce library?

                  • Larason2
                    Larason2 commented
                    Editing a comment
                    Thanks! I tried implementing a debounce code, but it didn't help with this particular problem. It slowed down the latency, without preventing infinite loops of On/Off. However, I didn't use the debounce library, I tried implementing debounce code similar to ones I found online. How would you implement the debounce library?

                    I tried implementing the debounce here: but it also didn't work, I wasn't getting any keypresses.

                    https://www.arduino.cc/en/Tutorial/B...mples/Debounce

                • #10
                  Well, I’ve been putting some work in to this project, and I’m sorry to report I’m no further along! After running into troubles getting the Arduino code to work, I thought I would try to add the planned resistors between the Allen circuits and the Arduino, so I could use both at the same time. I measured the impedance from the Allen row to the Allen Column, which was ~60k ohms, and the resistance from the Allen row to the Arduino column, and I got ~20k Ohms (interesting though, is that the polarity was reversed, which may have something to do with my problem...) So, I tried connecting a 47 k Ohm resistor to the columns, but oddly, the first key of 6 would work, but not the other 5. I went up resistor values until I got to 330k, but the behaviour remained. I also added 47k resistors to all the rows going to the Arduino, but the behaviour was the same! So, I’m still scratching my head as to what to do. I don’t know enough about the effects of polarity to know how to proceed in this case. I feel the behaviour of the Allen circuit is very bizarre, and I wonder if there are circuits involved to prevent reverse engineering. Any tips on other ways to try to get it to work would be appreciated!

                  if I can’t get it to work this way, my plan is to chromatically sample the Allen stops, then carefully label and desolder all of the Allen connections to the keyboards and pedals. The plan would be to make myself a personal Hauptwerk organ with the sampled sounds at some point in the future so I would still have them, and if a future owner wants the Allen sounds working again, I could just solder all the wires back as they were. That is plan B if I can’t get it to work the other way!

                  Comment


                  • #11
                    You know that Harrison Labs has a keyboard encoder for single computer MOS2 instruments that provides MIDI out without destroying the internal workings, right? I don't know exactly where they pick off the keyboard data, but I'm fairly sure they're not looking directly at the output of the scan matrix. The reasons I say this are because their converter doesn't work with MOS2 multi-computer models and it also responds to the settings of the transposer knob. If you have a multi-computer MOS2 model, the Zuma MOS2 Keyboard Encoder is still available.
                    -Admin

                    Allen 965
                    Zuma Group Midi Keyboard Encoder
                    Zuma Group DM Midi Stop Controller
                    Hauptwerk 4.2

                    Comment


                    • #12
                      Yes, I saw the MOS2 encoder for one computer from Harrison labs, however when I first looked at it, it seemed a bit expensive. On second thought though, maybe it is worth saving up for! Definitely a lot less headaches. I have dealt with Harrison Labs in the past, and they are good to work with. My system definitely only has one computer. I'll look into the possibility!

                      Comment


                      • Admin
                        Admin commented
                        Editing a comment
                        When it comes to DIY projects, the expense of a purchased solution is relative to how you value your time. The older I get, the less time I have and the more I value it. I've programmed computers for nearly 50 years, so I prefer playing to tinkering when it comes to organs nowadays.

                      • Larason2
                        Larason2 commented
                        Editing a comment
                        That’s a fair point. My wife does always say I spend more time tinkering than I do playing! I also do kind of feel like I’ve spent enough time re-inventing the wheel. Maybe I should order the boards and devote my time to practicing!

                    • #13
                      If you want to work with my Teensy code that 8x8 matrix application continues to function flawlessly in the ADC-8000. I would be happy to modify it for 11x6 matrix operation. I will soon have my current living room Rodgers 32B shipped out and will bring an Allen MOS-1 era console in from the cold garage. That should be within a week or two and I will be able to test the version you need and I'll send you an encoder with programmed Teensy 3.5. If it works you can reimburse just the nominal cost of the Teensy. That would be a rock solid encoder and connects with a few wires to each manual.

                      If you decided to strip out the Allen hardware then the same encoder could work with just a programming change. Send me an email response if you prefer.
                      http://www.kinkennon.com

                      Comment


                      • #14
                        Thanks John! Unfortunately I already ordered the Harrison labs solution and it’s on its way. However, as you know it doesn’t interface with the stop action. I’ll send you an email to see if you’d be able to put together a board to help take care of that end of things. Cheers!

                        Comment

                        Working...
                        X