element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Forum [PC FPGA interface via RS-232 ]how to fit data to my component ?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 9 replies
  • Subscribers 558 subscribers
  • Views 1524 views
  • Users 0 members are here
  • fpga
  • uart
  • rs232
Related

[PC FPGA interface via RS-232 ]how to fit data to my component ?

Former Member
Former Member over 13 years ago

hello,

i'm sending data to FPGA from a labview interface via RS 232 , my FPGA get data and then send it to many component in the circuit ,

there is a UART in the fpga my question is , what is the best method to get the data from this UART  ? I'm confusing between using a finite state machine (detect first byte that it well be the address, and  put the the byte that come after in the specified component, here the problem i'm afraid that i can learn data byte as an address byte ! ) or put data into ROM ( also with detecting the first byte and put )

thanks

  • Sign in to reply
  • Cancel
Parents
  • michaelkellett
    michaelkellett over 13 years ago

    Hello Hachani,

     

    You need to develop a serial protocol suitable for your application.

     

    If all your messages to the FPGA take the form of an address and a register to modify you could consider:

     

    word 1     address

    word 2     data

    word 3     checksum

     

    and separate the messages by an intermessage timeout.

     

    This can be  quite reliable:

    if the time since the last word was received exceeds some limit (typically 10-100mS) the receiving state machine resets. As each of the three words is received it is put into a buffer, when all three are received the FPGA checks the checksum against the other two words and copies the data to the right place if it's good. Finally the state machine resets and waits for the next message.

     

    Of course you can expand this protocol for multibyte addresses or data or both.

     

    Michael Kellett

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to michaelkellett

    Hello Michel

     

    Thanks for your answer , it's very good idea to define my own protocol , my longest control data has a size of 32byte , so my protocol will be a frame of 33 bytes : 1 byte (address) + 32 byte data , still i have some questions:

    Since the communication is wired (length wire about 30cm maximum ), do yo think i can do this protocol without checksum ?

    also another question , i'm receiving data from the UART in 8 bit each time , so do you think the best solution for my protocol is to count 33 bytes and then fit data the correspondent component ?

    thanks.

     

    Ahmed Hachani

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • michaelkellett
    michaelkellett over 13 years ago in reply to Former Member

    Hello Hachani,

     

    You can almost certainly do without a checksum from a data transmission point of view but it makes it hard for a very simple protocol to be sure that it has the complete message and nothing else.

    It may be a problem for you to buffer a complete 34 byte message in the FPGA so as an alternative you could consider sending 32 separate three byte messages (nice and simple if speed is not the primary concern).

    Another (more complicated) approach is to use two extra connections from FPGA to processor for handshake (perhaps not too easy from Labview on a PC).

     

    If you are using the inter message gap time to separate messages I think you should have a checksum - otherwise a delay in sending  a byte of data by the PC will confuse the FPGA into thinking it has a new message start.

     

    It makes for  a much more robust system if the FPGA acknowledges receipt of messages by sending back some data to indicate if the message was received and acted upon.

     

    Michael Kellett

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • michaelkellett
    michaelkellett over 13 years ago in reply to Former Member

    Hello Hachani,

     

    You can almost certainly do without a checksum from a data transmission point of view but it makes it hard for a very simple protocol to be sure that it has the complete message and nothing else.

    It may be a problem for you to buffer a complete 34 byte message in the FPGA so as an alternative you could consider sending 32 separate three byte messages (nice and simple if speed is not the primary concern).

    Another (more complicated) approach is to use two extra connections from FPGA to processor for handshake (perhaps not too easy from Labview on a PC).

     

    If you are using the inter message gap time to separate messages I think you should have a checksum - otherwise a delay in sending  a byte of data by the PC will confuse the FPGA into thinking it has a new message start.

     

    It makes for  a much more robust system if the FPGA acknowledges receipt of messages by sending back some data to indicate if the message was received and acted upon.

     

    Michael Kellett

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • Former Member
    Former Member over 13 years ago in reply to michaelkellett

    Hello Michel;

    thanks for your detailed answer, still i need more clarification

    You can almost certainly do without a checksum from a data transmission point of view but it makes it hard for a very simple protocol to be sure that it has the complete message and nothing else.

       withou checksum, i can do some hardware testing in this case, for example , if i will send data to a DAC i will just check the analog level with an oscilloscope, is it sufficient like this ?

     

    It may be a problem for you to buffer a complete 34 byte message in the FPGA

     

    i don't see really where is the problem ! do you mean that the problem in buffering 34 byte consume lot of spce into the FPGA ?

     

    as an alternative you could consider sending 32 separate three byte messages (nice and simple if speed is not the primary concern).

     

    the idea now is to write a finite state machine detect the first byte sent , and then (if i want to do serially as you suggest) i will  demultplexe the dat that came just after address byte, but even in this case i need to buffer the hole frame !!

     

    If you are using the inter message gap time to separate messages I think you should have a checksum - otherwise a delay in sending  a byte of data by the PC will confuse the FPGA into thinking it has a new message start.

    for the UART IP there's a signal (RXRDY) that indicate when we have  a new data (8 bit), for the  FPGA confusing part , between tow message (i mean by message a frame of 32 byte)this why i thought about making a counter that count 32 byte (by monitoring the RXDY signal )and buffering them, by this method i'm sure that there is no confusion between message

     

    Thanks

     

    Ahmed Hachani

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • michaelkellett
    michaelkellett over 13 years ago in reply to Former Member

    Hello Hachani,

     

    I'm assuming that you are doing this work because either you want to learn good practice or because you need to make a device that works. In either case you should try to design a robust communication between the PC and LabView and your FPGA. (I'm guessing that the LabView is running on a PC.)

     

    In any multiple word serial communication protocol there is an issue with framing (a data frame is a group of words) - how does the receiver know that it has exactly one frame of data. It is essential that it should know because the meaning of the data words is dependent on their position in the frame. It is highly desireable that the transmitter should know when messages have been correctly received.

     

    You can use hardware handshake lines or timing or a combination of the two to define frames. I shan't prove it here but you need at least three handshake lines to fully define and control the transmission and reception of frames without using timing. These control lines are not generally available/controllable in a useful way from a PC serial port so it's easier to use a timing defined frame.

     

    We specify a maximum inter-word time (Tw) so we know that if Tw seconds have passed since a word was received then the next word will be the start of  a new frame. If we can identify the end of a frame from its content or length we may know that the next word is the start of  a frame without waiting for Tw.

     

    Now all you LabView must do is send messages where the inter-word time is less than Tw. If you don't check that the FPGA received the message you must wait at least Tw before sending another frame - this can be rather slow.

     

    If the frame contains  a checksum the receiver has a way of detecting errors - this is not essential but will very often be useful. If the data link is not 100% reliable the checksum will help in operation but it is also very useful in development because it tends to make bugs much more visible.

     

    The amount of data in each message depends on the application - if you can support a buffer of 34 bytes it may make sense to use one message for all the data.

     

    In order to debug your device reliably you should provide a means of reading data out of the FPGA - checking data with a scope is OK for a quick look but can't be automated and will not easily spot a 1 bit error in an 8 bit word.

     

    If I were designing your interface I would use messages containing 3 words, command, data, checksum and the FPGA would reply with 3 words command, data, checksum.

    The LabView would issue commands and for every command it would get a reply.

    You would need commands for:

    set address

    write data

    read data

    The reply echos the command so that the controller knows if it is the reply to the command it expected. It is a good idea to set one bit in the command echo that is never set by a command so that the two can't be mixed up.

     

    It would be reasonable to arrange that write and read data operations incremented the address pointer so that you would need to send only one address command to read all the data.

    The advantages of this protocol are that it is simple, uses few FPGA resources, is self checking, is testable and is expandable.

     

    Have fun !

     

    Michael Kellett

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • pjclarke
    pjclarke over 13 years ago in reply to michaelkellett

    I would consider using the PicoBlaze (FREE Xilinx 8bit soft core) that is only 96 slices. This you could use to process your incomming data stream and then though its I/O ports pass the data out to other sub units.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • michaelkellett
    michaelkellett over 13 years ago in reply to pjclarke

    @Paul,

     

    PicoBlaze is only available on Xilinx FPGAs. Hachani still has exactly the same issues re. serial protocol if he uses an embedded soft processor or RTL level coding using VHDL, Verilog or whatever.

     

    But since you mention it  - how good are the debugging/development tools for PicoBlaze - can you co-simulate PicoBlaze code with VHDL fabric or does it all have to be done at RTL level ?

     

    Michael Kellett

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • pjclarke
    pjclarke over 13 years ago in reply to michaelkellett

    Depends on chip as compiler can be a issue with older ones. However there are great little tools like OpenPICIDE that you can simulate code before generating the .v or .vhdl prom image. This is normally enough to get it working in the fabric. Well the code I've written, if it simulates, it runs.

     

    I've seen, but not used C complies for the PicoBlaze but not convinced they would really help as its such a tiny device ASM is easy to use on it.

     

    True simulation debugging would have to be at RTL - PicoBlaze wraps up into a single component so can be looked at as a black box.

     

    I've read that people that changed the entity to bring out things like PC and other internals.

     

    You get what you pay for.

     

    Was just thinking it may be a good option as a FSM is going to get big quickly and is working with what is really a very slow interface (Serial) and a soft core would be better.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to michaelkellett

    Hello Michael and Paul,

     

    @Michael

     

    Thanks a lot for your precious advice

     

    I'm assuming that you are doing this work because either you want to learn good practice or because you need to make a device that works.

    Actually ,it's for both of them, and as you say i want to make a robust communication for my system,

     

     

    The amount of data in each message depends on the application - if you can support a buffer of 34 bytes it may make sense to use one message for all the data.

     

    yes i have enough space for buffering 34 bytes, even more, my plan is to buffer those each 34 byte into an array of Nx34Byte and all my devices , well get their value from this array, example ' i have 8 DAC to control  each dac require 1 DATA byte, so each input of any of those  DAC well be connected directly to his allocated space memory in this array

     

    In any multiple word serial communication protocol there is an issue with framing (a data frame is a group of words) - how does the receiver know that it has exactly one frame of data. It is essential that it should know because the meaning of the data words is dependent on their position in the frame. It is highly desireable that the transmitter should know when messages have been correctly received

     

    You can use hardware handshake lines or timing or a combination of the two to define frames. I shan't prove it here but you need at least three handshake lines to fully define and control the transmission and reception of frames without using timing. These control lines are not generally available/controllable in a useful way from a PC serial port so it's easier to use a timing defined frame.

     

    We specify a maximum inter-word time (Tw) so we know that if Tw seconds have passed since a word was received then the next word will be the start of  a new frame. If we can identify the end of a frame from its content or length we may know that the next word is the start of  a frame without waiting for Tw.

     

     

    it's a good idea to use inter-word time (Tw) , however , there's a signal into the UART (RxRdy) that indicate when he receive a new DATA , it's easy to use this signal rather than the (Tw) or handshaking

     

    otherwise, my question is in this part

    If I were designing your interface I would use messages containing 3 words, command, data, checksum and the FPGA would reply with 3 words command, data, checksum.

    The LabView would issue commands and for every command it would get a reply.

    You would need commands for:

    set address

    write data

    read data

    The reply echos the command so that the controller knows if it is the reply to the command it expected. It is a good idea to set one bit in the command echo that is never set by a command so that the two can't be mixed up.

     

    It would be reasonable to arrange that write and read data operations incremented the address pointer so that you would need to send only one address command to read all the data.

    The advantages of this protocol are that it is simple, uses few FPGA resources, is self checking, is testable and is expandable.

     

    this part is not very clear for me, i really want to omit the checksum part beacause, as i found checksume is usually used for wireless communication , in my case i'm using a wire of 30cm, so i'm 95% sure that this link is working correctly ,in the add in case i will use checksum, in the level of the Labview interface (runing on a PC) i'm dividing my interface in manyblock , like one block for 8 DAC other block for other component , and i'm sending information of each block separately (this one reason why my frame is too long) , then when i'm sure that i fit all my data, i just send click start to activate my system, in case using cheksum, i have to wait for each block after sending a message from the FPGA to know the statue of my frame ?

     

    Also, i like the protocol that you suggest, still, i have a component that required 256bit to be programmed , in your protocol data is a word (i think it's 8bit) it will be i think it's complicated next to gather the 256 bit from an bit word (because i put a unique address for 256 bit  here )

     

     

    Now i'm trying to send a frame to control tow DAC, i'm sending three bytes [@+ data_dac1+data_dac2] , although , my simulation for the code is working correctly , i don't get my data yet in the DACs, still working on it.

     

    @Paul:

    thank's for your suggestion i will take it in consideration ,  the FPGA that i'm using is IGLOO from Actel.

     

    Thanks

     

    Ahmed Hachani

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube