追加更新:频率输出精度提高(添加四舍五入取整)
This commit is contained in:
parent
2cd09e4902
commit
8074b96f75
|
@ -33,14 +33,14 @@ extern "C" {
|
|||
#define freq_operation(FREQ, PULSE) \
|
||||
do \
|
||||
{ \
|
||||
if (FREQ <= 0 || FREQ >= FREQ_SYS || PULSE <= 0 || PULSE >= 100) \
|
||||
if (FREQ <= 0 || FREQ >= FREQ_SYS || PULSE <= 0 || PULSE >= 100) \
|
||||
{ \
|
||||
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_2); \
|
||||
return; \
|
||||
} \
|
||||
int32_t duty = FREQ_SYS / FREQ; \
|
||||
int32_t duty = ( (float32)FREQ_SYS / (float32)FREQ + (float32)0.5 ); \
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, duty *PULSE / 100 - 1); \
|
||||
__HAL_TIM_SET_AUTORELOAD(&htim1, duty -1); \
|
||||
__HAL_TIM_SET_AUTORELOAD(&htim1, duty -1); \
|
||||
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2); \
|
||||
} while (0)
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue