data packet definition, data acquisition!

Discussion in 'Embedded Systems and Microcontrollers' started by Eric007, Apr 29, 2012.

  1. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Hi All!

    Assume the following scenario:
    A microcontroller with an ADC (10-bit resolution) is interfaced with 2 sensors: temperature (LM35) and pulse rate (TCRT1000) and a GSM (ublox 100).
    The acquired signals are sent to a sent to PC for display...

    A PC application is being implemented in visual basic 2010 in order to display the above signals (pulse and temperature) through graphical user interface.
    The PC aquires data by direct connection to the gadget through cable (RS232) or ethernet cable (for the gsm that sends data to the internet)

    My problem is the following:
    The software application must be able to decode the received data and consume it (ie, save to database, display real time pulse and temperature,...).

    My concern is what is the required format for the data, ie what should be the format of the sent data packet? And how the packet should be defined? How the software would recognise which data is the temperature and which is the pulse?
    It makes sense that the software should be programmed based on the packet definition, right?

    Hope I expressed myself clearly enough...
    Any algorithms, helps, method?

    Thanks!
     
    Last edited: May 3, 2012
  2. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,361
    You create what ever format you wish.
    Generally, you choose between binary or text. The choice is yours.
    You encode the data however you wish to make your life easy, while ensuring data integrity.
     
  3. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Thanks for your comment...I got the picture but can you please provide a concrete example of for instance how you would do that!? And as you said to make life easy!

    Please I need HELP!
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Another thing to make it more easy. Is that data sent only are sent back to the PC then requested. In a application like yours. With low data rates. This is OK
     
  5. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    i don't understand your comment!

    pardon my ignorance!:(
     
  6. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Can someone explain and send links on how to read the RS232 cable? since data will be sent via this cable...I need to know how this RS232 presents (sorry can't find the exact term).

    Also how to read (and interpret) data from an ethernet cable...?

    Thanks!
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Data is sent one byte at the time. It is nothing more to it. You can send what ever you want on the serial port. If you want to send a data packet. You have to break it down to byte level and then send it. On the receiver side you do the reverse thing and put the packet back
     
  8. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    @t06afre: thanks you starting to bring light to me...
     
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It is also a beginner mistake. To think that data sent by a serial link. Have to be in ASCII format. Inside the byte boundary. You can send every value from 0x00 to 0xff. The important thing is that the data receiver is able to get the information received. A binary protocol. May be preferable then high utilization of the total transmission capacity is needed.
     
    Eric007 likes this.
  10. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,361
    The simplest protocol to implement and debug is one that is based on text transmission.
    Make sure that all data is readable text using the ASCII character set.

    Secondly, it is best to implement a MASTER-SLAVE relationship.
    The PC is the MASTER and it will request data from the SLAVE, your external MCU based data provider.

    Here are my suggestions for a simple communications protocol.

    1) Choose a unique START-OF-COMMAND character. I have chosen $ in the past.
    This character will be the first character in the COMMAND transmitted by the MASTER to the SLAVE.

    2) Choose a unique START-OF-MESSAGE character. I have chosen *.
    This character will be the first character in the MESSAGE transmitted by the SLAVE to the MASTER in response to the COMMAND.

    3) Choose an END-OF-COMMAND and END-OF-MESSAGE character. I have chosen CARRIAGE RETURN (CR), which is 0x0D.
    This character will terminate all commands and messages.

    4) Choose your commands.
    Protocols have a tendency to grow. I would choose a 2-character command set. For example:

    RF - Read Frequency
    RT - Read Temperature

    So when the MASTER requires a temperature reading, send to the SLAVE:

    $RT<CR>

    - a total of four characters.

    The SLAVE will respond with

    *RT1234<CR>

    where 1234 represents the temperature and is a direct temperature reading or in some encoded representation. The number representation you choose can be integers, fixed point or hexadecimal, whichever is more convenient for your application.

    This is a simple example of a communications protocol. This scheme can be enhanced if required by adding error checking.

    You can also add DEVICE ID numbers in order to create a multi-device network of sensors.

    I have installed such networks extensively in factory floors and industrial plants.

    Google MODBUS.
     
    Eric007 likes this.
  11. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Thanks MrChips for this useful comment!
    I'm trying to implement a communication protocol as simple as possible and yours looks like one simple method!

    Let me read it again...
    I'll definitely ask for more clarification in a few minutes!
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You can simple things down with only sending one letter commands to the PIC also. Like sending a T to the PIC will return the temprature. And so on. Which C compiler do you use?
     
  13. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Given that the system has to display signals real time (or approximately), how often the master (PC) has to request for data to the slave?
    I'm thinking of having my system update the data every one second!
    BTW, in the graphical user interface I have design there are two textboxes, one to display 'temperature' and another one for 'pulse' I also have to display the waveform (only for the pulse rate).

    I also have a database to store information...
    Actually the system is a monitoring system for several patients BUT I first restrict my system to monitor only one patient and once the system works perfectly then I will extend it for several patients!

    Can you please provide an algorithm (or something) that implement your above description? (actually 2 algorithms, one for master (PC) and one for slave (mcu)).
    How about the communication channel (RS232)? What's the algorithm to read the port on PC side,...

    @t06afre I'm coding in Visual Basic 2010 (.NET)
    Actually I'm the software developper and there's a another one dealing with the gadget..but I think as a developper I need to understand the whole communication protocol in order to code it. And as you all know coding is not a problem the algoritm is.

    I have to oblige the embedded guy to send data as you will suggest...

    Thanks again!
     
  14. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,361
    "Real time" is a rather fluid term. You have to start putting down some numbers.

    When you say "display the waveform" you have to define what you mean by waveform.
    What is the sample record, that is, what is the length of time to be displayed?
    What is your sampling rate, i.e. how many points per second do you want to record?
    What is the sensor?

    Next you have to look at the maximum data throughput for a given baud rate.

    9600 baud represents 104μs per bit = 1ms per character.
    Four characters from the PC will take 4ms.
    If we estimate 8 characters for the response, that equals 8ms. Total transaction time = 12ms.
    If we include turn around time, total = 20ms. Hence we are looking at 50 data points per second. We can improve on this by increasing the baud rate.

    ------------------
    I normally would have suggested to go with an enhanced protocol since these things tend to grow. Hence I would include a one-character ID ADDRESS and and two-character checksum.

    So here is the full protocol:

    MASTER COMMAND

    <START> <ADDRESS> <2-char COMMAND> <2-char CHECKSUM> <END>

    - total of 7 characters

    SLAVE RESPONSE

    <START> <ADDRESS> <2-char COMMAND> < 4-char DATA> <2-char CHECKSUM> <END>

    - total of 11 characters (may vary depending on DATA)
     
    Last edited: May 1, 2012
    Eric007 likes this.
  15. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Thanks Mrchips for you above comment!
    I will address your questions as soon as I can...but in the meantime, would you like to have a look at the final schematics of the gadget?

    If I understand well your question "what is the sensor?" You mean the type of sensors used! If I'm correct the temperature sensor used is LM35 and pulse sensor is TCRT1000.

    I'll confirm soon with the schematics!

    Thanks!
     
  16. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    MrChips, would you mind writing a piece of code implementing your 'full protocol' even in C?
    I also believe that what you describe is just the format I was asking about...assuming I'm using this one, can you provide an algorithm (so I can understand) then a code from the reading of the port to the use of the data and assigning it to the textboxes (temperature and pulse) to the display of the chart!
    sorry for my poor description...
    here's a code simulation of it but this can't be used as this is just for visual purpose of how the system will actually be working...
     
  17. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Oops sorry I forgot how to put codes....
     
  18. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,361
    remove the / in the first [/CODE].
     
  19. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,361
    Can you OPEN the RS-232 COM port?
    Can you send one character?
     
  20. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    I can't ! I don't know how it works...and don't know to send one character...I was actually tryna read on this but haven't found a good thing I can read on this...you can explain!
     
Loading...