Delay time between inputs

This is a discussion on Delay time between inputs within the C Programming forums, part of the General Programming Boards category; Hi I'm new on this forum. I decided to post this after a while searching with no results. I have ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    3

    Delay time between inputs

    Hi I'm new on this forum. I decided to post this after a while searching with no results.
    I have basic knowledge of writing programs in C.
    I can't manage to think of a solution that I want for a C program.
    What I want is something like this, only in correct C language:

    Code:
    if (input_1=TRUE)
    {
    for (input_2=false)
    {count time}
    stop to count time}
    
    output (time between input_1 and input_2)
    What I want is to know the delay time between input_1 and input_2.
    This code is for an external program that is very basic and I don't know if it can handle external headers like ctime() or time().

    thanks in advance.

  2. #2
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    I am sorry but i don't understand what input_1 and input_2 are supposed to be.
    Code:
    for (input_2=false)
    {count time}
    Would that be a ...
    Code:
    while(input_2=false)
    {count time}
    Also, how do you count time? Will the code be a function needing to return something?
    Try to be a bit less confusing.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What is the platform for this?

    Normally, if I were to do something like this, I would use "clock()" to get the starting time for input1, then when input2 gets activated, I'd get the current value of "clock()", subtract the first value of from clock(), and you have the time it took. Then divide by "CLOCKS_PER_SEC" and you get the actual time in seconds.

    But of course that assumes a fairly complete set of standard C library, and some embedded systems (particularly on smaller platforms) do not support all of the standard library functions, in which case you have to use other methods.

    If this doesn't solve your problem, perhaps you could explain a bit more about what you are doing, what the platform is, etc, etc.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    3
    okay, it's a bit confusing for myself as well.

    the platform is company specific, the hardware contains a Motorola MPC5200 processor. I think it only supports basic C-functions. the program I'm programming with is called GAP Programmer but this is only used within my company.

    I'll try to explain it a little better:

    I have a Relay (DO) and a Discrete input (DI). The D.O. is connected to the D.I. When my program send a TRUE to the DO the relay will switch to TRUE. The program will get a feedback from the DI that the relay has actually switched.

    So lets translate to my program:
    DO is the output to my hardware, but this can also be an input for another function in my program. So I called it input_1.
    DI is the input from the hardware that has the function to report that de relay really switched. This input I call input_2.

    In my graphical programmer (internal use only) I have a block that can call a C-function. To this block I can connect multiple inputs and outputs: real, bolean or integer values.

    an example code of the contents of this block:
    Code:
                #include wgos.h 
    
                #include math.h 
    
                FILE=  file1.c
    
                FUNCT = _FUNCT1
    
     
    
                file1.c         _FUNCT1(double Rval1,              ...(num of Real Repeats),
    
                                                 int        Ival1,               ...(num of Int Repeats),
    
                                                 WGBOOLEAN Bval1,   ...(num of Boolean repeats),
    
                                                 float * ROval1,           ...(num of Real Out Repeats),
    
                                                 int *      IOVal1,             ...(num of Int Out Repeats),
    
                                                 WGBOOLEAN *BOval1, ...(num of Boolean Out repeats) )
    
                                     {
    
                                    //your code here
    
                                    //   example
    
                                    if ((Rval1 > 100.0) && (Ival1 > 22) && (Bval1 == TRUE))
    
                                        {
    
                                        *ROval1 = 22.0;
    
                                        *IOval1 = 11;
    
                                        *BOval1 = FALSE;
    
                                        }
    
                                    else
    
                                        {
    
                                        *ROval1 = -22.0;
    
                                        *IOval1 = -11;
    
                                        *BOval1 = TRUE;
    
                                        }
    
                                    }
    What I want to happen is that the C function measures the amount of time between the two inputs to be true. There is a delay in sending the instruction and receiving a feedback, I want to know that delay in time.
    the output can just be a variable that contains a bolean or integer (1=true, 0=false) value. The C-function block can handle this and can output it to my programmer.

    I hope this makes things a bit more clear!

    thanks!
    Last edited by Cabbie; 02-18-2008 at 03:51 AM.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So what is your hardware platform, at least what processor is it and what OS [if any]?

    To measure time you have to be able to get some sort of timing reference. There are several ways to achieve this, but which is the right way depends on the hardware and the requirements for precision. Are you after a precise number in seconds (milli or microseconds perhaps?), a relative measurement comparing multiple models of relays, or something else?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    3
    the proc is an Motorola MPC5200 processor it has a a Real Time clock.
    I want to know the time in milliseconds.
    The relays are on a module containing multiple relays (8) and the DI's are on a module with 16 inputs. The reason for wanting to know the delay is because I'm testing the system with a direct LON-connection vs. a LON-Fiber Optic-LON.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The Real-time clock is probably not precise enough [although it may be], but you should be able to use the clock() function to measure time reasonably well.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. Determine the closest departure time
    By Kyeong in forum C Programming
    Replies: 9
    Last Post: 10-07-2008, 09:06 PM
  3. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 08:56 AM
  4. Time delay function
    By sundeeptuteja in forum C++ Programming
    Replies: 4
    Last Post: 02-10-2003, 05:17 AM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21