AnsweredAssumed Answered

F334 HRTImer reset from TIM2

Question asked by theFloe on Jan 26, 2015
Latest reply on Feb 2, 2015 by theFloe
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:
01.// from cookbook
02.static void HRTIM_Minimal_Config(void)
03.{
04. 
05.  /* Use the PLLx2 clock for HRTIM */
06.  __HAL_RCC_HRTIM1_CONFIG(RCC_HRTIM1CLK_PLLCLK);
07. 
08.  /* Enable HRTIM clock*/
09.  __HRTIM1_CLK_ENABLE();
10. 
11.  /* DLL calibration: periodic calibration enabled, period set to 14µs */
12.  HRTIM1->sCommonRegs.DLLCR = HRTIM_CALIBRATIONRATE_14| HRTIM_DLLCR_CALEN;
13.     
14.  /* Check DLL end of calibration flag */
15.  while(HRTIM1->sCommonRegs.ISR & HRTIM_IT_DLLRDY == RESET);
16. 
17.}
18. 
19.void setupHRTimer(void)
20.{
21.    // enbale TimerA in one shot non retriggerable mode with preload enable
22.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].TIMxCR = HRTIM_TIMCR_PREEN;
23.     
24.    // reset on external event channel 2, source 3 -> TIM2_TRGO
25.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].RSTxR = HRTIM_RSTR_EXTEVNT2;   
26.    HRTIM1->sCommonRegs.EECR1 = HRTIM_EECR1_EE2SRC_1;
27.          
28.     
29.    // set period and compare registers
30.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].PERxR = 0x0F00;
31.     
32.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP1xR = 0x0001;   
33.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP2xR = 0x0100;   
34.     
35.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP1xR = 0x0200;   
36.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP2xR = 0x0400;
37. 
38.    // set set and reset conditions
39.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].SETx1R = HRTIM_SET1R_CMP1;
40.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].RSTx1R = HRTIM_RST1R_CMP2;
41. 
42.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].SETx2R = HRTIM_SET1R_CMP3;
43.    HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].RSTx2R = HRTIM_RST1R_CMP4;
44.     
45.    /* Enable TA1 and TA2 outputs */
46.    HRTIM1->sCommonRegs.OENR = HRTIM_OENR_TA1OEN + HRTIM_OENR_TA2OEN;    
47.   
48.    // start master timer and timer A
49.    HRTIM1->sMasterRegs.MCR |= HRTIM_MCR_TACEN + HRTIM_MCR_MCEN
50.}

And here for TIM2:
01.void setupTIM2(void)
02.{
03.    __TIM2_CLK_ENABLE();
04.     
05.    TIM2->CR2 |= TIM_CR2_MMS_1;            // use update as TRGO
06.    TIM2->ARR = 72000-1;                   // with 72MHz results on overflow every 1kHz
07.    TIM2->PSC = 1;   
08.    TIM15->CR1 |= TIM_CR1_CEN;
09.    TIM15->EGR |= TIM_EGR_UG;             // force update
10.}

I'm relatively new to ARMs and in special to STM32 so I would appreciate any help ;)
Thanks

Outcomes