I am using the STM32f7 Nucleo board for one of my projects. I need to make the program wait for the exact duration which is specified by the variable I am using. The waiting time is in terms of nanoseconds so I cannot use HAL_Delay() method.
The Timer frequency is 216 Mhz.I am using TIM3 which is ticking at 1us and TIM2 which is ticking at 1 milisecond.
However, I am not able to achieve the exact waiting time for the program.
while (ptpTimeCompare(configTime, currentTime) >= 0) {
    ptpTime temp;
    temp = ptpTimeDiff(configTime, currentTime);
    configStartWaitingTime = (uint64_t) (ptpTimetoCycleTime(&temp) *
        1000000000.0);
    if (temp.tv_sec > 0) {
        HAL_TIM_Base_Start(&htim2);
        delay_sec(temp.tv_sec * 1000);
        getCurrentTime(Scheduler);
        if (configTime >= currentTime) {
            HAL_TIM_Base_Start(&htim3);
            delay_usec(temp.tv_nsec / 100000);
            getCurrentTime(Scheduler);
        }
        else
            getCurrentTime(qbvScheduler);
    }
}
But, In the end the currentTime is always greater than the configTime.
Is there any way so that both currentTime & configTime are exactly equal so that the execution of the code begins exactly at the configTime ?
both the times are stored in a structure
currentTime{
tv_sec;
tv_nsec
};
Any help in this regard is highly appreciated
Thanks in Advance