|
apm32f003 pwm输出,使用ch3,ch4不用重映射,但是使用ch1和ch2需要重映射,需要特别注意,否则ch1和ch无输出
TIM1-ch3 pc3 不需重映射
TIM1-ch4 pc4 不需重映射
TIM1-ch1 pc6 需重映射
TIM1-ch2 pc7 需重映射
- void AFConfig(void)
- {
- FMC_AFRConfig_T AFRConfig;
- /* Set PC6 alternate function = TMR1_CH1 */
- AFRConfig.AFR0 = FMC_OB_AFR_ENABLE;
- AFRConfig.AFR1 = FMC_OB_AFR_DISABLE;
- AFRConfig.AFR3 = FMC_OB_AFR_DISABLE;
- AFRConfig.AFR4 = FMC_OB_AFR_DISABLE;
- AFRConfig.AFR5 = FMC_OB_AFR_DISABLE;
- /* Set PC3 alternate function = TMR1_CH1N */
- AFRConfig.AFR7 = FMC_OB_AFR_ENABLE;
- FMC_Unlock();
- FMC_EraseOptionByte();
- FMC_ConfigOptionByteAFR(&AFRConfig);
- FMC_Lock();
- }
- void TMR1_Init(void)
- {
- TMR1_OCConfig_T ocConfigStruct;
- TMR1_TimeBaseConfig_T timeBaseConfig;
-
- /* Up-counter */
- timeBaseConfig.cntMode = TMR1_CNT_MODE_UP;
- /* Set counter = 500 */
- timeBaseConfig.count = 500;
- /* Set divider = 47.So TMR1 clock freq ~= 24/(47 + 1) = 500KHZ */
- timeBaseConfig.divider = 47;
- /* Repetition counter = 0x0 */
- timeBaseConfig.repetitionCount = 0;
- TMR1_ConfigTimerBase(TMR1, &timeBaseConfig);
- /* Select channen1 3 */
- ocConfigStruct.channel = TMR1_CHANNEL_1;
- /* Set compare value = 250 */
- ocConfigStruct.count = 250;
- /* PWM1 mode */
- ocConfigStruct.mode = TMR1_OC_MODE_PWM1;
- /* Idle State is reset */
- ocConfigStruct.OCxIdleState = TMR1_OC_IDLE_RESET;
- /* Idle State is reset */
- ocConfigStruct.OCxNIdleState = TMR1_OC_IDLE_RESET;
- /* Disable CH1N ouput */
- ocConfigStruct.OCxNOutputState = TMR1_OC_OUTPUT_DISABLE;
- /* Enable CH1 ouput */
- ocConfigStruct.OCxOutputState = TMR1_OC_OUTPUT_ENABLE;
- /* CH1N polarity is high */
- ocConfigStruct.OCxNPolarity = TMR1_OC_POLARITY_HIGH;
- /* CH1 polarity is high */
- ocConfigStruct.OCxPolarity = TMR1_OC_POLARITY_HIGH;
- TMR1_ConfigOutputCompare(TMR1, &ocConfigStruct);
- /* Enable PWM output */
- TMR1_EnableOutputPWM(TMR1);
- /* Enable TMR1 */
- TMR1_Enable(TMR1);
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|