2018-01-21 10:48 PM
hi,
I am using SMT32F103VE, try to use TM1_CH1 ouput PWM at GPIOA_8, it can output correctly in debug mode with J-link, but can't output in normal mode(Power up after flash).
The below is code.
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure);//Motor enable signal
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD , ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure);TIM_Cmd(TIM1, DISABLE);
TIM_TimeBaseStructure.TIM_Period = 1000; TIM_TimeBaseStructure.TIM_Prescaler = 72-1; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_RepetitionCounter=0; TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_Pulse = 0; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM1, &TIM_OCInitStructure) TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM1,ENABLE); TIM_Cmd(TIM1, ENABLE); TIM_CtrlPWMOutputs(TIM1, ENABLE);Best Regards,
Kent
#tim-pwm2018-01-22 12:16 AM
Also I use STM32 ST-link Utility to reflash and SW reset, GPIOA_8 can output PWM signal. But after I re-power up, GPIOA_8 can't output PWM signal, other function work well.
2018-01-23 05:51 PM
I did another trial, short reset# pin to GND.
just rest#pin touch GND for about 1s(maybe), GPIOA_8 can output PWM
Best Regards,
Kent
2018-01-23 07:19 PM
Perhaps it has nothing to do with TIM1/PWM. Make sure BOOT0 is pulled low, and perhaps output info via a USART indicating the code is running.
2018-01-24 02:24 AM
Hi Clive,
Thanks a lot for your reply. Boot0 is pull low. And even disable UART, still can't work.
BTW, for PA8, there are UART1_CK/TM1_CH/MCO, how to select one function of them?
Best Regards,
Kent
2018-01-24 10:10 AM
The F1 has peripheral level remapping, if you have both peripherals enabled you'll need to remap one to a different group/block of pins. Absent a few errata if the other peripherals aren't enabled the one functioning takes ownership of the pins in AF mode.
The Data Sheet and Reference Manual should provide the details for pin groups, and remap options.
It is a 10 year old design, ST has improved the pin level mapping in newer families, and many of us have moved on. Consider if a newer model STM32 would be more suitable for a product designed today.
2018-01-25 03:20 AM
Hi Clive,
You know, I have Tim8 advance timer can output PWM correctly, but Tim1 advance timer can't output PWM correctly? If it is possible use wrong startup file or flash.ld file?
Why do say that, because we didn't procure chip in big spot market, just procure chip in web like ebay. So I doubt if they changer mark on the chip, for example 128k flash change to 256 or 512K for more profit
Best Regards,
Kent
2018-01-25 06:25 AM
I believe TIM1 and TIM8 should be workable. I don't have the time/resources to replicate your scenario and confirm the behaviour on F1 chips.
Make sure the structures are fully initialized, use '={0};' so behaviour is strongly defined.
2018-01-25 10:14 PM
Sorry, what ' use '={0};' ', what is it?
2018-01-26 12:21 AM
I solved the problem, just add 'TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset', but I just tim1_ch1, not use tim1_ch1N. Don't know why?