diff --git a/linux/main.c b/linux/main.c index 6739423..8382b28 100644 --- a/linux/main.c +++ b/linux/main.c @@ -52,14 +52,14 @@ typedef struct float realfreq; } timer_config_t; -bool compute_timer_parameter(timer_config_t *config, int timer_in_clk /*mhz*/, int infreq /*hz*/) +bool compute_timer_parameter(timer_config_t* config, int timer_in_clk /*mhz*/, int infreq /*hz*/) { - float psc_x_arr = timer_in_clk * 1000 /*定时器模块时钟*/ * 1000 / infreq; + float psc_x_arr =(float) timer_in_clk * 1000 /*定时器模块时钟*/ * 1000 / infreq; uint32_t psc = 0; uint32_t arr = 65534; for (; arr > 2; arr--) { - psc = psc_x_arr / arr; + psc =(uint32_t)( psc_x_arr / arr); if (psc >= 1) { uint32_t tmparr = psc_x_arr / psc; @@ -72,7 +72,6 @@ bool compute_timer_parameter(timer_config_t *config, int timer_in_clk /*mhz*/, i return false; if (arr <= 3) return false; //定时器一周期的分辨率太小了 - arr = psc_x_arr / psc; int psc_x_arr_real = arr * psc; @@ -85,58 +84,52 @@ bool compute_timer_parameter(timer_config_t *config, int timer_in_clk /*mhz*/, i config->prescaler = psc; config->realfreq = realfreq; // config->compare = arr / 2; - return false; } -void dumpconfig_info(timer_config_t *config) +void dumpconfig_info(timer_config_t* config) { printf("* freq : %f \n", config->realfreq); printf("* prescaler : %d \n", config->prescaler); printf("* autoreload: %d \n", config->autoreload); } -int main(int argc, char const *argv[]) +int main(int argc, char const* argv[]) { if (argc != 3) { - printf("%s system_clk mhz expect_freq khz\n", argv[0]); + printf("%s timerInClk mhz expect_freq khz\n", argv[0]); return -1; } float expect_freq = 0; - float systemclk = 0; - sscanf(argv[1], "%f", &systemclk); + float timerInClk = 0; + + sscanf(argv[1], "%f", &timerInClk); sscanf(argv[2], "%f", &expect_freq); - printf("systemclk : %f mhz\n", systemclk); - printf("expect freq: %f khz\n", expect_freq); + + printf("******************************************************\n"); + printf("* author: zhaohe *\n"); + printf("* e-mail: h_zhaohe@163.com *\n"); + printf("******************************************************\n"); + printf("*\n"); + printf("* timerInClk : %f mhz\n", timerInClk); + printf("* expect freq: %f khz\n", expect_freq); + printf("*\n"); int32_t infreq = (int32_t)(expect_freq * 1000); - timer_config_t timerconfig_apb1; timer_config_t timerconfig_apb2; - //apb1 - compute_timer_parameter(&timerconfig_apb1, systemclk / 2, infreq); - //apb2 - compute_timer_parameter(&timerconfig_apb2, systemclk, infreq); + compute_timer_parameter(&timerconfig_apb2, timerInClk, infreq); printf("******************************************************\n"); - printf("* APB1: TIM2 TIM3 TIM4 TIM5 TIM6 TIM7 TIM12 TIM13 TIM14\n"); - printf("*\n"); - printf("* timer_module_clk: %f mhz\n", systemclk / 2); - printf("* freq : %f khz\n", timerconfig_apb1.realfreq / 1000.0); - printf("* period : %f ms\n", (1.0 / timerconfig_apb1.realfreq * 1000)); - printf("* prescaler : %d \n", timerconfig_apb1.prescaler); - printf("* autoreload : %d \n", timerconfig_apb1.autoreload); - printf("*\n"); - printf("**\n"); - printf("* APB2: TIM1 TIM8 TIM9 TIM10 TIM11\n"); printf("*\n"); - printf("* timer_module_clk: %f mhz\n", systemclk); + printf("* timer_module_clk: %f mhz\n", timerInClk); printf("* freq : %f khz\n", timerconfig_apb2.realfreq / 1000.0); printf("* period : %f ms\n", (1.0 / timerconfig_apb2.realfreq * 1000)); printf("* prescaler : %d \n", timerconfig_apb2.prescaler); printf("* autoreload : %d \n", timerconfig_apb2.autoreload); - printf("***\n"); + printf("*\n"); + return 0; -} +} \ No newline at end of file diff --git a/release/stm32_pwm_computer.exe b/release/stm32_pwm_computer.exe index 8d0ba48..f90c5f6 100644 Binary files a/release/stm32_pwm_computer.exe and b/release/stm32_pwm_computer.exe differ diff --git a/windows/stm32_pwm_computer.cpp b/windows/stm32_pwm_computer.cpp index 968dbf8..80c94c6 100644 --- a/windows/stm32_pwm_computer.cpp +++ b/windows/stm32_pwm_computer.cpp @@ -56,51 +56,38 @@ int main(int argc, char const* argv[]) { if (argc != 3) { - printf("%s system_clk mhz expect_freq khz\n", argv[0]); + printf("%s timerInClk mhz expect_freq khz\n", argv[0]); return -1; } float expect_freq = 0; - float systemclk = 0; + float timerInClk = 0; - sscanf(argv[1], "%f", &systemclk); + sscanf(argv[1], "%f", &timerInClk); sscanf(argv[2], "%f", &expect_freq); printf("******************************************************\n"); - printf("* author: 赵贺 *\n"); - printf("* e-mail: zhaohe@163.net *\n"); + printf("* author: zhaohe *\n"); + printf("* e-mail: h_zhaohe@163.com *\n"); printf("******************************************************\n"); printf("*\n"); - printf("* systemclk : %f mhz\n", systemclk); + printf("* timerInClk : %f mhz\n", timerInClk); printf("* expect freq: %f khz\n", expect_freq); printf("*\n"); int32_t infreq = (int32_t)(expect_freq * 1000); - timer_config_t timerconfig_apb1; timer_config_t timerconfig_apb2; - //apb1 - compute_timer_parameter(&timerconfig_apb1, systemclk / 2, infreq); - //apb2 - compute_timer_parameter(&timerconfig_apb2, systemclk, infreq); + compute_timer_parameter(&timerconfig_apb2, timerInClk, infreq); printf("******************************************************\n"); - printf("* APB1: TIM2 TIM3 TIM4 TIM5 TIM6 TIM7\n"); - printf("* TIM12 TIM13 TIM14 \n"); printf("*\n"); - printf("* timer_module_clk: %f mhz\n", systemclk / 2); - printf("* freq : %f khz\n", timerconfig_apb1.realfreq / 1000.0); - printf("* period : %f ms\n", (1.0 / timerconfig_apb1.realfreq * 1000)); - printf("* prescaler : %d \n", timerconfig_apb1.prescaler); - printf("* autoreload : %d \n", timerconfig_apb1.autoreload); - printf("*\n"); - printf("* APB2: TIM1 TIM8 TIM9 TIM10 TIM11\n"); - printf("*\n"); - printf("* timer_module_clk: %f mhz\n", systemclk); + printf("* timer_module_clk: %f mhz\n", timerInClk); printf("* freq : %f khz\n", timerconfig_apb2.realfreq / 1000.0); printf("* period : %f ms\n", (1.0 / timerconfig_apb2.realfreq * 1000)); printf("* prescaler : %d \n", timerconfig_apb2.prescaler); printf("* autoreload : %d \n", timerconfig_apb2.autoreload); - printf("******************************************************\n"); + printf("*\n"); + return 0; } \ No newline at end of file