2015-01-26 08:09 AM
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
2015-01-28 03:09 AM
Hi,
Refering to RM0364, only TIM1 can be used for HRTIM synchronization configuring SYNCIN bits with value ''10: the on-chip TIM1 general purpose timer (TIM1 TRGO output)).
You can have a look tohttp://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/LN1897/PF260613
package where you will find various examples & use cases for the HRTIM (under STM32Cube_FW_F3_V1.1.0\Projects\STM32F3348-Discovery\Examples\HRTIM).-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2015-02-02 12:18 AM
Hi Mayla,
Thank you very much for the information. Where in RM0364 can I find the information? Thank you very much,Tobias2015-02-02 01:10 AM
Interesting. After solving some issues with my toolchain I now got it running as I wanted with TIM2:
1.
// reset on external event channel 2, source 3 -> TIM2_TRGO
2.
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].RSTxR = HRTIM_RSTR_EXTEVNT2;
3.
HRTIM1->sCommonRegs.EECR1 = HRTIM_EECR1_EE2SRC_1;