Friday 12 July 2019

Optoisolated Serial Coms

When Digital Meets Analogue

For my Multi-channel meter, I used some FL817 opto-isolators from Aliexpress.  Why?  Cheapest I could find.



I was then dissapointed to find that they didn't work at 115200 baud, but did at 9600.  I parked that for a while, then decided to take a look at it later.  It's now later :)

Not Square Waves




Firstly, I took a look at the expected waveforms.  The orange traces in the plots above are the signals from the microcontrollers UART, and the green are measured at the collector of the output transistor on the opto-isolator. 

As you can see, the rise time of the green signals are much slower that the orange.

MATHS

Of course, I took the screen shots above using 19200 baud (probably as this was the speed things started to get flaky).

The pulse length of an 19200 baud signal is (1 / 19200 s) = 52 micro seconds.

However the green pulse takes a while to rise as per this pic:


The time between the red lines looks to be about 2 1/2 ticks on the scope trace, and the time base (M) is set to 25 us per division, making the delay around (2.5/5)*25us = 12.5us.

Or 24% of a bit (symbol).

As most uarts sample multiple times (Pics sample 8 times the baud rate for example) you need a majority of reads to match to register a bit successfully.  At 19200 baud as shown above, you'll get 6 out of 8 samples registering if you're lucky.  At 9600 baud (104us) you'll get 7 reliably.  

At 115200, where the bit length is 8.7us, the rise time of the opto is more than this and you have zero chance of any bits getting transmitted.

RTFM?

Ok, so why didn't I see this coming?  Well, I didn't look.  Remember, just bought the cheapest ones on the day...

So looking at a FL817 datasheet, there's this spec:


Notice the "TRANSFER CHARACTERISTICS" has a specified 'cut-off frequency' of 80kHz typical.  

9600 Baud is well under this rate, 19200 is within band and 115200 is way too high.  

Also, the inverse of 80kHz is 12.5us, just like the measured rise time above.

So, it's all works as expected, and good to know why.


No comments:

Post a Comment