I have here:
- atmega328p running at 3.3V/8 MHz internal oscillator
- hardware pwm out at 16 bits / 122 Hz (no prescaler)
- optocoupler PS2501-1
- mosfet driver ir4427
- mosfet irfz44n
This is a construction I am fairly used to, except from the optocoupler. So normally I have the output of the pwm pin go directly into the mosfet driver (which runs at 12V, way enough to drive the mosfet's gate) and the output of the mosfet driver with a real small resistor to the gate of the mosfet. Works like a charm.
Now I wanted to add an optocoupler, as the device connected to the mosfet will be outside the house, and I'd like some protection from (indirect) lightning strike. I don't care if the mosfet, driver and the optocoupler get fried, I don't even care if the atmega gets fried, as long as the surge doesn't reach the enc28j60 which is connected to my home ethernet.
I add the optocoupler between de output of the pwm pin, with a 220 Ohms resistor in between, to drive the optocoupler at it's Vf of ~1.2 V (measured and is OK). The optocoupler's collector is connected to 12V, the emitter is connected to the input of the mosfet driver's input and I added a 33 kOhm resistor to ground to compensate for the driver's high input impedance.
The problem is the low duty cycle values (values < 16 (of 65536)). When I connect a led to the pwm directly (with suitable resistor of course), it lights exactly as expected. I have it run a sweep where the duty cycle gets multiplied by 1.1 every update, so it it glows up and down just nicely. When I connect the same led to the output of the optocoupler, I see non-smooth behaviour. The range 8-16 give all the same brightness, then below 8 the led stops completely.
I realise there are very small duty factors, but it can work nicely, when the optocoupler is removed from between the pwm output and the mosfet driver...
The optocoupler is supposed to have fast switching times, typical 3-5 microseconds (from the datasheet) and the input would have low capacitance: 0.5 pF at 1.0 MHz.
Anyone have an idea?
I have this theory, maybe some can comment? Although the complete pwm cycle is 280 Hz, if the pwm is switched off after only bit period, the "local" frequency is far higher than 280 Hz, something like:
280 Hz (complete pwm period) * 65536 (bit period, 16 bit timer), which yields 18 MHz (!), am I on the right track here? Possible solutions? (other than lowering the pwm cycle frequency or lowering the width of the pwm...)