新手入门
- 积分
- 16
- 金钱
- 16
- 注册时间
- 2018-4-27
- 在线时间
- 0 小时
|
楼主 |
发表于 2018-4-27 15:20:09
|
显示全部楼层
这是初始化pwm函数 用了三个信道
void TIM3_PWM_Init(u16 arr,u16 psc)
{
TIM3_Handler.Instance=TIM3; //¶¨ê±Æ÷3
TIM3_Handler.Init.Prescaler=psc; //¶¨ê±Æ÷·ÖÆμ
TIM3_Handler.Init.CounterMode=TIM_COUNTERMODE_UP;//ÏòéϼÆêyÄ£ê½
TIM3_Handler.Init.Period=arr; //×Ô¶ˉÖØ×°ÔØÖμ
TIM3_Handler.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1;
HAL_TIM_PWM_Init(&TIM3_Handler); //3õê¼»ˉPWM
TIM3_CH2Handler.OCMode=TIM_OCMODE_PWM1; //Ä£ê½Ñ¡ÔñWM1
TIM3_CH2Handler.Pulse=0x0000; //éèÖñè½ÏÖμ,′ËÖμóÃà′è·¶¨Õ¼¿Õ±è£¬Ä¬èϱè½ÏÖμÎa×Ô¶ˉÖØ×°ÔØÖμμÄò»°ë,¼′Õ¼¿Õ±èÎa50%
TIM3_CH2Handler.OCPolarity=TIM_OCPOLARITY_LOW; //êä3ö±è½Ï¼«DÔÎaμí
HAL_TIM_PWM_ConfigChannel(&TIM3_Handler,&TIM3_CH2Handler,TIM_CHANNEL_2);//ÅäÖÃTIM3í¨μà2
TIM3_CH1Handler.OCMode=TIM_OCMODE_PWM1; //Ä£ê½ Ñ¡ÔñWM1
TIM3_CH1Handler.Pulse=arr/2; //éèÖñè½ÏÖμ,′ËÖμóÃà′è·¶¨Õ¼¿Õ±è£¬Ä¬èϱè½ÏÖμÎa×Ô¶ˉÖØ×°ÔØÖμμÄò»°ë,¼′Õ¼¿Õ±èÎa50%
TIM3_CH1Handler.OCPolarity=TIM_OCPOLARITY_LOW; //êä3ö±è½Ï¼«DÔÎaμí
HAL_TIM_PWM_ConfigChannel(&TIM3_Handler,&TIM3_CH1Handler,TIM_CHANNEL_1);//ÅäÖÃTIM3í¨μà1
TIM3_CH3Handler.OCMode=TIM_OCMODE_PWM1; //Ä£ê½ Ñ¡ÔñWM1
TIM3_CH3Handler.Pulse=arr/2; //éèÖñè½ÏÖμ,′ËÖμóÃà′è·¶¨Õ¼¿Õ±è£¬Ä¬èϱè½ÏÖμÎa×Ô¶ˉÖØ×°ÔØÖμμÄò»°ë,¼′Õ¼¿Õ±èÎa50%
TIM3_CH3Handler.OCPolarity=TIM_OCPOLARITY_LOW; //êä3ö±è½Ï¼«DÔÎaμí
HAL_TIM_PWM_ConfigChannel(&TIM3_Handler,&TIM3_CH1Handler,TIM_CHANNEL_3);//ÅäÖÃTIM3í¨μà3
HAL_TIM_PWM_Start(&TIM3_Handler,TIM_CHANNEL_2);//¿aÆôWMí¨μà2
HAL_TIM_PWM_Start(&TIM3_Handler,TIM_CHANNEL_1);//¿aÆôWMí¨μà1
HAL_TIM_PWM_Start(&TIM3_Handler,TIM_CHANNEL_3);//¿aÆôpwmí¨μà3
} |
|