使用STM32C8T6怎么用输出两路独立的PWM啊,配置如下,是不是我的配置有问题啊。
void tim2_config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
tim2_nvic_config();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TIM_DeInit(TIM2);
TIM_TimeBaseInitStruct.TIM_Prescaler = 36-1;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_Period = 10-1;
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStruct); //初始化TIM2配置
TIM_ClearFlag(TIM2,TIM_FLAG_Update); //清除溢出中断标志
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM2,ENABLE); //开启时钟
}
void tim3_config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
tim3_nvic_config();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseInitStruct.TIM_Prescaler = 36-1;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_Period = 10-1;
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStruct); //初始化TIM2配置
TIM_ClearFlag(TIM3,TIM_FLAG_Update); //清除溢出中断标志
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM3,ENABLE); //开启时钟
}
void tim2_nvic_config(void)
{
NVIC_InitTypeDef NVIC_Init_Struct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_Init_Struct.NVIC_IRQChannel = TIM2_IRQn;
NVIC_Init_Struct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_Init_Struct.NVIC_IRQChannelSubPriority = 0;
NVIC_Init_Struct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_Init_Struct);
}
//TIM3___PWM2设置
void tim3_nvic_config(void)
{
NVIC_InitTypeDef NVIC_Init_Struct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_Init_Struct.NVIC_IRQChannel = TIM3_IRQn;
NVIC_Init_Struct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_Init_Struct.NVIC_IRQChannelSubPriority = 0;
NVIC_Init_Struct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_Init_Struct);
}
void TIM2_IRQHandler(void)
{
if(TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
pwm1_fq ++;
if(pwm1_fq < pwm1_high)
{
GPIO_SetBits (GPIOA, GPIO_Pin_0);
}
else if(pwm1_fq < 100)
{
GPIO_ResetBits (GPIOA, GPIO_Pin_0);
}
else
{
pwm1_fq = 0;
//led_breath.high_breath_counter ++;
}
}
TIM_ClearITPendingBit(TIM2,TIM_FLAG_Update);
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
pwm2_fq ++;
if(pwm2_fq < pwm2_high)
{
GPIO_SetBits (GPIOA, GPIO_Pin_1);
}
else if(pwm2_fq < 100)
{
GPIO_ResetBits (GPIOA, GPIO_Pin_1);
}
else
{
pwm2_fq = 0;
}
}
TIM_ClearITPendingBit(TIM3,TIM_FLAG_Update);
}
void set_pwm2_high(u8 high_tm)
{
pwm2_high = high_tm;
}
void set_pwm1_high(u8 high_tm)
{
pwm1_high = high_tm;
}
|