PC's Serial Port out -> parallel bits

Thread Starter

squatchy

Joined Nov 21, 2012
43
I fail to understand why something that would seem hugely common and helpful is so poorly documented and described in the circuit world.

All I want to do is connect the DATA OUT pin on a serial port from my PC to some kind of shift register, or UART, or converter in such a way that sending data bits in serial order will result in a single register of 8 parallel bits on an external circuit.

How can I do this? I don't want to use an Arduino or an entirely separate microcontroller, I just want to build a circuit that detects the baud rate of incoming serial data (start bits, stop bits, etc.), and outputs it as parallel data at fast pace.

Not sure why I'm having such a hard time researching this.

Attempt #1: Send data through the DATA OUT serial port pin to a shift register, and alternate 1 and 0 on one of the "READY" serial port pins for the clock speed on the shift register. This works, but something is limiting the alternating changes on the "READY" pin of the serial port to 1000 hz, so basically that's the limit.

Attempt #2: Buy a 24-pin digital I/O board from Measurement, then try to change the values of the pins quickly in C#. Unfortunately the board I got is not meant for high speed digital out, and the library calls take 7ms apiece which is really slow.

Attempt #3: Thinking about buying a UART chip and trying to wire it up to the serial port. Will this work? I can't tell if all UART chips have automatic baud rate detection or not. I feel like I need the chip to auto-detect the baud rate because there's no way for me to tell an external device what baud rate my PC is sending. Why is that? Seems dumb that serial ports can't send out a clock signal, just data.

I realize that I'm being too dumb to grasp this, so anything obvious that I'm missing would be greatly appreciated. :rolleyes:
 

tshuck

Joined Oct 18, 2012
3,534
How can I do this? I don't want to use an Arduino or an entirely separate microcontroller, I just want to build a circuit that detects the baud rate of incoming serial data (start bits, stop bits, etc.), and outputs it as parallel data at fast pace.
An FPGA would probably be the fastest, but that requires a lot more work than setting up a PIC to output the data in it's RX register on a RX interrupt...

Seems dumb that serial ports can't send out a clock signal, just data.
You are using an asynchronous transmission protocol.... seems pretty logical to me...:p
 

WBahn

Joined Mar 31, 2012
29,979
What are you going to do about data format, such as how many data bits, how many parity bits, and how many stop bits? If you are going to have to configure your external device for these parameters, why not configure it for baud rate at the same time?

If you want the baud rate to be auto-configured, then a common way is to initiate communication at a fixed baud rate, such as 2400 baud or 9600 baud, and then negotiate a different rate. One way to do this is have the initiating side tell the other side it's fastest rate. The other side then responds with it's fasted rate that is equal to or less than the rate it received. The first side does the same. This continues until one side echoes the same rate it was last told, meaning that this is the highest rate that both devices support. Both devices this reconfigure for that speed and the original initiator initiates the real communication at the agreed upon rate.

If you want to actually detect the baud rate, then you will almost certainly lose packets until you are fully trained up. One way to do this is to have the sender repeatedly transmit beacon packets of 55 or AA (or some other known and edge-rich data) and the receiver adjusts it's baud rate until it has received some minumum number of consecutive beacon packets and then to send an acknowledgement to the sender at the detected baud rate.

I would recommend against using the Ready (or other) hardware flow control signals since the degree to which these are supported and controllable in software is very hit and miss.
 

Thread Starter

squatchy

Joined Nov 21, 2012
43
You are using an asynchronous transmission protocol.... seems pretty logical to me...:p[/QUOTE]

I'm fine with an asynchronous protocol but then what's the circuit-based hardware solution for processing that data without running into problems with baud rates, etc.?

I'm trying to extend the software logic in my computer out to the real world of LEDs, motors, and such, but it seems like every solution for processing serial data, etc. just extends it further out into a microcontroller with its own software, etc.... what's the simplest way to get this serial data out onto an 8-bit register without raspberries and Arduinos, etc.?
 

Thread Starter

squatchy

Joined Nov 21, 2012
43
What are you going to do about data format, such as how many data bits, how many parity bits, and how many stop bits? If you are going to have to configure your external device for these parameters, why not configure it for baud rate at the same time?

