初中生
最后登录1970-1-1
在线时间 小时
注册时间2015-4-9
|
想用EXIT按键功能调节PWM的占空比,定时周期为1000,占空比有500,250,但按下按键由500变250时,输出的方波是这样的 ___| ̄|_| ̄|___,并不是我想要的占空比为250的方波
- void TIM3_Mode_Config(int pulse)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
-
- u16 t[] = {500,250};
-
-
- /* Time base configuration */
- TIM_TimeBaseStructure.TIM_Period = 999;
- TIM_TimeBaseStructure.TIM_Prescaler = 0;
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
- /* PWM1 Mode configuration: Channel1 */
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse = t[0];
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OC1Init(TIM3, &TIM_OCInitStructure);
- TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
-
- TIM_ARRPreloadConfig(TIM3, ENABLE);
-
- /* TIM3 enable counter */
- TIM_Cmd(TIM3, ENABLE);
- }
复制代码
- #include "stm32f10x_it.h"
- #include "pwm.h"
- extern TIM_OCInitTypeDef TIM_OCInitStructure;
- extern u16 t[];
- extern void TIM3_Mode_Config(void);
复制代码- void EXTI15_10_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line13) != RESET)
- {
- while(1)
- {
- TIM_OCInitStructure.TIM_Pulse = t[1];
- TIM3_Mode_Config();
- }
-
-
- }
- }
复制代码
- #include "stm32f10x.h"
- #include "pwm.h"
- #include "exit.h"
- int main(void)
- {
- EXTI_PC13_Config();
- TIM3_PWM_Init();
- }
复制代码
|
|