Jump to content
Electronics-Lab.com Community

Interfacing circuits to the PC


slackjack
 Share

Recommended Posts

Hey guys,

I'm now wanting to interface circuits to the PC. Whether if its for data acquisition, control systems or just to light up a few LEDs or LCD display, it just comes down to interfacing. My question is what interface (port) should I use on the computer - serial port, parallel port or USB port? And can you please say why I should use that.

--thank you  :)

Link to comment
Share on other sites

My personal choice is the Serial port.
Parallel ports are getting rare on new machines and if you do use one you will need to run 8 data lines, 3 control lines (minimum) and you may have to fight the OS for direct hardware control of the port.

USB is a very hard to use.  It requires a complex protocol that is tricky to implement on a small system. The hardest part to manage is the memory stack needed. Most microcontrollers are limited in memory so just setting up a USB can be difficult.

If you use a higher end processor or development board, some of them have built in USB support (The higher end PIC chips and the Rabbit systems for example)

A serial port only needs 3 wires so the interface is physically simple.
The Voltages can be converted using a MAX232 chip (Digikey part Number:MAX232ACPE-ND)
This allows you to deal with simple 5V single supply systems.

The Async Protocol is supported on many microcontrollers as part of the hardware.  The PIC16,17, & 18 series all have UARTS and hardware support right on the chip.

On the PC side the serial interface is easy to use also.  Most OS actually handle much of the interface for you and they even supply terminal emulators.  (Windows = Hyper term)

In Visual Studio you can use the MSCOMM object for C or VB programs.

With a baud rate of 192kbs the serial port is fast enough for most needs.

-Mike

Link to comment
Share on other sites

which software, what are you going to control or get data from, how many channels do you need, analogue or digital or both?


Well for now I'm going to use windows xp (mayb later I'll worry about interfacing with linux). Ante can you please elaborate on "software". For now I plan to control, but later I will be using sensors hooked up to the computer. I dont understand what is meant by "channels". I guess (talking about the sensor part) ill measure some entity with analog signals then ill have to convert it to digital signals so the computer can understand it.  But before I jump that far ahead ill worry about the LEDs and LCD display  ;D

The Voltages can be converted using a MAX232 chip (Digikey part Number:MAX232ACPE-ND)
This allows you to deal with simple 5V single supply systems.


This 5v you are talking about. Does it apply to the volatge from or to the serial port? What is the typical output volatge from the serial port or is it variable?



Link to comment
Share on other sites

The RS232 standard uses 16V signals, however 12V is acceptable.

The MAX232 chip uses 4 capacitors and some clever internal switching to convert a 5 volt supply into a 12V supply for the RS232 standard.

Without the MAX chip you could use the 1466 Driver and the 1468 receiver plus a 12V power supply.

Here is a little chart. 
I hope it aligns right.  It shows the voltage levels we are talking about:

5volts (TTL level)---[MAX232 Chip]---(12/16V Rs232 Level)
Tx from Microchip->TX In==TX OUT->Tx RS232  to PC.
Rx To Microchip<-RX Out==RX In<-Rx RS232  From PC.

Here is one solution you may look into as a simple test project.

PIC 12CE684 (I think that’s the number)  it’s an 8 pin part.
It has 2 power pins (Vcc and Ground)
It has 2 A/D converters on board (With an external Vref input if needed)
And the remaining 4 pins can be used for anything else.

You can pick 2 pins and make them the TX and RX pins for the serial port.

The source code for the RS232 Protocol is on Microchip.com in an application note.
Once you have the code modified to run on the PIC12 series, You can sample 2 different things at the same time and then send the data to a PC.

I would have the PC send a signal to the PIC first, something like a ‘?’ symbol.

Computer to PIC:  ?
Pic to Computer: 1=124<CR>2=209

Note: the PIC will return 0-255 from the A/D converter, you will have to convert that to an actual value your self depending on what you are measuring. 
For Instance if your Vref is 9v, then a measurement of 192 could be converted to a reading by (192 * 9) /255 =  6.78V (Binary reading times Vref) divided by Max Reading = Actual Value.

Does that help?

-Mike

Link to comment
Share on other sites

Hi Jack,

Well software might be visual basic if you are making your own code. I might also be some commercial software for controlling the outputs/inputs you need. Channels, the number of relays (example output device) or number of inputs from NTC, A/D converter or any other source you like to sense or read.
There is a tutorial here in E-Lab about interfacing an LCD to your computer, have you checked it out?

Link to comment
Share on other sites

I'll be using TubroC++ for my programs. Is it this project you are referring to Ante?
http://www.electronics-lab.com/projects/pc/020/

Theatronics, thanks for the walkthrough, it very much appreciated. But I have decided to use the parallel port as a start becuase I have several books on it  ;D Do you have any tips on using the parallel port, mayb some experiments?

thanks again guys.

Link to comment
Share on other sites

Parallel ports are about as straight forward as you can get in the electronics world.

8 wires / 8 bits.

Unless you need it to be complex try to keep it simple.

Bi-directional ports can be done but some computers require you to
Select that mode in the Cmos. Check your machine before you get
Frustrated.

Most ports support 8 output pins and 8 input pins (16 total)
The 8 input pins are meant for the old line printers to use.
(Paper out, Offline, Wait, Printer Ready, and some others….)

These are often forgotten about because everyone goes right for
The Bi Directional mode.  If you only need a few inputs because
You are building a controller rather than an input, try to use those.

ALWAYS BUFFER YOUR INPUTS.

Put in some sockets and put simple line buffer chips in as the first part for all the data and control lines.  This will protect your computer from damage if you blow something on your board.  NOT ENTIRELY but some protection is better than none!.

BE CAREFUL ABOUT GROUND LOOPS.  Make sure the ground on your PC is the same as your power supply.  Some bench power supplies can be set to ‘float’ If yours does you will need a real solid ground between your PC and the PS.

Use latch chips to capture data from the PC.  If you try to latch the data at a Microcontroller you might miss the pulse. Remember your PC is running at a much higher speed than your Microcontroller.

I don’t have any good Parallel examples because I have only built a few things that use the port.  A CNC controller and a LED Sign.  Later I wished I had used a serial port anyway. 

Good Luck!

-Mike

Link to comment
Share on other sites

Before you make your decision about what port to use, check this out:

http://www.sparkfun.com/commerce/product_info.php?products_id=762

This "Bit Whacker" looks perfect for simple and modern interfacing with any USB equipped computer! On plug-and-play USB systems it identifies itself as a serial port, and shows up as such in Windows device manager. Linux too should automatically create a TTY device for it. This means of course that your program treats it like a serial port, but with all the speed and portability of USB. Magic!

SparkFun (OK, a shameless plug, I know) has tons of other stuff for interfacing, and I encourage you to check out the whole kit and kaboodle.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
  • Create New...