2024-03-19 03:42 PM - edited 2024-03-19 04:07 PM
Hi,
I'm working with a STM32F439 and I set both timers, timer3 & timer4 to produce a 460ns pulse at a 50Hz frequency with their PWM feature. Now I need to be able to control their offset to each other with the ability to set it to 0. But it appears like the lowest offsety I can achieve is 1.23us. I've reimplemented the Start function like this:
HAL_StatusTypeDef HAL_TIM_PWM_Start_custom(TIM_HandleTypeDef *htim, uint32_t Channel)
{
uint32_t tmpsmcr;
/* Check the parameters */
assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
/* Check the TIM channel state */
if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
{
return HAL_ERROR;
}
/* Set the TIM channel state */
TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
/* Enable the Capture compare channel */
TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
{
/* Enable the main output */
__HAL_TIM_MOE_ENABLE(htim);
}
/* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
{
tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
{
//__HAL_TIM_ENABLE(htim);
}
}
else
{
//__HAL_TIM_ENABLE(htim);
}
note the commented out __HAL_TIM_ENABLE(htim); lines. I call this on both etuimers and then, to enable them, I do:
__disable_irq();
__HAL_TIM_ENABLE(&htim3);
__HAL_TIM_ENABLE(&htim4);
__enable_irq();
which gives me an offset of 708ns. How can I further improve this?
Thanks!
Solved! Go to Solution.
2024-03-19 07:49 PM
Three options
2024-03-19 07:49 PM
Three options