Hi all. Obligatory: Long-time lurker, this is my first post here! I'm excited to join this community!
Jump down to the bolded section to get right to the technical challenge at hand. I've given some extensive background on the project that's not particularly necessary to the specific technical challenge.
Anyway, I'm converting a reed organ (pump organ) to be MIDI-controlled with 88 solenoids, one under every key.
Solenoids are special because they need a lot of power to pull in: in my case, my solenoids draw 1.3A @ 12V each. However, once they are down, they don't need nearly as much power to stay in. They stay down with just 4V (therefore just over 400mA of current). Continuously feeding them 12V also results in a large amount of heating; after just a minute of being held in they get intolerably hot.
My solution? PWM them. Of course, it would be fairly impractical to generate and control 88 PWM channels, so I'm going to PWM them in groups. I've designed and ordered 15x (!!!)(I can't make any changes now) of a 16-solenoid driver PCB, and each half of this driver board (groups of 8 solenoid driver circuits) has another MOSFET controlling the overall power, like so:
Of course, this schematic is only showing a 4-channel setup. These are actually in groups of 8.
88 keys/8 per group = 11 groups of PWM control = 5 and a half driver boards.
How does this setup work? I'm using 3 Arduino Megas to control the individual notes (using only 2 would work in terms of pins, but I'm using 3 for wiring purposes).They are all reading serial data off the same data line and triggering notes accordingly - currently all the PWM MOSFET gates are just pulled high, effectively bypassing them. This is working beautifully, ignoring the absurd power consumption and solenoid heating.
Now that I have my explanation of my setup complete, here's where stuff gets more difficult. My plan is to PWM the "PWM control MOSFETS" at around 40% duty cycle when no solenoids are being triggered. When a solenoid needs to go down, the duty cycle goes to 100% for a split second before going back to 40% to hold it in. I've tried this with an individual solenoid, and it works very well - sort of. At the default Mega 2560 PWM frequency of 490Hz, the solenoid is very audible. Raising the frequency to 31kHz by setting the timer prescaler to 1 works very well for eliminating this hum.
If I'm messing with timers, then I've decided I'm probably best off using another standalone Mega for generating the PWM, especially as my MIDI-decoding code works perfectly. The key-triggering Megas would simply have 11 output lines between them running into my PWM-generating Mega. Whenever a MIDI note came in, the key-triggering Arduino would make the line high that corresponded to the driver board that MIDI note's solenoid was attached to. The PWM-generating Arduino would be constantly generating a 40% duty cycle 31kHz PWM signal across all the power control MOSFET gates, and when one of its inputs was high, it would change to 100% duty cycle for a split-second on the line connected to the correct solenoid group. This sounds complicated in my explanation but it really isn't.
So after this long-winded explanation, this is the situation I am left with: I need to generate a >20kHz PWM signal @ ~40% duty cycle across 11 Mega pins. The Mega needs to listen to 11 pins, and whenever one goes high, it needs to change to 100% duty cycle on the corresponding output pin.
Am I better off bit-banging this instead of using analogWrite() and non-default timer frequencies? Can I achieve >20kHz PWM if I bit-bang it? Will analogWrite() take too much time for my application? I don't have a scope, so I really can't test these myself.
Or do I have completely the wrong approach? What if I used 11 separate attiny 45 or similar chips? That would certainly make the coding easier...
Although probably not really necessary, phase-shifting the PWM across the 11 pins would be much nicer on my power supplies... this would make bit-banging it more complicated.
Any help/ideas appreciated. Apologies for the large amount of words.