没有PWM输出
本帖最后由 ttl_web 于 2016-11-1 16:36 编辑请教以下代码,始终无法看到PWM输出//问题:没PWM输出
//TIM3产生1路PWM
//stm32f103vet6
#include "stm32f10x.h"
void RCC_conf()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
}
void GPIO_conf()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
void TIM3_conf() {
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3,ENABLE);
TIM_TimeBaseStructure.TIM_Period=900-1;
TIM_TimeBaseStructure.TIM_Prescaler=0;
TIM_TimeBaseStructure.TIM_ClockDivision=0;
TIM_TimeBaseStructure.TIM_CounterMode=
TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC1Init(TIM3,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_Cmd(TIM3,ENABLE);
}
int main()
{
//SystemInit();
RCC_conf();
GPIO_conf();
TIM3_conf();
while (1)
{
}
}
有个MOE位不知道LZ用了没?
跟踪一下,看看是不是gpio模式不对 用示波器看看。 签到,好多内容,谢谢! 你都没有给TIM3->CCR1赋值 ,当然没有东西输出了。 jackeyt 发表于 2016-10-31 08:54
你都没有给TIM3->CCR1赋值 ,当然没有东西输出了。
CREN 已使能 //已看到PWM
//TIM3产生1路PWM
//stm32f103vet6
#include "stm32f10x.h"
void RCC_conf()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
}
void GPIO_conf()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
void TIM3_conf() {
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3,ENABLE);
TIM_TimeBaseStructure.TIM_Period=900-1;
TIM_TimeBaseStructure.TIM_Prescaler=0;
TIM_TimeBaseStructure.TIM_ClockDivision=0;
TIM_TimeBaseStructure.TIM_CounterMode=
TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse=100;
TIM_OC1Init(TIM3,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd(TIM3,ENABLE);
}
int main()
{
//SystemInit();
RCC_conf();
GPIO_conf();
TIM3_conf();
while (1)
{
}
}
jackeyt 发表于 2016-10-31 08:54
你都没有给TIM3->CCR1赋值 ,当然没有东西输出了。
谢谢点拨 限流电阻太大了吧,即使有,也看不清楚;
直接短路1K电阻看看,可以直接驱动LED的;
页:
[1]
2