void TIM3_PWM_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStruct;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3,ENABLE);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
TIM_TimeBaseInitStruct.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_Period=arr;
TIM_TimeBaseInitStruct.TIM_Prescaler=psc;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct);
TIM_OCInitStruct.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStruct.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_OCNPolarity=TIM_OCPolarity_High;
//TIM_OCInitStruct.TIM_Pulse=0;
TIM_OC1Init(TIM3,&TIM_OCInitStruct);
TIM_OC2Init(TIM3,&TIM_OCInitStruct);
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_Cmd(TIM3,ENABLE);
}
#include"stm32f10x.h"
#include"PWM.h"
#include"delay.h"
int main(void)
{
TIM3_PWM_Init(19999,71);
//TIM3_Init(1999,7199);
while(1)
{
TIM_SetCompare1(TIM3,500);
delay_ms(1000);
TIM_SetCompare1(TIM3,1500);
delay_ms(1000);
TIM_SetCompare2(TIM3,500);
delay_ms(1000);
TIM_SetCompare2(TIM3,1500);
delay_ms(1000);
}
}
友友们,你们用这串代码能输出pwm吗?反正我不管怎么改参数和模式,仿真一直都是低的qwq