cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030F4P6 PWM on PA4 not working

Renato
Associate II

Hi,

I've set up a PWM with TIM14_CH1 on pin PB1, using standard peripherial library and this worked fine (the signal on the output-pin was just as expected).

Now I've tried to move the PWM signal from pin PB1 to PA4, still using TIM14_CH1, but with no success (the pin stays low, no pwm signal at all).

Here is the code is used (:

	// PWM (Tim14)
	//-------------
 
	// GPIOx Clock enable
	RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);
//RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
 
	// GPIOx Pin configure (as alternate function push-pull)
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd =  GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_0);
//GPIO_Init(GPIOA, &GPIO_InitStructure);
//GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_0);
 
	// TIM14 clock enable
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14 , ENABLE);
 
	// calc PWM-Periode (102 kHz)
	PWM_period = (SystemCoreClock / 102000 ) - 1;
 
	// calc PWM-DutyC pulse (50% Dutycycle)
	PWM_DutyC_pulse = ((PWM_period- 1) / 2);
 
	// Time Base configure
	TIM_TimeBaseStructure.TIM_Prescaler = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseStructure.TIM_Period = PWM_period;
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
	TIM_TimeBaseInit(TIM14, &TIM_TimeBaseStructure);
 
	// Timer compare-channel 1 configure (in PWM mode)
	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
	TIM_OCInitStructure.TIM_Pulse = 0;
	TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
	TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
	TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
	TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
	TIM_OC1Init(TIM14, &TIM_OCInitStructure);
 
	// Timer enable
	TIM_Cmd(TIM14, ENABLE);
 
	// Timer PWM output enable
	TIM_CtrlPWMOutputs(TIM14, ENABLE);
 
	// start PWM (set DutyC > 0)
	TIM_SetCompare1(TIM14,  PWM_DutyC_pulse);

1 ACCEPTED SOLUTION

Accepted Solutions

> //GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_0);

Note, that on PA4, TIM14_CH1 is *not* AF0 but AF4.

JW

View solution in original post

2 REPLIES 2

> //GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_0);

Note, that on PA4, TIM14_CH1 is *not* AF0 but AF4.

JW

Renato
Associate II

Thank you very much for the hint.

This solved my Problem and everything is no working as expected. Knowing what was wrong, I now could also find the Information inside the Chip datasheet.

Quite unbelievable that it did not occur to me to check the alternate function when I changed the pin.