I2C PWM Controller... will the TLC5940 work?

I am looking to have 5 (or 10) independent PWM outputs. It would be nice if each could be assigned a specific frequency (4Hz to 200Hz) and have Duty cycles ranging from 0-100% at a resolution of no more then 4%.

Will the TLC5940 work? If not, does someone make one with I2C that will work? It is for driving power transitors that will be used for solenoids and motors.


You can't change the frequency of the individual channels with a TLC5940 they all go at the rate of the clock you feed into it. This clock is divided by 1024 to give the time period of the final signal. Anyway why do you want to change the frequency is is just the duty cycle that defines the power in the load?

All the other PWM chips I have seen are either for just 4 channels or are meant for switched mode power supplies.

Well it is ideal to allow the user to control the frequency. It may be ideal to allow the user to control the PWM on a motor at 100Hz that is used as a pump. For the solenoids, it varies. Faster is better, for quick control, however some solenoids may have to heavy of a needle for fast control (high pressure gas), so it is ideal to keep them around 10Hz.

I guess I am looking for flexability.


You may be able to do this by using a large CPLD or small FPGA (each PWM would require a number of gates to store the value, and the frequency dividers could double that). Of course this is now a completely different part you have to program.

Maybe you could hang a flock of ATtiny13's off an I2C bus. They've got two independent timers each. Just a thought.

Might also be possible to do this by updating some 74HC595's really fast, you'd have to update the array a maximum 50KHz to get 8 bit resolution at 200Hz, but that's not impossible.

Are you mixing up frequency with duty cycle? I can't see why the frequency of PWM in a solenoid matters. To control the power you just control the duty cycle.

Am I missing something?

I could see a situation where you might have a valve that wants to be either fully on or fully off, and the solenoid mechanism isn't designed to hold an intermediate position. In that case, a high frequency just means the valve sit there and buzzes, slamming the needle into the valve seat hundreds of times per second, increasing wear. With a lower frequency, you just have the valve turning fully on and off with varying duration, resulting in more of a metered pulse effect than a continuously varying flow. If you had a ball valve with a servo or rotary solenoid, it might make more sense to use a high PWM frequency and go for maintaining an intermediate value.

Of course I don't actually know, I'm just winging it here.

Actually you are pretty close. Higher frequency is always better, however, the high pressure fluids or gases require heavier valves and you get buzzes where the valve cannot accelerate fast enough.

Maybe the solution would be to have two I2C PWM controllers (3 ports each) that have their clock driven by Arduino using Timer1 and Timer2, respectively. The user programs Timer1 and Timer2 events to equate to two different frequencies that best fits his/her application by kind of putting some one one, and some on the other. Then if the user needs a high frequency output for motor controller, then you use one of the standard PWM outputs with a frequency doubler.

I really only need 5 outputs at any one time, but having different kind of configurable frequencies would be nice.

Where can I find one of those I2C PWM controllers?


I agree you can always go too fast or too slow with anything, if your solenoid buzzes then make it faster still. There will be a point where it no longer vibrates. The acceleration is from the rate of change of duty cycle.

Anyway a 4 channel PWM generator is the M66240, it has parallel inputs so to make it I2C you will have to add an I2C expander chip like the PCF8574.


Now for the hard part of figuring all of this out. I just programmed by first arduino from scratch. doing micro controller stuff is new even though i learned about it in college way back when. it is indeed fun. i am just glad my latest project is actually working to keep up the motivation!