2
#include "target.h"
#include "xcp.h"
#include "LocatedVars.h"
#include "osek.h"


/**
 * This task is activated every 10ms.
 */
long OSTICKDURATION;
TASK( Task10ms )
{
    void XCP_FN_TYPE Xcp_CmdProcessor( void );
    uint32 startTime = GetQueryPerformanceCounter();

    /* Trigger DAQ for the 10ms XCP raster. */
    if( XCPEVENT_DAQ_OVERLOAD & Xcp_DoDaqForEvent_10msRstr() )
    {
        ++numDaqOverload10ms;
    }

    /* Update those variables which are modified every 10ms. */
    counter16 += slope16;

    /* Trigger STIM for the 10ms XCP raster. */
    if( enableBypass10ms )
    {
        if( XCPEVENT_MISSING_DTO & Xcp_DoStimForEvent_10msRstr() )
        {
            ++numMissingDto10ms;
        }
    }



    duration10ms = (uint32)( ( GetQueryPerformanceCounter() - startTime ) / STOPWATCH_TICKS_PER_US );
}

What would be the easiest (and/or best) way to synchronise to some accurate clock to call a function at a specific time interval, with little jitter during normal circumstances, from C++? I am working on WINDOWS operating system now. The above code is for RTAS OSEK but I want to call a function at a specific time interval for windows operating system. Could anyone assist me in c++ language ??

rahul jv
  • 19
  • 1
  • 3
  • Welcome to SO, you may consider changing your question since the words [High Precision Event Timer](http://en.wikipedia.org/wiki/High_Precision_Event_Timer) are used for a certain hardware timer configuration. – Arno Oct 28 '13 at 16:56

2 Answers2

2

New applications should use CreateTimerQueueTimer!

Timers in this queue, known as timer-queue timers, are lightweight objects that enable you to specify a callback function to be called when the specified due time arrives. The wait operation is performed by a thread in the thread pool.

CreateTimerQueueTimer function. Example: Using Timer Queues (C++).

However, the granularity is about 1ms, a setup of 10 ms may cause periodic hiccups at 9/11 ms.

For higher resolution you may have to setup a timer wheel using Clock::now() as described here.

Community
  • 1
  • 1
Arno
  • 4,994
  • 3
  • 39
  • 63
  • what you say for the high precision equipment timer ?? – rahul jv Oct 29 '13 at 07:45
  • oups, what's a high precision equipment timer? – Arno Oct 29 '13 at 15:20
  • On windows10 and when using accurate profiler (Nvidia NSight markers), even when stating time to 1ms, the actual results are much bigger latency. if you need to run something every 1ms, this is definitely not the API for the job. Only some busy-wait loop with sampling on chrono high resolution timer, but that's gonna hog your CPU time.. – IdanB Oct 27 '21 at 11:01
1

The timeSetEvent API will give you the best stability available, and it can go down to as low as 1 millisecond intervals.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15