cancel
Showing results for 
Search instead for 
Did you mean: 

G4 MCU in OnePulseMode on TIM3, how to set default (idle) value to low

MKlei.1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
MKlei.1
Associate II

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.

View solution in original post

4 REPLIES 4
MKlei.1
Associate II

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.

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

MKlei.1
Associate II

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!

MKlei.1
Associate II

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.