Correct on both counts. I suggest you use a PWM frequency of 3906.25Hz, which is a value you can get from the PWM pins associated with timer 1 and timer 2.

This gives a period of 256 ns, and since there are two clock edges per period, this would require an opto-isolator with at most 128 ns on/off time (and, realistically, somewhat less than that) Correct?

EDIT: Holy cow! The cheapest "high-speed" optical isolator on Mouser is nearly $8, although it does have a 50-100 ns on/off time.

No, the period is 256us. So an ordinary opto isolator that takes perhaps 5us to switch off in the circuit I gave will suffice.

joshuabardwell

When I first started this project, one of the people who was kind enough to advise me made a big deal out of galvanic isolation. I didn't really understand, given that I'm not working with high-voltage at all. I thought of it primarily as a safety issue. I have a much better appreciation now of how galvanic isolation simplifies the interface between two circuits.

Regarding the optoisolator, can anyone comment on whether this one would be a good choice: http://www.mouser.com/ds/2/427/k817p-240395.pdf

I think it is fine, and I hate to be overly critical, but I'm a little tired of ordering things from Mouser only to find I overlooked some specification that renders them unusable in this project. I'm acquiring quite the cache of ICs for use in future projects, though! One specification I don't fully understand is current transfer ratio.

That (or almost any other phototransistor-output opto isolator) will be fine in the circuit I suggested.

If the current transfer ratio is C, this means that when you pass a current I through the emitting side and apply whatever voltage is specified between the collector and emitter of the receiving side, you will get a collector current of C * I. Current transfer ratio is typically specified as a percentage. For the circuit I suggested, the CTR is not critical unless you are using low values of R. What values of R will you be using?

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

joshuabardwell

If the current transfer ratio is C, this means that when you pass a current I through the emitting side and apply whatever voltage is specified between the collector and emitter of the receiving side, you will get a collector current of C * I. Current transfer ratio is typically specified as a percentage. For the circuit I suggested, the CTR is not critical unless you are using low values of R. What values of R will you be using?

