문서의 이전 판입니다!


프로그램 딜레이 발생

증상

  • Application 의 변경 없이 프로그램이 느려지거나 타이밍 문제 발생
  • Serial이 통신의 비정상 동작
  • 동일 사양의 양산 설비에서 설비에 따라 증상이 나오거나 나오지 않음


발생 시점

  • PC 교체 후
  • Windows 재설치 및 버전 변경 후

원인

  • Windows의 Timer Resolution이 기본값으로 설정되어 있음
  • Windows의 Timer 는 15.625ms 의 Resolution을 기본값으로 가지며,
  • 이 경우, 1ms Sleep 명령에도 15ms 또는 16ms 의 Sleep을 가짐
  • Sleep Time이 길어짐에 따라 상기 문제 발생
  • Visual Studio 등의 프로그램 설치에 따라 Timer Resolution이 1ms로 바뀔 수 있음

Soultion (C++)


// timeBeginPeriod 사용
// 1ms 까지 설정가능
// 0.5ms Resolution 필요 시 NtSetTimerResolution 사용

#define TARGET_RESOLUTION 1         // 1-millisecond target resolution

TIMECAPS tc;
UINT     wTimerRes;

if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) 
{
   // Error; application can't continue.
}

wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);
timeBeginPeriod(wTimerRes); 

//       do your stuff here at approx. 1 ms timer resolution
timeEndPeriod(wTimerRes);