Connect with us

PC Serial -> Custom communications.

Discussion in 'Electronic Basics' started by Guest, Sep 26, 2003.

Scroll to continue with content
  1. Guest

    Guest Guest

    I am looking at building a project that will basically allow me to read and
    write to 128 output lines from a PC's serial port. I know I need a UART and
    PIC, but I have no clue which ones. I have built a basic 16x8 memory
    structure that controls the output lines with a basic addressing system.
    (Each output controls a relay) I am fuzzy on the PC communications and any
    help/advise would be greatly appreciated =)
     
  2. I would recommend against getting a separate UART. There are plenty of
    modern PICs which already incorporate a UART internally, but failing that,
    it is easy to write firmware to bit bang a serial port if you don't need
    bidirection communications at the same time.

    It isn't clear to me how many I/O lines you need to operate your memory
    addressing system, but as a good start, I would recommend looking at the
    PIC16F627A. If that one doesn't have enough I/O pins, the PIC16F873A has
    more I/O pins and other schnazz. Both of these PIC include the internal
    UART. If cost is no issue, you might even wish to splurge on one from the
    newer and cooler PIC18F series. You can compare the PIC features in the
    Microchip Product Selection Guide [
    http://www.microchip.com/download/lit/rlit/00148h4.pdf ].

    On the PC side, communications with the serial port is entirely defined by
    your operating system. If you are writing for Windows, you will need to use
    the CreateFile, ReadFile, WriteFile, and CloseHandle Win32 API functions,
    among possibly others. I would recommend taking a look at [
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp ]
    .. If you have Visual Basic, the Mircrosoft Comm Control (MSCOMM32.OCX) may
    simplify your implementation.

    Howard Henry Schlunder
     
  3. If I understand you well, you need to switch 128 relays independedly. You
    already have a 4 to16 lines address decoder of which each (decoded) address
    line correspond to a 8 bits memory word (usually called a register.) So each
    of the 16 address lines controls 8 relays.

    Some simple calculation tells me that you have to get 12 bits of data out of
    the computer, 4 address bits and 8 data bits. To achieve this, a micro with
    a build in uart and 12 output pins (plus the pins used by the uart of
    course) will do. But.... an asynchronous serial data link only transfers
    groups of 8 bits (or less.) So your main task is to develop a protocol that
    makes it possible to distinguish between adress and data bits or, in other
    words, reliably transfers 12 bits of "data" using an eight bits channel.

    One method may be to cut the 12 bits into three portions of four. Then you
    first send an eight bit word containing the address in one nibble and the
    number one in the second. Next you send four databits in one nibble and a
    two in the second nibble. You will guess that you send the remaining four
    databits with a three. The receiving micro checks the sequence of the parts
    and re-establishes the original form so it can be used to switch the relays
    addressed.

    If something goes wrong the micro will have to send back an error message to
    the PC. Otherwise your main controlling program is not aware of it and may
    make wrong decisions.

    A PIC16F870 will do all this for you, that's to say, when you programmed it
    correctly first. But this is only an example. There are lots of other micros
    that can do the same.

    pieter
     
  4. Guest

    Guest Guest

    Thanks for the help guys =) I think I know the basics that I need to in
    order to get started on this project. Howard pointed me to beyondlogic.com
    which was really helpful and the recommendation by petrus gave me the basic
    idea of what I needed =)

    I am sure I will be back with lots of questions =)
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-