完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
贴上代码
#define MOTOR_1_PWM_PIN GPIO_Pin_5 #define MOTOR_1_PWM_GPIO_PORT GPIOB #define MOTOR_1_PWM_PORT_CLK RCC_APB2Periph_GPIOB #define MOTOR_1_PWM_TIM TIM10 #define MOTOR_1_PWM_TIM_CLK RCC_APB2Periph_TIM10 #define MOTOR_1_PWM_TIM_IRQn TIM10_UP_IRQn #define MOTOR_1_PWM_TIM_IRQHandler TIM10_UP_IRQHandler void Motor_1_PWM_TIM_Config( u16 arr, u16 psc, u16 ccp ) { GPIO_InitTypeDef GPIO_InitStructure={0}; TIM_OCInitTypeDef TIM_OCInitStructure={0}; TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0}; NVIC_InitTypeDef NVIC_InitStructure={0}; // 开启定时器时钟和PWM输出引脚时钟 RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE ); RCC_APB2PeriphClockCmd( MOTOR_1_PWM_PORT_CLK | MOTOR_1_PWM_TIM_CLK, ENABLE ); GPIO_PinRemapConfig(GPIO_Remap_TIM10 , ENABLE); GPIO_InitStructure.GPIO_Pin = MOTOR_1_PWM_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init( MOTOR_1_PWM_GPIO_PORT, &GPIO_InitStructure ); // 定时器配置 TIM_TimeBaseInitStructure.TIM_Period = arr; TIM_TimeBaseInitStructure.TIM_Prescaler = psc; TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit( MOTOR_1_PWM_TIM, &TIM_TimeBaseInitStructure); // PWM模式配置 #if (PWM_MODE == PWM_MODE1) TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; #elif (PWM_MODE == PWM_MODE2) TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; #endif // 输出比较参数配置 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = ccp; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC3Init( MOTOR_1_PWM_TIM, &TIM_OCInitStructure ); // PWM输出使能 TIM_CtrlPWMOutputs(MOTOR_1_PWM_TIM, ENABLE ); TIM_OC3PreloadConfig( MOTOR_1_PWM_TIM, TIM_OCPreload_Enable ); TIM_ARRPreloadConfig( MOTOR_1_PWM_TIM, ENABLE ); NVIC_InitStructure.NVIC_IRQChannel = MOTOR_1_PWM_TIM_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); TIM_ITConfig(MOTOR_1_PWM_TIM, TIM_IT_Update, ENABLE); TIM_Cmd( MOTOR_1_PWM_TIM, ENABLE ); } |
|
|
|
只有小组成员才能发言,加入小组>>
456 浏览 1 评论
CH579M+RT-Thread,RTC从Sleep模式唤醒失败是什么原因?
2865 浏览 2 评论
2352 浏览 1 评论
804浏览 2评论
CH569通过HSPI实现USB3.0和FPGA高速双向通讯
629浏览 1评论
490浏览 1评论
CH32F103C8T6使用当前官网上的CDC例程会出现设备描述符请求失败
353浏览 1评论
629浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-20 06:12 , Processed in 0.940040 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号