2015-07-15 03:29 AM
Hello,
I have configured only PB0 (TIM1_CH2N) for PWM output, but I can't get any signal from the pin. code looks like this: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO | RCC_APB2Periph_TIM1, ENABLE); gpio_struct.GPIO_Mode = GPIO_Mode_AF_PP; gpio_struct.GPIO_Pin = GPIO_Pin_0; gpio_struct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB,&gpio_struct); GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE); /* timebase setup */ tmr_period = (SystemCoreClock / 25000); TIM_TimeBaseStructure.TIM_Period = tmr_period - 1; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = tmr_period/2; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; /* channel 2*/ TIM_OC2Init(TIM1, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable); /* enable main output */ TIM_CtrlPWMOutputs(TIM1, ENABLE); /* enable timer */ TIM_Cmd(TIM1, ENABLE);Thanks #pwm #timer #stm32f1032015-07-15 08:14 AM
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;2015-07-15 08:39 AM
I already figured your proposal, but even now it does not working.
2015-07-15 08:52 AM
I have found the problem in TIM1 remap, what SHOULD be:
GPIO_PinRemapConfig(GPIO_PartialRemap_TIM1, ENABLE);thanks clive12015-07-15 11:16 PM
I tried put PWM in idle state, so the the:
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;will pull PWM signal to HIGH state.I tried to preset MOE control bit, but it only disables PWM and I can't getpre-programmed HIGH signal on output.Any advice?2015-07-16 05:14 AM
You you try min/max values in CCR2, ie 0% 100%
TIM1->CCR2 = 0; // 0%TIM1->CCR2 = TIM1->ARR + 1; // 100%