Serial Port/PLD communcation. Suggestions?

Jun 14, 2006 9 Replies

I am working on a very simple hardware project and would like to develop serial port controls, but I'm having a little bit of trouble starting out. The project is the following:



I have built an LED lamp with 8 seperate light-up sections controlled by a PLD. Each time the PLD clocks, it assigns the value of the input (either high or low) to one of the output pins (0 through 7), which subsequently controls the lamp.



I would like my program to set these segments with the 9-pin serial port, which means I need to send a clock signal and a single bit of data, either high or low, to the PLD. However, all the information I can seem



to find online about the serial port and C is about large data and file



transfers. Any suggestions? I have never programmed with hardware before.



Well, serial port is of asynchronous nature, so it will be pretty difficult to transmit a clock signal through it. I would try, instead, with the parallel port.

regards,

Zara

On 13 Jun 2006 22:37:10 -0700, snipped-for-privacy@purdue.edu wrote in comp.arch.embedded:

What serial port? On what computer? Under what operating system?

The solution is completely different even on the same computer under different operating systems. The required code for Linux is completely different than that for Windows, on the same box.

Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://c-faq.com/ comp.lang.c++ http://www.parashift.com/c++-faq-lite/alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

If you use e.g. tcl/tk the code is nearly the same.

Michael

Remove the sport from my address to obtain email www.enertex.de - Innovative Systemlösungen der Energie- und Elektrotechnik

9 pin - so this is a PC serial port ? You need to look at the code examples for sending a character, and controlling the handshake lines, via the control register.

The PC sends > +/-9V, and the PLD will not like that, so you need either RS232 buffers, or resistors+transistors, or resistors+clamp diodes, to get the TTL levels needed by the PLD.

One flaw in your control system, is how does the PLD know where it is ? If you miss a clock, or get an extra one, the system skips a cog, and cannot recover (unless this is manually clocked ? ).

So, you probably need 3 control lines. You can use SendChar to reset the PLD, and then control two handshake lines in SW. - add some slowdown, to allow the RS232 drivers time to move. Multiple writes is one simple way, as the IO speeds are relatively constant on PCs ( much more so that a repeat loop in a cache )

If you want more marks, and have a slightly smarter PLD (that can build a monostable timer), you can send as a PWM coded serial stream, and need only one single BIT of the serial port (TXD).

Data is sent this - Bits 0,3,6 contain data, so 3 bytes sends 9 bits. Monostable is set for 1.5 BAUD times, for data sample, Sync timer is set for 1.5 x 3

s 0 1 2 3 4 5 6 7 P S S TXD =====\_/d/=\_/d/=\_/d/=======

Reset can be 00H TXD =====\_________________/====

-jg

hi, writting a C program to control the serial port is not difficult, but the problem is to implement an UART which can deserialize data comming from PC.

so I advice u to use the parallele port so u can send a clock and one bit information.

this is a sample code to control lpt0 (parallele port):

===================================================

#include #include

int data,etat,cont,octet;

int main() { unsigned int lu;

data=0x378; /* for the port lpt0 */ etat=0x379; cont=0x37a;

if(ioperm(data,3,1)) {perror("ioperm"); exit(1);}

octet=0xFF; outb(octet, data);

lu=inb(etat); printf("%X", lu); exit(0); }

If you want to control your device using standard PC serial port, it uses asynchronous characters (one start bit, several data bits and stop bit(s)) at RS-232 voltage levels.

At your receiving end, you first need to convert the RS-232 voltage levels to TTL levels with a suitable buffer.

Then you need an internal bit rate generator, which runs the same bit rate (or preferably on a multiple) of the PC bit rate.

Then you need to detect the beginning of the start bit (the falling edge Mark->Space), delay you internal bit rate clock with 1.5 bit times, and then use the next 8 clock pulses from your internal generator to clock your PLD. The Receiver data goes to the PLD data input. The clock samples the states at the middle of each of the 8 data bits. Then you have to disable the PLD clock, wait for the stop bit to pass, before enabling the start bit detection.

With the internal clock at twice the bit rate and with 8 bit data and one stop bit, a divide by 20 counter should be enough, with the required number of gates to decode the different states. Reset the counter, when the start bit is detected.

What you have know, is basically the receiving section of a UART (Universal Asynchronous Receiver & Transmitter).

---- To activate any combinations of eight LEDs, it would have been easier to start with some old style UART with separate input and output data pins (8xDataIn and 8xDataOut) and just feed the eight DataOut pins via buffers to the LEDs.

Paul

You need to use RTS and DTR as your clock/data lines.

formatting link

Grant Edwards grante Yow! But they went to MARS at around 1953!! visi.com

I suspect a lot of the suggestions will not work since zdicklin indicated that his clock comes from the serial port. How oversample without a clock?

I would use TXD as the clock line.

RTS=data is (de)asserted, and then a character is sent. Next action is when the shift register is empty.

Jim is right in that you may want to know which LED to start with!

Best Regards, Ulf Samuelsson ulf@a-t-m-e-l.com This message is intended to be my own personal view and it may or may not be shared by my employer Atmel Nordic AB

He needs to control two outputs. RTS and DTR are outputs he can control.

Oversampling? My reading of the posting was that just wants to clock data into a shift register.

If you set it up for no parity and sent 0x00 bytes, that would work also.

Grant Edwards grante Yow! I know th'MAMBO!! I at have a TWO-TONE CHEMISTRY visi.com SET!!

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required