If you want the baud rate to be auto-configured, then a common way is to initiate communication at a fixed baud rate, such as 2400 baud or 9600 baud, and then negotiate a different rate. One way to do this is have the initiating side tell the other side it's fastest rate. The other side then responds with it's fasted rate that is equal to or less than the rate it received. The first side does the same. This continues until one side echoes the same rate it was last told, meaning that this is the highest rate that both devices support. Both devices this reconfigure for that speed and the original initiator initiates the real communication at the agreed upon rate.

If you want to actually detect the baud rate, then you will almost certainly lose packets until you are fully trained up. One way to do this is to have the sender repeatedly transmit beacon packets of 55 or AA (or some other known and edge-rich data) and the receiver adjusts it's baud rate until it has received some minumum number of consecutive beacon packets and then to send an acknowledgement to the sender at the detected baud rate.

I would recommend against using the Ready (or other) hardware flow control signals since the degree to which these are supported and controllable in software is very hit and miss.
This all sounds like another software solution on an external microcontroller. Doesn't anyone else think it's weird that there isn't a simple way to have general I/O pins out of a PC? Having to upload my programs to a microcontroller with 1/100th the processing power and a tiny fraction of the memory seems silly to me. I want to run software on my PC which directly controls electrical circuits via a series of binary commands.... I know the programming, and I know the basic circuitry/robots..... it's all the crap in-between I don't understand.
 

Papabravo

Joined Feb 24, 2006
21,159
The simple answer is that "Serial" ports are just not designed to drive shift registers and they never were. The original UARTS from General Instruments AY3-1013 series were designed to do what you want. The parameters were hardwired to specific pins on the UART and the parallel outputs had a strobe when the data register was full.
 

MrChips

Joined Oct 2, 2009
30,720
As far as I know, the only way to do automatic baud detection is you have to begin transmission with a known character, or at the minimum, a character that is ODD, i.e. the least significant bit is ONE.

I fail to understand why something that would seem hugely common and helpful is so poorly documented and described in the circuit world.
This is fully documented. You just have to know what and where to look. If you don't know what to look for you are not going to find it.

You really need a UART. A much simpler solution is to use a microcontroller.
 

tshuck

Joined Oct 18, 2012
3,534
I'm fine with an asynchronous protocol but then what's the circuit-based hardware solution for processing that data without running into problems with baud rates, etc.?
There is no such thing... what you are describing is a synchronous protocol, one that agrees when data is ready based off of a clock line... The RS-232 protocol relies on specific timing. You could design an auto baud rate detector using this information, but that would be more work than using a uC...

I'm trying to extend the software logic in my computer out to the real world of LEDs, motors, and such, but it seems like every solution for processing serial data, etc. just extends it further out into a microcontroller with its own software, etc....
And this data needs to be translated into a form that can be used....

what's the simplest way to get this serial data out onto an 8-bit register without raspberries and Arduinos, etc.?
perhaps a blueberry? I kid.

Seriously, though, the baud rate, or symbol rate, is time dependent, meaning that a discrete solution will be quite cumbersome and more work than even starting from the ground up in uCs....
 

Thread Starter

squatchy

Joined Nov 21, 2012
43
As far as I know, the only way to do automatic baud detection is you have to begin transmission with a known character, or at the minimum, a character that is ODD, i.e. the least significant bit is ONE.

This is fully documented. You just have to know what and where to look. If you don't know what to look for you are not going to find it.

You really need a UART. A much simpler solution is to use a microcontroller.
If a microcontroller is going to let me pass binary between C# and a set of digital in/out pins at a very high speed, then can you recommend one that can do this faster than the pokey 142hz digital i/o board I've already tried? I know there are a lot of fancy microcontrollers out there but if I use one it's sole job is literally going to be to herd bits from a USB/serial port onto a set of GPIO pins as fast as possible.

Thanks for tolerating my idiocy.
 

tshuck

