February 27, 2010

Optos and Switching Time

I need the help of the EE people on this. I’ll have a more general interest post about microtonal harmony soon.

I mentioned in an earlier post that I think the optos that I’m using in my solenoid driver circuit are adulterating the PWM signal by acting as a low pass filter. The first indication that there was a problem occurred during testing, when I noticed that the voltage across the solenoid did not vary linearly with the PWM duty cycle. Instead, the voltage crept up slowly for low duty cycles and then shot up rapidly as I approached the mid duty cycle range. This is what one would expect if the PWM signal had its edges smoothed out by a low pass filter. (Of course, if I had a scope, I verify this theory). I managed the problem in software by using only a narrow range of duty cycles, but even then, the non-linear relationship between the voltage over the solenoid the PWM signal has caused a lot of annoyance.

[Update: thanks to peabody for correcting my unit conversion below, but now I'm just more confused]. Over the past few days, I’ve gotten two comments on the topic from people more expert than me; one supported me and one disagreed, saying that the switching time for optos is in the tens of nano-seconds and therefore shouldn’t matter. That may be true for some optos, but I looked up the datasheet for the 4N29 optos that I’ve used, and it looks like the switching time is on the order of 150 to 300 nanoseconds, which in the context of a 1000 hz PWM signal, might make a difference for lower duty cycles. A 1000 hz PWM signal has a period of 1 ms = 1,000,000 nanoseconds. Even at a 10% duty cycle, which has an on-time of 100,000 nanoseconds, smoothing out the first 300 nanoseconds shouldn’t make a difference.

My second question is, if I wanted to get rid of the optos, how would I redesign the circuit? I see no reason that I couldn’t eliminate the opto and connect the PWM chip, which pulses a connection to ground, to the base of a PNP Darlington. What I’d like to do for my next machine is use Darlington arrays, but Darlington arrays seem to come only in the NPN flavor, which means I’d have to invert the signal from the PWM chip from active low to active high, which requires more components. Suggestions?


Comments (7)


February 27th, 2010 at 10:30 am    

I don’t know about the rest, but 1 millisecond is 1000 microseconds or 1,000,000 nanoseconds.


February 28th, 2010 at 11:38 am    

The datasheet didn’t work for me (running chrome on ubuntu linux), so I grabbed the sheet for a 4N29 from Fairchild (http://www.fairchildsemi.com/ds/4N/4N32M.pdf).

On page 3 you see the AC (transient) characteristics, which is where you can see the turn-on and turn-off times for different situations. A quick look at your PWM driver shows that its absolute max output current is 120mA (assuming you’re driving it at maximum, which wouldn’t be sustainable with higher duty cycles). 120mA is only 60% of the input (LED) current used when rating the turn-on time, so you’re probably turning on much slower than what’s listed. That being said, the listed turn-on time is 5uS, and the listed turn-off time if 40uS. So there’s 45uS of time (at best) when the unit isn’t doing what’s supposed to. As your load resistance and LED driving current decrease below the values used in the test, this number will get worse.

Now when you say a 1Khz PWM signal, do you mean that GSCLK is being switched at 1Khz, or do you mean that the PWM period is 1Khz. In the latter definition, an entire PWM cycle (all 12 bits) happens every 1mS, and that means that the smallest pulse will be the 1mS PWM period divided by your PWM resolution. A 12-bit PWM would generate a minimum pulse width of 1mS/(2^12) = ~244nS. Now that is a pulse width that can get really messed up by the switching times described above.

A simple way around the NPN problem is to invert the grayscale value you send for each channel (ie. x = 4096 – x).

A more fun way would be to ditch the PWM driver altogether and run a NPN array (ie ZDT1053TA) straight off the Arduino GPIO. I haven’t checked, but surely the Arduino has some hardware PWM channels. If not, you might want to look using at a PIC microcontroller as a replacement for or augmentation to the Arduino.

Good luck!


February 28th, 2010 at 5:25 pm    

OK, so I geeked out and checked on PWM from the Arduino. It’s got 6 channels of 8-bit PWM with a period of ~500Hz. That means the smallest pulse would be 2ms/256 = 7.8uS. So long as you stick with duty values above, say 8 (62.4uS pulsewidth), then that’ll keep you above the region where pulse distortion becomes a big deal.


February 28th, 2010 at 7:09 pm    

I would run the PWM straight from the Arduino, but I need 8 channels for the bongos. I know the Mega has more, but future instruments will require 96 channels, which I can get by daisy-chaining multiple TLC5940s. I’d rather go with what I know will always cover my needs.

@ Justin, by 1 khz PWM, you’re right that I meant the pulse period, not the GSCLK. You clearly show that the opto would interfere with the minimum pulse width on the TLC5940, but at a 10% duty cycle, you’d think the problem would become insignificant, but I still see the non-linearity I mentioned there. I wonder if it’s simply a function of a fairly high current (around 1 amp) moving through an inductive circuit. I’ve read that inductors resist changes in current, so maybe there’s nothing to be done.

Good idea about inverting the signal to the NPN. I’m a little worried about power dissipation in the chip, as well as what happens on start up. If 96 solenoids were switched on before the TLC chip starts running, I would have a problem. I guess I could have separate switches for the Arduino/TLC and the solenoids.

As soon as my next shipment of electronics arrives, I’ll start testing some alternative circuits instead of just speculating about them. Thanks for you input.


March 7th, 2010 at 5:47 am    

The question is “why are you using optos” ?
The main reason why we use optocouplers os when insulation is required between two parts. In your case, if I follow your schematics, you can perfectly drive the power transistor directly from a TTL PWM output. Just look to the drive current needed by the transistor base.
You have to consider that the frequency response (rise and fall times) of the different optos you can find varies widely from a model to another.
Entry range models like 4N26, 4N27, CNY33, etc… are typically “slow”. They will transform a 10kHz square signal into something more or less trapezoidal.
A model like 6N136 or even better 6N137 that I use on all MIDI interface I make) reaches the MHz. If you absolutely need (or want) to use optos and keep the PWM signal as it is generated by the control module, you can use these ones (but they are really more expensive)


March 7th, 2010 at 9:04 am    

The reasons why I originally used optos had more to do with my own ignorance than anything, and you’re right that I could drive the Darlington directly from the PWM output. That’s what I plan to do with my next machine. I think that you correctly diagnosed the proportionality problem as the result of the saturation effect withing the solenoid, which means that the optos in my existing circuits are superfluous but not harmful.


April 19th, 2010 at 7:30 pm    

I don’t know about the rest, but 1 millisecond is 1000 microseconds or 1,000,000 nanoseconds.

Leave a reply