Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 3 months ago.
Optocoupler for 5V PWM output not working
I am generating a PWM at 20kHz to drive a motor. The signal goes into a motor controller which range is from 0 to 5 volts.
Since the PWM output is 3.2 volts I need to amplify it. For that I am using this optocoupler:
This is the electronic circuit I am using:
The optocouplers are inverted, pin 1 is down-right. The capacitors are 0.1uf as specified in the datasheet and the resistors are 330 ohms.
The optocoupler output is not working, it gives me less than one volt.
I already try supplying the optocouplers Vcc with an external power source, but the result is the same.
1 Answer
8 years, 2 months ago.
Hi Luis. The optocouplers you are using are open-drain style. This means the part will output a low but not a high logic level. For the 'high state' the output will be high impedance (in logic terms, not a high and not a low). To complete this design, as per the optocoupler datasheet, you will need to insert a pull-up resistor at each output to the voltage of your choice but must be within the recommended maximum voltage as noted in the datasheet. The datasheet is recommending around 360 to 390 ohms but 330 ohms should also be ok to test with one side to your optocoupler output and the other to +5 volts.
Add a 330 ohm resistor between pin 6 and pin 8 of your optocoupler. This will now create a logic 'high' for this output.
Then add another 330 ohm resistor between pin 7 and pin 8 of your optocoupler. This will now create a logic 'high' for this output.
Now, when the optocoupler is in hi-z (high impedance) state, the external 330 ohm resistors will create the true logic high of +5 volts. Test it and post your results.
Hi Luis and Sanjiv, Your input was very helpful to me. I built the electronic circuit, including the pull up resistors and it works well. I needed a 5V PWM for speed control of a harddisk motor using a cheap ESC (electronic speed controller). One thing I found out however, is that the signal which the circuit produces is inverted, which I corrected in my software: the ESC needs 1-2 ms pulses. I use a 50 Hz = 20 ms period. So I made the PWM pulses between 18 and 19 ms. Tip for calibrating an ESC at startup: first give a max. 2 ms pulse and then a min. 1 ms pulse for a few seconds (i.e. 18 and 19 due to the inverter). After that, giving pulses between 1 and 2 ms determine the speed.
posted by 16 Feb 2018