2020-09-02 06:09 AM
I have successfully set up this timer to output one high pulse with following low state.
However after finishing the period the output toggles to high until next activation.
I need it to be low inbetween activations. How can this be achieved?
I tried all combinations of PWM1 and PWM2 with high and low polarity.
Delay->Pulse is no problem but Pulse->Pause always sets the Idle value wrong.
Solved! Go to Solution.
2020-09-02 08:12 AM
Found one solution myself, please keep me posted if there is a more elegant way:
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
TIM3->CCER &= ~TIM_CCER_CC2P;
TIM3->CR1 |= 0x1;
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM3) {
TIM3->CCER |= TIM_CCER_CC2P;
}
}
I do capture on channel 4 therefore I cannot trigger directly and have to go by interrupts.
Line 4 starts the pulse.
2020-09-02 08:12 AM
Found one solution myself, please keep me posted if there is a more elegant way:
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
TIM3->CCER &= ~TIM_CCER_CC2P;
TIM3->CR1 |= 0x1;
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM3) {
TIM3->CCER |= TIM_CCER_CC2P;
}
}
I do capture on channel 4 therefore I cannot trigger directly and have to go by interrupts.
Line 4 starts the pulse.
2020-09-02 08:19 AM
One way might be to use some of the combined modes, to output high only in the CNT range of 1..CCRx instead of 0..CCRx, if you can tolerate the 1-clock delay.
There might be other solutions; it depends on the particularities of your application (e.g. how exactly do you start the pulse).
JW
2020-09-02 08:23 AM
I do an edge triggered capture on TIM3_CH4 and start the pulse via timer enable on IC_CaptureCallback as seen above.
1 cycle surely poses no problem (at 168 Mhz ;) ) so I will look into combined modes tomorrow, thank you for your answer!
2020-09-02 08:27 AM
Ah, I have to add.
The Pause after the Pulse is needed. During that time no new pulse can be allowed, regardless of new trigger pulses on channel 4.
This is why I went for OnePulse + PWM in the first place.