本帖最后由 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)
- {
-
- }
- }
复制代码
|
CREN 已使能
谢谢点拨
直接短路1K电阻看看,可以直接驱动LED的;
https://www.stmcu.org.cn/module/forum/thread-608340-1-1.html