Joined Oct 18, 2012
3,534
This all sounds like another software solution on an external microcontroller. Doesn't anyone else think it's weird that there isn't a simple way to have general I/O pins out of a PC? Having to upload my programs to a microcontroller with 1/100th the processing power and a tiny fraction of the memory seems silly to me. I want to run software on my PC which directly controls electrical circuits via a series of binary commands.... I know the programming, and I know the basic circuitry/robots..... it's all the crap in-between I don't understand.
Ever hear of the parallel port? It's dead because it was too bulky and limited...

If you understand robots, then you should understand communication protocols...
 

MrChips

Joined Oct 2, 2009
30,720
Just about any microcontroller will do the trick, except Low Pin Count chips. You will need a chip with at least 14 pins.
 

Thread Starter

squatchy

Joined Nov 21, 2012
43
How I feel:

"I have a really fast and powerful computer which I can run programs on. I want to write a program that sends raw binary data out to a set of metal pins, which I will connect to an otherwise isolated electronic circuit which does things with that data, such as turn on lights, motors, servos, etc., all directly commanded by my fast computer."

What I keep hearing:

"Your really fast computer can't do that. You have to send the binary data to a small, really slow, incredibly inferior computer first. That computer has general input/output pins as you request. Unfortunately, the small computer is really slow, has almost no memory, and also will not run your programs because it's such a limited device. Good luck."
 

tshuck

Joined Oct 18, 2012
3,534
How I feel:

"I have a really fast and powerful computer which I can run programs on. I want to write a program that sends raw binary data out to a set of metal pins, which I will connect to an otherwise isolated electronic circuit which does things with that data, such as turn on lights, motors, servos, etc., all directly commanded by my fast computer."

What I keep hearing:

"Your really fast computer can't do that. You have to send the binary data to a small, really slow, incredibly inferior computer first. That computer has general input/output pins as you request. Unfortunately, the small computer is really slow, has almost no memory, and also will not run your programs because it's such a limited device. Good luck."
And yet you refuse to believe us:p
 

tshuck

Joined Oct 18, 2012
3,534
If you really want to take advantage of your computer's speed, you will need a PCI card which will allow for parallel output... I know of a few, but I haven't seen any used for a very long time....Not to mention you'll probably need to write your own driver for it...
 

MrChips

Joined Oct 2, 2009
30,720
So you have a super fast computer.

You want to send digital data to the outside world and control things such as lights, motors, servos, etc.

What is the maximum switching rate by which you want to control these lights, motors, servos, etc.?
 

tshuck

Joined Oct 18, 2012
3,534
MrChips brings up a good point, most of the devices that you have referenced do not need anything fast. Human vision is roughly(and I mean roughly) 30Hz and motors are largely inductive slugs with really low response times....
 

MrChips

Joined Oct 2, 2009
30,720
That is only partially my point.

The real point I want to make is whenever someone says fast, they should define what fast means.

I can send a new character every 20μs over USB. Is that fast enough for you?
 

Thread Starter

squatchy

Joined Nov 21, 2012
43
So you have a super fast computer.

You want to send digital data to the outside world and control things such as lights, motors, servos, etc.

What is the maximum switching rate by which you want to control these lights, motors, servos, etc.?
Let's say I send serial data out the serial port of my PC (from a C# program). It goes to a microcontroller running on on-board program and its only job is to cut the incoming data into byte-sized chunks and place them on an 8-bit pin register for output. It does that fast enough that I can use those 8 pins to send the data out to a huge 256-bit-long chain of shift registers using clock signals, etc.

If I can do that, and refresh the 256-bit register chain at 50hz or faster, I'd be plenty happy.

I haven't found a way to do it that fast yet though.
 

Thread Starter

squatchy

Joined Nov 21, 2012
43
That is only partially my point.

The real point I want to make is whenever someone says fast, they should define what fast means.

I can send a new character every 20μs over USB. Is that fast enough for you?
Probably, if you can split all that data out using shift registers and clock signals, etc. onto a large number of I/O pins.

I'm not working with christmas lights, but if you can imagine my end goal being to have 256 or so final-destination GPIO pins which I can directly control from C# and do it quickly, that's pretty much what I'm looking for and I imagine I'm not the only one.
 
Top