本帖最后由 yuanliangbeyond 于 2025-6-27 20:47 编辑
APM32F003F6P6芯片, 给PD4引脚, 配置PWM调速, 频率1KHZ, 代码如何配置呢?
- SEGGER_RTT_printf(0, "===========PwmLed_init=========== \r\n");
- TMR1_OCConfig_T ocConfigStruct;
- TMR1_TimeBaseConfig_T timeBaseConfig;
-
- timeBaseConfig.cntMode = TMR1_CNT_MODE_UP; /* Up-counter */
- timeBaseConfig.count = 2; /* Set counter = 500 */
- timeBaseConfig.divider = 48000-1; /* Set divider = 47.So TMR1 clock freq ~= 24M/(47 + 1) = 500KHZ */
- timeBaseConfig.repetitionCount = 0; /* Repetition counter = 0x0 */
- TMR1_ConfigTimerBase(TMR1, &timeBaseConfig);
- //
- ocConfigStruct.channel = TMR1_CHANNEL_2; /* Select channen1 3 */
- ocConfigStruct.count = 48000/(100*100); /* Set compare value = 250 */
- ocConfigStruct.mode = TMR1_OC_MODE_PWM1; /* PWM1 mode */
- ocConfigStruct.OCxIdleState = TMR1_OC_IDLE_RESET; /* Idle State is reset */
- ocConfigStruct.OCxNIdleState = TMR1_OC_IDLE_RESET; /* Idle State is reset */
- ocConfigStruct.OCxNOutputState = TMR1_OC_OUTPUT_DISABLE; /* Disable CH1N ouput */
- ocConfigStruct.OCxOutputState = TMR1_OC_OUTPUT_ENABLE; /* Enable CH1 ouput */
- ocConfigStruct.OCxNPolarity = TMR1_OC_POLARITY_HIGH; /* CH1N polarity is high */
- ocConfigStruct.OCxPolarity = TMR1_OC_POLARITY_HIGH; /* CH1 polarity is high */
- TMR1_ConfigOutputCompare(TMR1, &ocConfigStruct);
- TMR1_EnableOutputPWM(TMR1); /* Enable PWM output */
- TMR1_Enable(TMR1); /* Enable TMR1 */
|