小学生
最后登录1970-1-1
在线时间 小时
注册时间2017-12-26
|
本帖最后由 神话破灭 于 2017-12-29 15:40 编辑
请教一下:芯片STM32F103VCT6
我用TIM4_CH4通道产生方波来给步进电机驱动器的PUL+提供信号,在测量PD15脚没有波形输出。(PB9测过,也没有信号)
以下是我配置的代码,请问是哪里出了问题?
- [code]
- main.c文件:
- #include "pbdata.h"
- void RCC_Configuration(void);
- void NVIC_Configuration(void);
- int main(void)
- {
- RCC_Configuration();
- Tim1_PWM_Init();
- NVIC_Configuration();
- KEY_Init();
-
- while(1)
- { }
- }
- void RCC_Configuration(void)
- {
- SystemInit();
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
- }
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- tim_pwm.c文件:
- #include "pbdata.h"
- __IO uint16_t Pulse=500;
- void Tim1_PWM_Init(void)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
-
- //GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE);
- GPIO_PinRemapConfig(GPIO_Remap_TIM4,ENABLE);
-
- TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
- TIM_TimeBaseStructure.TIM_Prescaler =72;
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
-
-
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse = Pulse;
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
- TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
- TIM_OC2Init(TIM4, &TIM_OCInitStructure);
-
- TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Disable);
-
- TIM_ITConfig(TIM4,TIM_IT_CC4,ENABLE);
- TIM_Cmd(TIM4, ENABLE);
- TIM_CtrlPWMOutputs(TIM4, ENABLE);
- }
- tim1_pwm.h文件:
- #ifndef _TIM1_PWM_H
- #define _TIM1_PWM_H
- #include "stm32f10x.h"
- #define PWM_Pin GPIO_Pin_15
- #define PWM_GPIO_Port GPIOD
- extern __IO uint16_t Pulse;
- void Tim1_PWM_Init(void);
- #endif
- stm32f10x_it.c文件中加了TIM4的中断处理:
- void TIM4_IRQHandler(void)
- {
- if(TIM_GetITStatus(TIM4,TIM_IT_CC4)!=RESET)
- {
- TIM_ClearITPendingBit(TIM4,TIM_IT_CC4);
- TIM_SetCounter(TIM4,0);
- TIM_SetCompare4(TIM4,Pulse);
- }
- }
复制代码
[/code]
|
-
|