[HardwareTimer] one pulse mode

Working libraries, libraries being ported and related hardware
Post Reply
Patrick
Posts: 22
Joined: Thu Dec 19, 2019 9:50 am
Answers: 2

[HardwareTimer] one pulse mode

Post by Patrick »

I want to port some code from core 1.6.1 to 1.9.0 and use HardwareTimer.
I used one pulse mode:

Code: Select all

	// Initialize Timer 6
	// - enable TIM6 clock
	// - set prescaler for 1 µs resolution
	// - one pulse mode
	// - force update
#if STM32_CORE_VERSION < 0x01070000
	RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
	TIM6->PSC = (uint32_t)(getTimerClkFreq(TIM6) / (1000000)) - 1;
	TIM6->CR1 |= TIM_CR1_OPM;
	// Clear the update flag
	TIM6->SR = ~TIM_SR_UIF;
	// Enable interrupt on update event
	TIM6->DIER |= TIM_DIER_UIE;
	 // Enable TIM6 IRQ handler
	HAL_NVIC_SetPriority(TIM6_IRQn, 0, 0);
	HAL_NVIC_EnableIRQ(TIM6_IRQn);
#else
	 // Enable TIM6 IRQ handler
	readTimer->setInterruptPriority(0, 0);
	readTimer->setPreloadEnable(true);
	readTimer->attachInterrupt(readIRQHandler);
#endif
This seems to work but I changed the way I set the timer value:

Code: Select all

#if STM32_CORE_VERSION < 0x01070000
	TIM6->ARR = 127 * worker.period - 1;
	TIM6->CR1 |= TIM_CR1_CEN;
#else
	readTimer->setOverflow(127 * worker.period, MICROSEC_FORMAT);
	readTimer->resume();
#endif
And the IRQ handler:

Code: Select all

#if STM32_CORE_VERSION < 0x01070000
extern "C" void TIM6_IRQHandler() {
	// One pulse
	TIM6->SR = ~TIM_SR_UIF;
	lep_output();
}
#else
void readIRQHandler(void) {
	readTimer->pause();
	lep_output();
}
#endif
I will be more comfortable with one pulse mode.
Is there a way to achieve this with current HardwareTimer an if no, is it possible to add it in a future release?
ABOSTM
Posts: 60
Joined: Wed Jan 08, 2020 8:40 am
Answers: 7

Re: [HardwareTimer] one pulse mode

Post by ABOSTM »

Hi @Patrick,
Current implementation of HardwareTimer does not support OnePulse mode. And there is no plan to do it.
Any contribution is welcome ;)

But it is still possible to use STM32 HAL API (which are usable directly within Arduino sketch) to use OnePulse mode.
Post Reply

Return to “Libraries & Hardware”