cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f7discovery

vrba1
Associate
Posted on July 27, 2015 at 19:16

Hello,

I need help with pwm on stm32f7 discovery, have you any examples?

Regards

#stm32f7-discovery-pwm-examples
5 REPLIES 5
Posted on July 27, 2015 at 20:29

Sorry I don't, would suggest you port from the other F7 examples

STM32Cube_FW_F7_V1.1.0\Projects\STM32756G_EVAL\Examples\TIM\TIM_PWMOutput

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
megahercas6
Senior
Posted on July 28, 2015 at 09:14

void TIM_Config(void)
{
TIM_HandleTypeDef htim1;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
TIM_OC_InitTypeDef sConfigOC;
__TIM1_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
htim1.Instance = TIM1;
htim1.Init.Prescaler = 1000;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 60000;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 1;
HAL_TIM_PWM_Init(&htim1);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig);
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
sBreakDeadTimeConfig.DeadTime = 0;
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.BreakFilter = 0;
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
sBreakDeadTimeConfig.Break2Filter = 0;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig);
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 16000;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_SET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_4);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);
}

this is functional code that took long time to make it work. But never try to change CCR register or frequency. But it should work
vrba1
Associate
Posted on July 28, 2015 at 19:09

Thank you, that's what I needed

v

u12011658
Associate
Posted on September 08, 2015 at 11:56

This code is not working for me? On which port is the PWM output? I can't find Port A11 on the discovery board as it is indicated in this code.

I also tried to change the port/timer/channel and don't get any PWM from ports. I'm following the STM32F7 Discovery Manual to set the correct port/timer/channel but don't see anything on the oscilloscope. 

Posted on September 08, 2015 at 14:38

TIM1-CH1 (PA8) on the Arduino header (D5) might require the least changes

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..