Using this calculator (http://sim.okawa-denshi.jp/en/CRtool.php), I played around with some target cut-off frequencies. With a cut-off frequency of exactly 30 Hz, the Bode diagram showed about 6 dB of attenuation at 30 Hz. At Fc=100 Hz, there was almost no attenuation at all shown at 30 Hz, and somewhere in the neighborhood of 30 dB of attenuation at 3 kHz (the PWM frequency you recommended). That seems like a pretty good outcome.

The potentiometer that I'm replacing is 22k, so each of the resistors will be 11k. The corresponding capacitor value to 11k, for Fc=100 Hz, is 1.4 uF. Using the closest standard capacitor value of 1.5 uF, we get Fc = 96 Hz. Or should I have been using 22k as the resistor value instead of 11k? The capacitor is only short-circuiting one of the resistors, so I think 11k is the correct value.

EDIT: The calculators on that site seem to disagree. If I use the calculator that takes a cutoff frequency as a parameter and work backwards, I get a cap value of 1.5 uF. But if I put 11 kOhm and 1.5 uF into the calculator that works forwards to derive a cutoff frequency, I get 9 Hz, not 99 Hz. I'm going back to the formula that was given earlier to calculate by hand.

joshuabardwell

Based on a cutoff frequency of 100 Hz, resistor value of 11 kOhm, capacitor value of 0.15 uF, I then go to this calculator ( http://sim.okawa-denshi.jp/en/PWMtool.php ) which is PWM-specific. It tells me that I will have a ripple of 0.25 volts on a 0-5v PWM output. 5v / 0.25v = 20. Does this mean that I will effectively only have 20 steps of resolution? It looks like I can reduce the ripple by pushing the PWM frequency up, so if so, that is not an insurmountable problem, as the Arduino is capable of PWM frequencies an order of magnitude higher than 3 kHz.

Based on a cutoff frequency of 100 Hz, resistor value of 11 kOhm, capacitor value of 0.15 uF, I then go to this calculator ( http://sim.okawa-denshi.jp/en/PWMtool.php ) which is PWM-specific. It tells me that I will have a ripple of 0.25 volts on a 0-5v PWM output. 5v / 0.25v = 20. Does this mean that I will effectively only have 20 steps of resolution?

Not quite. You will have 255 steps, but the output voltage will have 0.25V of ripple, which may or may not matter.

You can reduce the ripple by using a 2nd (or higher) order filter instead of a first-order filter. Can the welder Vcc supply intended for the pot drive a lower resistance than 22K? If so, then you could (for example) make R=3.3K and C=4.7uF, and then add an additional filter stage comprising a 6.8K series resistor and 2.2uF capacitor to ground.

Another option is to use an op amp powered fro the welder Vcc, to implement an active 2nd or 3rd order filter.

Yet another option (but more expensive) is to use an ADUM6401 digital isolator chip feeding a DAC.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

joshuabardwell

Not quite. You will have 255 steps, but the output voltage will have 0.25V of ripple, which may or may not matter.

My testing shows that the welder maps voltage on the wiper pin linearly to output. 0.25v / 5v = 5%. This should then mean that the welder's output would vary when welding by as much as +/-2.5% of its full-range output. Full-range output is 160 amps, so this would be a swing of +/-4 amps, which would be too much.

Quote

You can reduce the ripple by using a 2nd (or higher) order filter instead of a first-order filter. Can the welder Vcc supply intended for the pot drive a lower resistance than 22K?

I'm not 100% sure, but I think the answer to this question is no. I have a handful of 10k pots laying around, and I once tried to substitute one of them for some reason that I don't remember. When I did, the welder did not display the correct output range. I don't have detailed notes, unfortunately, and I will refrain from attempting to recollect (inaccurately).

Quote

Another option is to use an op amp powered fro the welder Vcc, to implement an active 2nd or 3rd order filter.Yet another option (but more expensive) is to use an ADUM6401 digital isolator chip feeding a DAC.

What about increasing the PWM frequency from 3 kHz to 30 kHz, which reduces ripple by a factor of ten?

As usual, thanks much for your continued engagement on this topic. It's incredibly educational for me.

What about increasing the PWM frequency from 3 kHz to 30 kHz, which reduces ripple by a factor of ten?

That's OK in theory, but in practice it's difficult to get a 30kHz signal through opto isolators accurately without using a more complicated circuit. If you have an oscilloscope, you could try it. Adding a resistor of about 100K between base and emitter of the opto isolator makes it faster, but also less sensitive. You can get high-speed opto couplers with built-in amplifiers such as http://uk.mouser.com/ProductDetail/Avago-Technologies/ACPL-M71U-000E/?qs=sGAEpiMZZMtd3yBnp8bAgM1RuSnuM3xJN4d2%2fBXxla8%3d. A single one would do, however they need a few milliamps of power - you would need to check whether the welder Vcc can supply that. Does the 22K pot still function correctly if you connect a resistor of about 2.2K in parallel with the pot, or does that cause the voltage to drop?.

You might be able to find a compromise PWM frequency such as 10kHz which gives a sufficiently low ripple but for which the opto isolator switching times are good enough.

Otherwise, use a rail-to-rail op amp such as MCP6281 to implement a 2nd order low pass filter. Or an ADUM6401 and SPI DAC.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

joshuabardwell

Right, right, right. I forgot that the opto-isolator has to be able to handle the PWM frequency. Okay. Well, I think I have plenty to meditate on, and thank you ever so much for your assistance. It really has been educational.

joshuabardwell

Today was the first time that I actually welded with The Box, and I have to come back here to say that those who said that PWM output must be filtered (Grumpy_Mike, for example) were totally right (they probably knew this) and I was wrong when I thought that the process appeared to be working fine.

The welder's output control circuit DOES interpret the PWM signal flawlessly. However, when welding, there is a "singing" tone that is not usually present, that could be nothing other than the PWM signal imposing itself on other parts of the welder's circuitry. You can hear it in this video:

http://youtu.be/1fjmwlb-vfU

Just to be a little more certain, I compared it to a 4 kHz test tone (my PWM frequency should be around that, if my setting of the clock divisor is as I expect) and they are dead-on.

I don't know whether the PWM signal could be harmful to the welder's circuitry, but I'm certainly not going to push my luck and find out. (I only welded for a minute or two to make the demo video.) Also, that singing is darned annoying. I have intended to build the "digital potentiometer" circuit described most graciously by dc42 ever since he described it to me, because really that is the proper way to do this. This reinforces that the filtering component of that circuit is absolutely mandatory.

joshuabardwell

I suggest two opto isolators (or one dual opto isolator) configured as in the attached schematic. Choose R to be about half the value of the recommended potentiometer, and the product R * C to be about 0.1 to 0.2 seconds.

I have built the "attached schematic" (re-attached here, for reference), and my results are not as expected. To simplify troubleshooting, I am feeding the circuit with simple HIGH and LOW signals, vs. PWM. Here are my results

I have double-checked the wiring and I believe it's correct, although I plan to sleep on it and try again tomorrow with fresh eyes. I have also studied the schematic to try to figure out where I might have gone wrong, and I realize that there are still aspects of it that I don't understand. Specifically, when Dout goes HIGH and the "top" opto-isolator turns off, how is there any connection at all between Vcc and the wiper? This seems consistent with my HIGH circumstance, where pin 5 is open to the wiper and ground. Likewise with Dout LOW, it seems like there should be an open circuit between wiper (pin 4) and Gnd (pin 3), but there isn't.

I don't think I understand how this circuit emulates a potentiometer after all.

The circuit doesn't emulate a potentiometer, it emulates a switch that connects the output either to Vcc or to ground through a resistor of value R. In conjunction with the smoothing capacitor C, when driven by PWM this provides a voltage variable between Vcc and ground, which is what a potentiometer would do.

To test the circuit, apply about 5V (or even 9V from a battery) between the output Vcc and output ground, and use a multimeter to measure the output voltage as you vary the PWM.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.