I'm working on a MIDI controlled drum set player. I have an arduino reading midi data on one channel from a sequencer to trigger short pulses on the 6 pwm pins. Each pwm pin drives a different solenoid to activate a drumstick on each drum of a drum set.

The one pin (or midi note) that behaves differently is G#1 (expressed through pwm10). This note controls a solenoid that (when charged) lifts the hi-hat to the open position. A G#1 note with a volume > 1 lifts the hi-hat. It stays lifted (charged) until a G#1 with a volume of 1 is played. That closes the hi-hat.

My problem (and I think it's a code problem) is that once the pwm10 gets charged (by a G#1 w/Volume of over 1), none of the other notes (for the 5 other PWM pins) are responded to until the pwm10 turns off (by a G#1 w/Volume equal to 1).

I'm rather new to programming, so any insight into what might be causing my problem would be greatly appreciated.

unsigned long now = millis(); // Get current time if(pwmStart3 > 0 && now - pwmStart3 >= onTime3) // Check how long the pin has been firing { analogWrite(3, 0); // Turn the PWM off if it has been long enough - onTime }

if(pwmStart5 > 0 && now - pwmStart5 >= onTime5) // Check how long the pin has been firing { analogWrite(5, 0); // Turn the PWM off if it has been long enough - onTime }

if(pwmStart6 > 0 && now - pwmStart6 >= onTime6) // Check how long the pin has been firing { analogWrite(6, 0); // Turn the PWM off if it has been long enough - onTime }

if(pwmStart9 > 0 && now - pwmStart9 >= onTime9) // Check how long the pin has been firing { analogWrite(9, 0); // Turn the PWM off if it has been long enough - onTime }

if(pwmStart11 > 0 && now - pwmStart11 >= onTime11) // Check how long the pin has been firing { analogWrite(11, 0); // Turn the PWM off if it has been long enough - onTime }

Tonight, I will simply disconnect the wires to the hi-hat lifter solenoid. If everything starts performing normally, then I will know (maybe*) my solenoid power source is too weak. (I think it's 24v, 10 amp.) I will then first try to fix with johnwasser's power-saving tip.

A detail I should have mentioned on the hardware side is that the PMWs are controlling n-channel enhancing mosfets - which, in turn, are releasing current from the larger power supply to the solenoids. (sorry about the omission, I was pretty sure it was just a code issue).

My first question about johnwasser's tip that includes a 500ms (or less) delay is:Won't that delay mean I'll be missing data that comes in during that delay? For example, if the MIDI data prescribes for a bass drum hit on the same beat as the hi-hat is to be lifted, won't I possibly miss the bass drum hit coming in right after (during the delay)?

*If I'm understanding it correctly, WilliamK's suggestion addresses a problem that had not occurred to me. Can my arduino have enough juice to function but not enough to be firing all 6 pmw's at once? I have been afraid of over-supplying the arduino. Could my larger power source (solenoid driver) be adequate while my arduino needs more board power?? What's a max rating for the board power supply?

With the mosfets and massive power supply you should not be having a problem with power.

The half-second initial delay is just to be certain that the HiHat lifter always lifts.. that way you can tune the holding current first. I hope that a lift time of a few milliseconds will be enough. With the delay your input stream will not be processed for that time. If the lift time is long enough that there is a noticeable lag you can always use the same sort of pulse-timing logic you use on the other pins to time the reduction to hold current.

In case 0 of your switch statement, did you intend to drop through into case 1? It's unusual not to have a 'break' at the end of each case so if you intend to drop through you should add a comment.

if(pwmStart3 > 0 && now - pwmStart3 >= onTime3) // Check how long the pin has been firing { analogWrite(3, 0); // Turn the PWM off if it has been long enough - onTime pwmStart3 = 0; // ADD THIS or the analogWrite will happen every time through the loop after the timer expires. }

Those are the only things I see so far. I don't think either would cause the symptom you describe.

The troubleshooting revealed that the problem lies with power. The 24v/10A Mean Well power source isn't cutting it for multiple solenoids firing at the same time.

( I went ahead and implemented johnwasser's 2 phase solution for cutting back on longterm power drain from the hi-hat lifter. - As well a the suggested code clean-ups)

One or more of these must be happening:1. the solenoids are taking way more current(?) than I thought to do their job2. the solenoid power source isn't doing what it's rated to do3. my circuit is highly inefficient4. the board doesn't have enough current to have more than 2 pins PMWing 100% at the same time (could that even be it?)

The lifter solenoid Ledex 129415-026 looks like it can run off 24 volts if you don't keep it on for more than about 40 seconds and let it rest a couple of minutes between lifts. Looks like at 28V it draws about 2.75 Amps so at 24 volts it will be lower (maybe 2.5?)

Have you thought of using a spring to lift the HiHat and a solenoid to pull it down? That would reduce the time that solenoid was activated.

I have recently been working on the permanent build for this project. I think this might have been a good project to etch a pcb for.

I've been mounting 2 atmega328's, an array of 12 separate power mosfets, and all the support components to perfboard. That is a ridiculous amount of soldering and wires to fit in. Maybe it's just the perspective of this being my first project.

My RadioShack soldering-helper magnifying-glass station has already broken. I'm seeing the wisdom of investing in a much nicer apparatus for soldering - hopefully one with very bright lighting.