I have a Nucleo board, and want to update the DAC output each time one of the PWM rising edge occurs.
When I configure a PWM using a timer, it auto generates the following interrupt only:
void TIM1_UP_TIM16_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_TIM16_IRQn 0 */
/* USER CODE END TIM1_UP_TIM16_IRQn 0 */
HAL_TIM_IRQHandler(&htim16);
/* USER CODE BEGIN TIM1_UP_TIM16_IRQn 1 */
/* USER CODE END TIM1_UP_TIM16_IRQn 1 */
}
I should add the HAL_DAC_SetValue function to some section so that at each rising edge of the PWM HAL_DAC_SetValue outputs a value. Is there a function or way to do that using HAL library or else?
edit:
1 Answer 1
Normally, when the TIM update event occurs (counter == ARR), TIM counter is reset and output rises to logic high. Signal falls again when counter matches with CCR value. So, your scope observation is confusing, I would expect it to be other way around.
The easiest thing you can try is inverting the output using relevant output polarity bits in TIMx_CCER register, as @Arsenal suggested in the comments.
But a more effective approach would be using DAC automatic triggering and DMA. You can configure your TIM to generate trigger outputs on various events, like update event or CCR match (see MMS bits in TIMx_CR2 register). Then, you can configure your DAC to use this TRGO of your TIM, so that TRGO triggers a DMA transfer and DAC output update. Of course, DMA also needs to be configured. In this case, you don't even need interrupts. Unfortunately, TIM1 doesn't seem to be available for DAC triggering, but most other timers are usable.
HAL_DAC_SetValue
there. Not sure what you are really asking. \$\endgroup\$