I searched and read through a lot of posts on optoisolators on this forum and I thought I understood how to use one. I drew this schematic and built this circuit but it did not work!
It is basically an SPI-type isolated interface from an MCU to another board. I am pushing 5mA though the LEDs (which I measured and verified). The ACPL-247 datasheet says the current-transfer-ratio is 100-600% at 5mA If. My data/clock speed is slow, about 500 Hz. I chose 2.2K pullup resistors. One thing I noticed was when I put oscilloscope probes on the CLK and MOSI pull-up resistors, the circuit worked. I experimented and changed the 4 pull-up resistors to 1K and then the circuit worked perfectly.
I do not understand why the circuit works with 1K pull-up resistors and doesn't work with 2.2K. Anybody have an idea? This is really bothering me...
Are you sure that the clock has a long high and long low time ? and not short pulses at 500Hz.
The optocoupler is for maximum 80kHz, that is very slow to be used next to a microcontroller.
The lower the RL, the lower the response time.
In the datasheet they say 2us response time if RL is 100 ohm.
I'm bit banging the CLK 1ms low, 1ms high, and making sure MOSI changes in the middle of the clock cycle not anywhere near CLK edges. Verified it on a scope many times...
Does not make sense to me why 2.2K pull-ups are not sufficient.
No, I don't know what caused it.
Perhaps there is a lot of noise. For example a 5V that is not decoupled, or a bad ground.
When you put the probe pin on the pullup resistors, a little capacitive coupling is added. But the 2k2 is already a low value. Or is there a servo motor or something like that nearby ?
My best guess is a noisy 5V or very low 5V, or with short pulses at the 5V, or a bad GND. But that's just a guess, I have no clue
Using 2.2K would adversely slow the turn off time of the signal.
In the datasheet, the total delays would be 67µs for IF=16mA and RL=1.9K
In your case, IF = only 5mA and RL = 2.2K which would probably increase the total delay to >100µs
I think the slow rise time here is messing up the required timing of signals in relation to each other for the shift register (they may slightly overlap and appear as crosstalk). Also, isolator 1 may have CTR of 100% and isolator 2 have CTR of 148%, etc.
The 1K pull-ups (lower resistance) produce sharper signals. More Less current at IF will also produce sharper signals.
EDIT: Corrected ... See MarkT's reply below. +1
You aren't using a logic optocoupler, you are using a very slow analog one - the turn-off time on the
photo-transistors is 40us, so these are good for perhaps 5--10kHz, not fast logic speeds.
Note that turn-off time for phototransistors is much worse than turn-on time and can be improved
by using less current in the LED (within reason). A stronger pull-up will also help.
You probably need a logic opto-coupler like the ACPL-6400 (switching times about 100ns) or the new
non-opto logic isolators like the ISO734xx family: http://www.ti.com/lit/ds/symlink/iso7342c.pdf
[max 60ns switching] for fast SPI interfacing.
Thank you all very much for the help! It was extremely useful.
Very slow turn off times would explain the strange behavior I was seeing. I have changed the pull-up resistors to 1K on all of my boards and they are all working perfect now.
The issue with phototransistors (as opposed to photodiodes) is that the light flooding in generates lots
of stored charge in the base region (like over-saturating a BJT), and this charge has to clear the base
after the light goes before the transistor stops conducting. Still 40us is about the worst I've seen!
This kind of thing is why you should read the datasheet...