Question
F334 HRTImer reset from TIM2
Posted on January 26, 2015 at 17:09
Hi,
I need to generate a Signal with high resolution but with low frequency (sub 500ps resolution with frequency of 1kHz). My idea was to configure the HRTIMA in one shot mode (non retriggerable) and to use the update event from TIM2 via TRGO to reset HRTIMA. As TIM2 is a 32bit timer I could reach the required frequency on keep all timers running synchronized. HRTIMA runs fine in one shot mode and by software reset it generates the signals one time. So fine so good. But it seems I cannot get TIM2 to reset / update the HR Timer. This is how I initialize the HRTimer:
// from cookbook
static
void
HRTIM_Minimal_Config(
void
)
{
/* Use the PLLx2 clock for HRTIM */
__HAL_RCC_HRTIM1_CONFIG(RCC_HRTIM1CLK_PLLCLK);
/* Enable HRTIM clock*/
__HRTIM1_CLK_ENABLE();
/* DLL calibration: periodic calibration enabled, period set to 14µs */
HRTIM1->sCommonRegs.DLLCR = HRTIM_CALIBRATIONRATE_14| HRTIM_DLLCR_CALEN;
/* Check DLL end of calibration flag */
while
(HRTIM1->sCommonRegs.ISR & HRTIM_IT_DLLRDY == RESET);
}
void
setupHRTimer(
void
)
{
// enbale TimerA in one shot non retriggerable mode with preload enable
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].TIMxCR = HRTIM_TIMCR_PREEN;
// reset on external event channel 2, source 3 -> TIM2_TRGO
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].RSTxR = HRTIM_RSTR_EXTEVNT2;
HRTIM1->sCommonRegs.EECR1 = HRTIM_EECR1_EE2SRC_1;
// set period and compare registers
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].PERxR = 0x0F00;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP1xR = 0x0001;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP2xR = 0x0100;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP1xR = 0x0200;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP2xR = 0x0400;
// set set and reset conditions
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].SETx1R = HRTIM_SET1R_CMP1;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].RSTx1R = HRTIM_RST1R_CMP2;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].SETx2R = HRTIM_SET1R_CMP3;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].RSTx2R = HRTIM_RST1R_CMP4;
/* Enable TA1 and TA2 outputs */
HRTIM1->sCommonRegs.OENR = HRTIM_OENR_TA1OEN + HRTIM_OENR_TA2OEN;
// start master timer and timer A
HRTIM1->sMasterRegs.MCR |= HRTIM_MCR_TACEN + HRTIM_MCR_MCEN
}
And here for TIM2:
void
setupTIM2(
void
)
{
__TIM2_CLK_ENABLE();
TIM2->CR2 |= TIM_CR2_MMS_1;
// use update as TRGO
TIM2->ARR = 72000-1;
// with 72MHz results on overflow every 1kHz
TIM2->PSC = 1;
TIM15->CR1 |= TIM_CR1_CEN;
TIM15->EGR |= TIM_EGR_UG;
// force update
}
I'm relatively new to ARMs and in special to STM32 so I would appreciate any help ;)
Thanks
#hrtim #stm32f334 #nucleo #f334 #hr-timer #hrtim