|
stm32f205 PWM,搞不定啊,跪求!!!
[复制链接]
设置PWM的代码 在stm32103系列中可以使用 没有TIME_Init这一说 波形可以实现输出。
到了stm322xx波形不能输出 代码和这个类似 我不知道怎么去设置TIM_Init ,下面是放在一个platform.c中的代码:
void OUTGPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
OUTGPIO_CLK_INIT(OUTGPIO_CLK, ENABLE);
GPIO_InitStructure.GPIO_Pin = OUTGPIO_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(OUTGPIO_PORT, &GPIO_InitStructure);
}
void TIM_Config(uint16_t Channel2Pulse)//, uint16_t Channel3Pulse
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/* TIM4 clock enable */
TIME4_CLK_INIT(TIME4_CLK, ENABLE);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 999; //1KHz
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
//TIM2Ô¤·ÖÆμéèÖÃ:1MHZ,APB1·ÖÆμÏμêy2£¬êäèëμ½TIM3ê±ÖóÎa36MHzx2 = 72MHz
TIM_PrescalerConfig(TIM4,50, TIM_PSCReloadMode_Immediate);
/* Channel 2 and 3 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = Channel2Pulse;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC2Init(TIM4, &TIM_OCInitStructure);
// TIM_OCInitStructure.TIM_Pulse = Channel3Pulse;
// TIM_OC3Init(TIM2, &TIM_OCInitStructure);
//ê1ÄüTIM2¶¨ê±¼ÆêyÆ÷
TIM_Cmd(TIM4, ENABLE);
//ê1ÄüTIM2 PWMêä3öÄ£ê½
TIM_CtrlPWMOutputs(TIM4, ENABLE);
printf("maoxian\n");
}
|
|