新手上路
- 积分
- 21
- 金钱
- 21
- 注册时间
- 2016-4-28
- 在线时间
- 3 小时
|
1金钱
根据A盘的例程,我不使用程序的复用功能,而是使用TIM3 通道2在无复用情况下的PA7,引出外电路到面包板上,但是灯不亮,没有产生PWM波。我的目的是,不使用复用功能。直接通过TIM3的CH1->PA6、CH2->PA7、CH3->PB0、CH4->PB1来输出PWM波。不知道程序配置时哪里有问题。
程序如下:
#include "timer.h"
int main(void)
{
TIM3_PWM_Init(899,0); //2»·ÖÆμ¡£PWMÆμÂê=72000000/900=80Khz
while(1)
{
TIM_SetCompare2(TIM3,100);
}
}
#include "timer.h"
void TIM3_PWM_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); //GPIOA
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //TIM_CH2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 更改为推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); //GPIOA.7
TIM_TimeBaseStructure.TIM_Period = arr;
TIM_TimeBaseStructure.TIM_Prescaler =psc;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_Cmd(TIM3, ENABLE);
}
|
|