-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimerCalc.c
31 lines (27 loc) · 968 Bytes
/
timerCalc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <math.h>
//This script will output certain periods required for a certain frequency (from 1kHz)
int main(void){
double getPeriod;
double timerCounter;
int periodInt;
int r;
printf("Enter the highest frequency (kHz) for 8bit, 1us count microcontroller: ");
scanf("%d", &r);
printf("Period to produce a varied square wave (varied frequency) \n");
//loop
for (int n=0; n < r+1; n++){
if (n == 0){
getPeriod = 0;
printf("Frequency: %dkHz Period: %dus \n", n, getPeriod);
}
else{
getPeriod = (1.0/(n * 1000));
timerCounter = ((getPeriod/2))* 1 * pow(10, 6);
timerCounter = floor(timerCounter);
periodInt = (int)timerCounter; // type cast...
printf("Frequency: %dkHz Period: %dus with float:%.7f \n", n, periodInt, timerCounter);
}
Sleep(1);
}
}