이것이 내 문제입니다. TM4C123에서 내 PLL 대기를 위해 ms와 us에 얼마나 많은 클럭 사이클이 있는지 계산해야합니다. 그러나 두 배로 값이 제로로 나오므로 내 다른 값이 올바르지 않습니다. 어떤 도움이라도 대단히 감사 할 것입니다. 내가 할두 배의 숫자를 C에 저장하지 않음 (숫자가 너무 작음)
#include <stdio.h>
int main()
{
float ms_cycled;
float us_cycled;
int ms_cycle;
int us_cycle;
unsigned long MHz = 50;
double TPC = 1/(MHz*10000000); //calculate time per clock cycle
//calculate cycles for ms
ms_cycled = 0.001/TPC;
ms_cycle = ms_cycled;
//calculate cycles for us
us_cycled = 0.000001/TPC;
us_cycle = us_cycled;
printf("TPC = %.16f \n", TPC);
printf("ms_cycled = %f \n", ms_cycled);
printf("us_cycled = %f \n", us_cycled);
printf("ms_cycle = %i \n", ms_cycle);
printf("us_cycle = %i \n", us_cycle);
return 0;
}
출력은 다음과 같습니다 당신이 정수를 arithmetics을 사용하고
TPC = 0.0000000000000000
ms_cycled = inf
us_cycled = inf
ms_cycle = -2147483648
us_cycle = -2147483648
이것은 내가 본 시계 중 가장 비효율적 인 방법입니다. 'MHz'를 가지고 있다면 초당 클럭 수를 갖게됩니다. 그리고 ms 당 클록은 1/1000의 단순한 요소입니다. μs 당 클록 수는 1/1000의 인수가됩니다. 'ms_cycle = MHZ * 1000; us_cycle = MHz'. 'TPC '의 값은 10^6 대신 10^7을 사용하여 MHz를 곱하면 10 배만큼 떨어져 있습니다. – Gerhardh