Click here to Skip to main content
13,096,660 members (98,257 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, I have given a task to make an automotive machine, I'm stuck with the timer
ok, i.e:

When 'Object a' reach 'Station A', 'Station A' need 5 second to make the process,
after 5 second, it will take few second(define by user) before go through another station, <- here I mean refresh timer..

I got the concept on how to make the refresh timer, but I'm just not sure about the timer needed for the machine to do the process.. is that possible for me to use sleep?
1st8bits |= 0x01;
Function(address+0xc0,(unsigned char)first8bits);
Function(address+0xc0,(unsigned char)first8bits);

Sorry for did not use proper English @@


Posted 28-Sep-12 19:52pm
Updated 28-Sep-12 20:07pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You should know that this won't be deterministic, your program will have the priority that the OS will give to it and therefore timers can change slightly their final results.

Apart of that, if you would need to do some parallel tasks during that "timer" or sleep call, you would not be able to do it.

Then things can grow up more difficult...

What typically it is being done in the automotion world when you program a PLC or so, is to establish an infinite while loop.

Those loops take a specific amount of time (typically 10ms).

Then all the code happens there and you are in each cycle checking all the conditions and reacting to them to get the desired result... something like:

while (true)
  if (move_activated)
    // moving something to a specified/given position (without PID or other advanced positioning systems).
    if (position < destination)
      move_neg = false;
      move_pos = true;
    else if (position > destination)
      move_pos = false; 
      move_neg = true;
      move_pos = false;
      move_neg = false;
    // reacting to a given time.
    if (bTimeCount)
      if (previous_bTimeCount = false)
        StartTime = GetTime();
      CurrentTime = GetTime();
      if (CurrentTime - StartTime > DesiredWaitingTime)
        bTimeCount = false;
        // DoWhateverYouWant...
      bPreviousTimeCount = btimeCount;
  /* other conditions should be placed here. */
  sleep(10); //10 ms so you will recheck the condition much faster than the 5 seconds you were speaking about.

That was a small pseudocode snippet that can give you some advice in how to proceed.

See that in case you want to process a time and meanwhile you want to control other things, what is done in the automation world is preparing a base cycle of x millisencods and react to the world conditions with that time base.

Again, you can't trust it to be real each cycle, this is what makes industrial controllers special, they are deterministic.

And let me ask you one question... How do you plan to connect the software to the real world? I mean which will be the interface to the inputs and outputs?

Good luck!
arnoldxx 29-Sep-12 7:30am
i'll use an ipc with an IO Card~
Joan Murt 29-Sep-12 7:57am
Regarding the cycle time it is important to make it as short as possible: you will react to any input from that io card as soon as your software will be able to do it. Imagine that you would make a code fragment which execution time would take longer than the cycle time (those proposed 10ms) then you would have a problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100