2016-05-10 09:52 AM
Hi everyone.
I'M using a STM32F302CB. I'm using many timers in the application. I had a problem that I find a solution with 2 timers, but I don't understand the reason why.Timer configuration:Problem explanation:
When the timer 15 reaches the configured value, it is reset to 0. In cubeMX, the option Master/Slave Mode was at Enable (sync between this TIM (Master) and its slave (trhought TRGO)). At this moment, the timer TIM1 was also reset to 0. The TIM1 Master/slave mode is at disable (no sync...). TRGO and TRGO2 is at reset.Whye timer 1 is resetting?Any help or precision? #no-hablo-hal2016-05-10 10:28 AM
Present the code configuring the interconnection of the timers, I can't muddle through this description.
2016-05-10 12:36 PM
The line that generate this fail is in bold.
For timer 15:void MX_TIM15_Init(void){ TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig; TIM_OC_InitTypeDef sConfigOC; htim15.Instance = TIM15; htim15.Init.Prescaler = 1000; htim15.Init.CounterMode = TIM_COUNTERMODE_UP; htim15.Init.Period = 60; htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim15.Init.RepetitionCounter = 0; HAL_TIM_Base_Init(&htim15); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; HAL_TIM_ConfigClockSource(&htim15, &sClockSourceConfig); HAL_TIM_OC_Init(&htim15); HAL_TIM_OnePulse_Init(&htim15, TIM_OPMODE_SINGLE); sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; // TIM_MASTERSLAVEMODE_ENABLE HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig); sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; 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.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig); sConfigOC.OCMode = TIM_OCMODE_TOGGLE; sConfigOC.Pulse = 10; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_1); sConfigOC.Pulse = 40; HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2);}For timer 1:void MX_TIM1_Init(void){ TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig; TIM_OC_InitTypeDef sConfigOC; htim1.Instance = TIM1; htim1.Init.Prescaler = 0; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 3600; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim1.Init.RepetitionCounter = 0; HAL_TIM_Base_Init(&htim1); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig); 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.OffStateRunMode = TIM_OSSR_DISABLE; sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; sBreakDeadTimeConfig.DeadTime = 50; sBreakDeadTimeConfig.BreakState = TIM_BREAK_ENABLE; sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_LOW; sBreakDeadTimeConfig.BreakFilter = 0; sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE; sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_LOW; sBreakDeadTimeConfig.Break2Filter = 0; sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_ENABLE; HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig); sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 1800; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1); HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2);}
2016-05-13 09:28 AM
Hi,
Someone has specification or explanation? I need to understand.RegardsJF2016-05-13 10:49 AM
It is not obvious to me why it would reset TIM1 either, but it is not something I can spend time on.
I suspect you'll need to decompose the register settings as configured against the reference manual descriptions and see if it is a library issue, or some other quirk. It might take some digging.