Making an USB-TTL using opto-coupler

Alright Mike, I agree with you. I check my input of the opto-coupler, and I saw a spike wave form, so I add a cap to place the signal at 0 V line, and the signal at collector ( of the input side of the opto-coupler was better - square wave, but the output of the opto coupler is a small sine wave.

I will keep you guys posted

Don't forget the ground on the scope needs to be on the same side you are doing the measurements on.

Of course Mike, of course... :wink:

Updated :

The problem earlier is this : The signal at collector - Q2 was not 50 % duty, it was 80 to 90 duty.... yeah... not good.

So I modify the input side of the opto-coupler, and I did a small modification of the ouput side - Q3. change R5 and R4.

Here the revised schematic.

Yes again C3 should not be there, it should be all DC coupled.

Now, here the picture of the input signal of the opto-coupler and the output of the coupler.

Top image : signal at Q1 - collector

Bottom image : signal at opto-coupler - pin 5 - collector.

Setting : 1 V / div - 2 us / div. Frequency : 160 kHz. = 160 000 baud rate.

And I know, the probe has to be ground properly ... :wink: at the input side and at the output side. Opto-coupler = isolation...

The idea of using C1, C2 and C3 is to place the signal at 0 V line, and over-saturated the signal ( flat the top and bottom ) so I can get a square wave at 50 % duty... At least close to it.

Next step : construct 3 channel, loop-test at 115 200 baud rate, and upload a sketch into the Arduino to see it working.

OK Mike, in some cases, yes <-- no cap ... in others cases, no <-- with cap.

In my case, I try - with cap and without cap - C3...

Without C3... direct wire. Duty is about 25 %.... With C3 ....Duty is about 30 to 40. At the output of the LS14, with C3, it is much better.

Here the pictures.

Top :

Without C3

Bottom :

With C3

I will keep C3 in that case.

Sorry Grumpy_Mike.

Beside, thank for helping and tips.

None of those low cost optocouplers are designed for high speed. Look up high speed photocouplers in a disti catalog and you'll get sticker shock. The 4N35 datasheet I'm looking at (vishay) says 110 kHz cutoff. Based on Ton and Toff times, you should be able to gt a bit more than that (as you seem to be doing). One thing you can do to coax more speed is decrease the collector current. I'd shoot for 2mA or maybe even 1 mA. You're north of 30 mA. Definitely lose the coupling cap. In fact, I'd lose everything except the pullup resistor (and the emitter resistor, of course). Try not to load the output - I'd feed straight into the Schmidt trigger.

I am aware of the low bandwith of the opto-coupler.

One thing you can do to coax more speed is decrease the collector current. I'd shoot for 2mA or maybe even 1 mA. You're north of 30 mA.

I did try that also, but my speed was below 9600 baud. I investegate and I reduce the R2, see the wave, it improve, so I lower and lower, and the datasheet said 100 ohms is OK. And that was their test circuit. So I look closely at the graphs in the datasheet to figure things out. And I even try to fix the input side <-- the led side, that is why the new schematic have a cap after the output of the LS14. If I did not, the collector signal of Q2 square wave is no longer 50 % duty, but more 10 % duty and it affect the outside of the opto-coupler.

Definitely lose the coupling cap. In fact, I'd lose everything except the pullup resistor (and the emitter resistor, of course). Try not to load the output - I'd feed straight into the Schmidt trigger.

I did that too... not working to well either...

When I build a circuit, I always check the circuit to see if it work fine, if not, I will do some modification to make it work.

I appreciated the help and sudgestions... in theory...yes... practical... well...not so so... need to test...

Anyway, it work fine at low speed ( at 4800 , not higher )...I tested that. I am building a programer link fot the Arduino chip in a live circuit...programing "on-the-fly", the opto-coupler provided the isolation. And I could modify the file "boards.txt" to change the speed from 115200 to 4800, and that will limit the access data rate speed.

Hey, I am still open minded...

Look up high speed photocouplers in a disti catalog and you'll get sticker shock

Sticker shock like : EXPENSIVE .... <--- That what you mean ?

I search the net, typing < high speed opto-coupler and I have a few hits...

I check Digikey.... they have, but you have to order a min of a few hundrends.... yeah... right.... NO THANK...

than I can across the part : 6N135 - 6N135 8 Pin High-Speed Transistor Optocoupler, not to expensive, under 1.50 US, not bad...

OK... here what I am going to do. I will breadboard the 3 channels ( RX, TX, DTR ) of my circuit, test and see what happen. I will download the datasheet of that part, and I will check the local store if they have it, if yes, I will buy it, if not, I will order it and re-do my circuit and re-design around that part 6N135.

I found the 6N135 available locally. It sold a pack of 2 at Active Components - Steeles Ave / Victoria Park Ave - 1 block south, for 3.59 ca. Not bad...

The problem with ordinary optocouplers at speed is that they are slow to turn off. As Mike says, you should DC couple the whole circuit. To speed it up you can connect a resistor between base and emitter of the phototransistor of the optocoupler. The value of this resistor is a compromise, because it reduces the sensitivity of the optocoupler. About 100K is a good value to try. Lower is better if you can get it to work. You may need to increase the drive current of the IR emitter to near its maximum rating to compensate for the reduced sensitivity.

Another thing to avoid is too high a value for the resistor between the collector of the phototransistor and +5v. Again, lower is good for speed but bad for sensitivity. Aim to use a value in the range 1k to 10K.

If you can't get the speed you are looking for in this way, then you will need to use the optocoupler receiver as a photodiode instead (i.e. use the collector and base connections only), and use a load resistor and a high speed comparator IC to detect the small current flow in the photodiode.

@dc42

Yep... I agree with you. The optocoupler I have is slow. I am trying to "push it" to make it work. I have to admited, the 2N3904 is an excellent transistor - for amplification, up to 300 MHz, 35 nS <-- rise & fall - switching -time. excellent cheap transistor... I will have to buy the 6N135 for this particalar project application. And I prefer DC couple, if it work - practicaly. Thank for the tips.

Updated :

I did the loop-test. My setup is : USB - mini adapter - ( come last Friday from http://www.hvwtech.com , a bit expensive - 23.05 ca - it is a excellent USB adapter ) , connect the 3 channel using my circuit... power up, USB connected and a 4.5 V connect... use the serial monitor, select 300 and type : test and I got : @$%& <--- BS data ! re-tested at 115200, same output : &%@& <-- BS output... Humm... :roll_eyes:

Ok, time to re-design and re-test a new circuit. This time, instead using a frequency generator, I will be using the USB adapter as a square wave generator and do a small Processing program to send a : 0101010101 <-- this patern. I will use my scope to see the waveform, and design from there. Heh... it's "breadboarding" time :wink:

Let see ... Start bit, 8 data bits, Stop bit , no parity. It is this ? --- > Start -> 0 - LSB -> 1 - 0 - 1 - 0 - 1 - 0 - 1 - 0 <-- MSB - 1 <-- Stop bit. Hex = 0x55 = Letter "U" ASCII .... I am right ? Anyone correct me here.

If am still having a hard time, I will buy the 6N135.

Updated :

I re-tested and re-build the circuit. I use the USB-mini to test the signal output with the help of my scope. I test at low baud rate : 300 baud to 115200 baud. I did visit this site : http://saturn.uni-mb.si/~bojan/pdf/app45.pdf It show design formulas to use a opto-coupler. Very informative.

In my new circuit, I still use a inverter buffer for input signal and output signal. I use a simple switching transistor circuit to drive the opto-coupler LED and keep the If lower than 10 mA. At the output of the opto-coupler, Rc is a bit higher, 220 instead of 150, I did use 10 K first, but the output signal at collector was bad at high baud rate. So I lower until I have a proper output signal. The signal was ridding above 2 V ( 2 V to 5 V switching ), and I was thinking...hum... a comparator will clean that signal, and I did place a comparator - LM339, set the Vref about 3 V, and I got a NICE output signal ... :smiley: Now, I am in the game... and place the signal to an inverter buffer, so it is 1 in , 1 out, 0 in , 0 out.

Here the Processing code I use to display a "square wave". I use the character 85.

import processing.serial.*;

Serial myport;

int portindex=5;
int myspeed=115200;

void setup()
{
   size(200,200);
   println(Serial.list());
   println("Connecting to "+Serial.list()[portindex]);
   myport = new Serial(this,Serial.list()[portindex],myspeed,'N',8,1); 
   
}

void draw ()
{
    myport.write(85);
}

Here the schematic of the com link channel.

Here the pictures of the output signal at collector - opto-coupler pin 5.

Top picture : At 300 baud

Bottom picture : At 115200 baud

Next step : Wire up the others 2 channel link and do a Loop-Test. If work, upload a sketch into an Arduino chip.

Updated :

Success... :smiley:

I did the "Loop Test" using the IDE serial monitor. I enter : "this is a test" and it echo. I test every baud rate, from 300 baud to 115200 baud. It echo exactly I type on all baud rates. So the final schematic work.

Next step : upload a sketch. I did that and worked just fine. I was using the USB mini, so I select the board : Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328, so the baud rate it was uploading is : 57600 baud., but I try UNO, but it failed to upload, which make sense because it is not a UNO board being program.

Here the board section of the file : boards.txt

pro5v328.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328

pro5v328.upload.protocol=stk500
pro5v328.upload.maximum_size=30720
pro5v328.upload.speed=57600

pro5v328.bootloader.low_fuses=0xFF
pro5v328.bootloader.high_fuses=0xDA
pro5v328.bootloader.extended_fuses=0x05
pro5v328.bootloader.path=atmega
pro5v328.bootloader.file=ATmegaBOOT_168_atmega328.hex
pro5v328.bootloader.unlock_bits=0x3F
pro5v328.bootloader.lock_bits=0x0F

pro5v328.build.mcu=atmega328p
pro5v328.build.f_cpu=16000000L
pro5v328.build.core=arduino

Here a picture of my breadboard circuit setup.

I will post the final complete schematic later.

Now, I am ready for the PCB version.

@ADI_iCoupler

First... Thank for the link and the tips.

Digital Isolators are a more modern alternative to optocouplers, offering improved performance with lower power dissipation. They’re also much easier to implement in a design since the inputs and outputs use standard digital logic.

I do agree with you... if I was planning for mass production of the linker. Or I order a PCB and plce the SMT chip in it. Yes in that case.

The ADuM3160 and ADuM4160 provide 2.5kVrms and 5.0kVrms isolation, respectively, for USB2.0 applications.

Those chips are usefull if I was going to made a USB - "union" . The computer side and the device side power each side. Than those chips will work.

My project do not use the full USB. It use a FDTI, take the signal from it, and send toward an Ardiuno for : Programing transfer or data transfer. So those chips ADuM3160 and ADuM4160 will not be usefull in that application. But this part at that link :

A dual-channel ( "East bound" / "West bound" ) - 2 way traffic. will work. I will need 2 of them if I was going to make / order a PCB accepting SMT part, and mass produce it... yes it will work. Before that, I need to order a sample and experiment with it to test the noew hardware version using those parts.

For now, my circuit design work and I will buy this week-end at Actice Component for a 6N135 and re-do the circuit using those parts to test at high speed.

Thank for the link and info.

Edit :

I found the right part for my project..if I smt's the project... 3 way com-link, 2 -East bound and 1 West-bound. I will need to test a new circuit with the use of the new chip.

Updated...

I re-do the circuit using the 6N135. It pass the loop-test , even 115200 baud,but not the programing test <-- can only program once.

So I decide to keep the 4N35 design for a program linker. The new version with 6N135 will be keep as a comunication linker.

Here the schematic and my setup.

Updated :

I did a test to check data out and data in. In this tread, http://arduino.cc/forum/index.php/topic,94382.0.html, I did a Arduino code to send an ADC value to the PC using Processing, and the Processing code received the value and convert into a voltage and send the voltage value to the Ardiuno to be display on a LCD.

My opto-coupler work great, beside a few bugs <--- voltage a bit off and the display do : 2.345 <-- normal and also .345 <-- not normal. To me, it pass the final breadboard test.

Now, I am in the stage to build the circuit.

Here a picture.

Hi Techone

Techone:
I re-do the circuit using the 6N135. It pass the loop-test , even 115200 baud,but not the programing test <-- can only program once.

So I decide to keep the 4N35 design for a program linker.

Didn't you try to see why the 6N135 isn't completely working right?
Maybe a slight change will solve the problem you mention, and then it'll be working perfectly..

If Data is passing well even at 115200,
but programming is not working,
maybe the problem is in the length of the DTR signal sent..

Maybe the chip makes the signal abit shorter, which can be fixed by making it abit longer for example..
It seems like the problem is in the Reset..

Did you try to see if you manually reset the board (before, after, or both) the upload, then the upload completes well?