2013-11-17 10:37 AM
2014-11-03 03:05 PM
Hello guys,
I seem to have the exact same problem. I have implemented PWM generation for infrared control on STM32F103ZG before, but on a different board. Now (the same CPU but different board) that the IR led is on another pin, it doesn't work. I experience exactly the same. I set the pin to Out_PP and I am able with GPIO SetBits to turn it on, but not have PWM. When I set to AF_PP for PWM, it doesn't work at all. Not only in the PWM generation, but even with GPIO SetBits it doesn't turn on. The funny thing is that the same timer (Timer3_CH2)is mapped to the pin but as jjTronix noted in AF_PP mode it is just dead...Any ideas? Vagelis2014-11-03 04:06 PM
So which pin? PB5 would need a remap for TIM3_CH2, which would require AFIO being clocked/configured.
The STM32F1 series parts have a somewhat inflexible pin mapping/remapping options. Pins like PA15 will also conflict with JTAG pins if that interface is not reconfigured.2014-11-04 04:00 AM
Hello,
Thank you for your immediate response. Yes it actually PB5. AFIO is enalbed and TIM3 is fully remapped. void initializePWM(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct; TIM_OCInitTypeDef TIM_OCInitStruct; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO ,ENABLE); RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3| RCC_APB1Periph_TIM4, ENABLE ); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init( GPIOB, &GPIO_InitStructure ); GPIO_PinRemapConfig( GPIO_FullRemap_TIM3, ENABLE ); // Map TIM3_CH2 //tim3-channel 2 for PWM1 generation TIM_TimeBaseStructInit( &TIM_TimeBaseInitStruct ); TIM_TimeBaseInitStruct.TIM_ClockDivision = 0; TIM_TimeBaseInitStruct.TIM_Period =179; // 0..179 TIM_TimeBaseInitStruct.TIM_Prescaler = 9; //0-9 ->72M/(40K*180) TIM_TimeBaseInit( TIM3, &TIM_TimeBaseInitStruct ); TIM_OCStructInit( &TIM_OCInitStruct ); TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStruct.TIM_Pulse = 135; // 75% duty cycle TIM_OC2Init( TIM3, &TIM_OCInitStruct ); // Channel 2 //timer4 for delay_us function implementation TIM4->PSC = 71; // 1MHz TIM4->CR1 = TIM_CR1_CEN; //DBGMCU->CR = DBGMCU_CR_DBG_TIM4_STOP; }note that the exact same batch of code works in my previous board,with the only difference that it was PC9 and TIM3_ch32014-11-04 05:54 AM
Thank you so much Clive for for concern but I found it!(page 180, reference manual) PB5 needs a partialremap not a full one. PC9(previous board) needed a fullremap so that's why it was working.
Now with the partialremap it works! Thanks anywayVagelis