Communicating 64 bits via the serial port - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Communicating 64 bits via the serial port

I need to be able to send up to 64 bits via the serial port. i have found several pages of information each only discribing how to send 8 bits at a time and i unsderstand these articles to adequate standard, enough to actually go ahead and build one.

I have searched for a microcontroller whch will give me 64 bit input and 2 bit output (+ everything else required) but i have had no luck.

If anyone can help, i'd appreciate it.

TIA

Comments

  • pcrompcrom Posts: 7Member
    : I need to be able to send up to 64 bits via the serial port. i have found several pages of information each only discribing how to send 8 bits at a time and i unsderstand these articles to adequate standard, enough to actually go ahead and build one.
    :
    : I have searched for a microcontroller whch will give me 64 bit input and 2 bit output (+ everything else required) but i have had no luck.
    :
    : If anyone can help, i'd appreciate it.
    :
    : TIA
    :

    Well, I don't think you will find a serial port that does anything else than 7 or 8 bits. Reason for this is that it is a standard (called RS-232). All drivers that I know let you use 7/8 databits, 1/2 stopbits etcetera.
    But why do you want to use 64 bits ? You can send out 8x8 bits ?

    Please let me know if this gets you some further

    Patrick



  • TomasTomas Posts: 30Member
    : : I need to be able to send up to 64 bits via the serial port. i have found several pages of information each only discribing how to send 8 bits at a time and i unsderstand these articles to adequate standard, enough to actually go ahead and build one.
    : :
    : : I have searched for a microcontroller whch will give me 64 bit input and 2 bit output (+ everything else required) but i have had no luck.
    : :
    : : If anyone can help, i'd appreciate it.
    : :
    : : TIA
    : :
    :
    : Well, I don't think you will find a serial port that does anything else than 7 or 8 bits. Reason for this is that it is a standard (called RS-232). All drivers that I know let you use 7/8 databits, 1/2 stopbits etcetera.
    : But why do you want to use 64 bits ? You can send out 8x8 bits ?
    :
    : Please let me know if this gets you some further
    :
    : Patrick
    :
    Hi!
    I have to agree with Patrick. I have seen microcontrollers that let you use 9 databits, but thats just the paritybit that you may use as you like, a PC wouldn't accept that. I can imagin that you see difficulties in keeping track of wich bytes of bits that belong to each other? The way to handle such things is to implement a simple protocol, first send a header, then the data.
    /Tomas

  • JamesFosJamesFos Posts: 240Member
    Lets see now, how to get you to understand...

    I have a box with 64 buttons. (producing 64 high/low states)

    I have a UART which i can interface with the serial port but which only has 8 inputs.


    now, I hope you can see that this is not enough to send 64 bits to the computer!!!

    I don't care if it comes into the computer in 8 bit slices, in fact that would be best.

    but how do i do that??? (I need a hardware answer)

    TIA

  • pcrompcrom Posts: 7Member
    : Lets see now, how to get you to understand...
    :
    : I have a box with 64 buttons. (producing 64 high/low states)
    :
    : I have a UART which i can interface with the serial port but which only has 8 inputs.
    :
    :
    : now, I hope you can see that this is not enough to send 64 bits to the computer!!!
    :
    : I don't care if it comes into the computer in 8 bit slices, in fact that would be best.
    :
    : but how do i do that??? (I need a hardware answer)
    :
    : TIA
    :

    Ok, in that case I think th ebest way is to use a TTL shift register like the 74xx198. This chip has 8 parallel inputs and shifts this information out serially. It can be cascaded so with 8 of those chips you have 64 inputs. It is a TTL IC, so it works with 5V signals. It cannot directly used on the RS-232 port, because this one uses +/- 12V levels. Also you cannot use the standard shift-instructions for the serial port because the RS-232 uses no direct clocking signals. Two solutions for this :
    1) Connect the chip to the serial port via level converters.
    2) Connect the chip directly to signals of the parallel port, which is allready 5V.
    In both ways you should write a program that controls directly the in- and output signals of the hardware port.

    The serial port of the PC has only nice possibilities when the connected device communicates also via RS-232. In most cases this means it must also be a computer or microcontroller

    Hope this helps ?

    Patrick

  • JamesFosJamesFos Posts: 240Member
    Thanks.

    I'll see if that helps.

    I'll be back to ask more questions later.

    James

  • retrogeekretrogeek Posts: 93Member
    : Lets see now, how to get you to understand...
    :
    : I have a box with 64 buttons. (producing 64 high/low states)
    :
    : I have a UART which i can interface with the serial port but which only has 8 inputs.
    :
    :
    : now, I hope you can see that this is not enough to send 64 bits to the computer!!!
    :
    : I don't care if it comes into the computer in 8 bit slices, in fact that would be best.
    :
    : but how do i do that??? (I need a hardware answer)
    :
    : TIA
    :

    It sounds like you are basically attempting to interface a (64 key) keyboard to the computer through the 8 bit (actually 1 bit) serial port. You might want to do a search for keyboard interfacing.

    How about this.........???

    Use a uart chip to connect to the computer serial port to give you 8 parallel input lines and 8 parallel output lines.

    Arrange the button connections as an 8 by 8 matrix (8 rows, 8 columns).

    Connect the 8 uart output lines through an octal D-type latch chip to the row side of the matrix.

    Connect the column side of the matrix to the input of the uart.

    With software, scan the matrix to see which, if any, of the buttons are pressed.


    Pseudo code:
    (numbers are decimal, AND is the logical bitwise operator AND)
    [code]
    do
    let rownum = 1
    do while rownum is less than 2^8 (256 decimal)
    Output rownum to the serial port
    let colnum = 1
    let inp = serial input
    do while colnum is less than 256
    if inp AND colnum is true then...
    consol output -- "button at row log (base 2) rownum
    colunm log (base 2) colnum
    is currently pressed"
    endif
    let colnum = colnum x 2
    end do
    let rownum = rownum x 2
    end do
    [/code]

    If the programming language you are using has a shift-left operator, that would be more efficient than multiplying by 2

    You could also implement the matrix scan in hardware, but then you would have to multiplex the column output and the scan output so the computer would know which row is being scanned when it finds a high on a column output.... much more complicated both hardware and software.

    Hope this gives you some ideas.

    Enjoy!

    rg

  • JamesFosJamesFos Posts: 240Member
    : Arrange the button connections as an 8 by 8 matrix (8 rows, 8 columns).

    No can do. i've investigated a martix and the only problem is that you can not tell which buttons are being pressed if more than one button is pressed. i need to be able to tell exactly which buttons are on and off all of the time.

    Thank you for your help tho. If you know of a wany to compress the information contained in 64 bits so that you could easily extract it (or not so easily) that would be great!

  • retrogeekretrogeek Posts: 93Member


    : : Arrange the button connections as an 8 by 8 matrix (8 rows, 8 columns).

    :No can do. i've investigated a martix and the only problem is that you can not tell which buttons are being pressed if more than one button is pressed. i need to be able to tell exactly which buttons are on and off all of the time.

    You are thinking of a diode matrix to give a unique 8-bit number to each key. Yes, such a system is unable to detect n-key rollovers (multiple buttons pressed) correctly.

    But, with the system I described, using the buttons themselves in a scan matrix, you WILL be able detect all of the buttons that are pressed! In each iteration of the outer loop of the software, one row of 8 buttons is enabled, with the other 7 rows (56 buttons) disabled. The iteration of the inner loop then checks each of the 8 column buttons in the enabled row, detecting each one that is pressed. The outer loop then disables the first row (and all the other rows) and enables the second row. Again the inner loop checks each of the columns in that row. The process continues, checking each of the 64 buttons. If more than one button is pressed: let's say three buttons are pressed, it will detect each of the three buttons.

    :If you know of a wany to compress the information contained in 64 bits so that you could easily extract it (or not so easily) that would be great!

    In effect, that is what the hardware system does! The 64 bits of information is time-multiplexed, dividing the available time into slices of eight and using each slice to send 8 bits of information. The software then latches the information coming through on the slices to put it back together as 64 bits of data.

    To perhaps make this more clear, here is the pseudo-code rewritten to specifically show the state of each (and every) button:

    [code]

    Pseudo code:
    (numbers are decimal, AND is the logical bitwise operator AND)

    do
    let rownum = 1
    let writebitnum = 1
    do while writebitnum is less than or eqal to 8
    Output rownum to the serial port
    let colnum = 1
    let readbitnum = 1
    let inp = serial input
    do while readbitnum is less than or equal to 8
    display on the console:
    "button at row" writebitnum "and column" readbitnum "is"
    if inp AND colnum is true (1) then display on the console:
    "pressed"
    else if inp AND colnum is false (0) then display on the console:
    "not pressed"
    endif
    display a carraige return and linefeed on the console
    let colnum = colnum x 2
    let readbitnum = readbitnum + 1
    end do
    let rownum = rownum x 2
    let writebitnum = writebitnum + 1
    end do

    [/code]

    Now, when this code is invoked, 64 lines will be displayed on the computer console describing where each of the 64 buttons is in the matrix, and stating whether or not it is pressed.


    Perhaps eliminating the logarithm base 2 stuff will help relieve some confusion (actually, it is still there -- it's just that the routine generates the logarithms).


    BTW, I just realized that the hardware system as described won't work because of TTL specs. It may work with mos type uarts but probably not. When the buttons are open (not pressed), it leaves the uart inputs floating, and they will probably float high. So the computer will always see a 255 (11111111 binary) on the serial input. Pulling each of the 8 usart inputs low with a 4.7k ohm resistor will probably fix it for mos uarts. For TTL uarts, you would probably have to pull the inputs high with 1k ohm resistors, then change the software to invert the port putputs and inputs. That is, a 1 on coming in would indicate a non-pressed button, and a 0 would indicate a pressed one.

    Hope this helps

    Enjoy!

    rg

  • JamesFosJamesFos Posts: 240Member
    Thank you. it is all made clear now. Ingenious. I've been trying to work out how to do that for ages, that's exactly what i need!

    Thanks again.

    Greatfully
    James

Sign In or Register to comment.