English
Language : 

AN4539 Datasheet, PDF (15/33 Pages) STMicroelectronics – HRTIM cookbook
AN4539
HRTIM operating principles basics
/* --------------------- Timer A initialization ---------------------- */
/* TIMA counter operating in continuous mode with prescaler = 010b (div.
by 4) */
/* Preload enabled on REP event*/
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].TIMxCR = HRTIM_TIMCR_CONT
+ HRTIM_TIMCR_PREEN + HRTIM_TIMCR_TREPU + HRTIM_TIMCR_CK_PSC_1;
/* Set period to 33kHz and duty cycles to 25% */
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].PERxR = _33KHz_PERIOD;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP1xR = _33KHz_PERIOD/4;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP2xR = _33KHz_PERIOD/2;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP3xR =
(3*_33KHz_PERIOD)/4;
/* TA1 output set on TIMA period and reset on TIMA CMP1 event*/
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].SETx1R = HRTIM_SET1R_PER;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].RSTx1R = HRTIM_RST1R_CMP1;
/* TA2 output set on TIMA CMP2 and reset on TIMA period event*/
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].SETx2R = HRTIM_SET2R_CMP2;
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].RSTx2R = HRTIM_RST2R_CMP3;
/* Enable TA1, TA2, TD1 and TD2 outputs */
HRTIM1->sCommonRegs.OENR = HRTIM_OENR_TA1OEN + HRTIM_OENR_TA2OEN +
HRTIM_OENR_TD1OEN + HRTIM_OENR_TD2OEN;
GPIO_HRTIM_outputs_Config(); /* Initialize HRTIM GPIO outputs */
/* Start Timer A and Timer D */
HRTIM1->sMasterRegs.MCR = HRTIM_MCR_TACEN + HRTIM_MCR_TDCEN;
2.3
Note:
Generating PWM with other timing units and the master timer
In this section we will discuss:
• Generation of signals on outputs not related to a given timer.
This example shows that thanks to the set/reset crossbar, it’s possible to have PWM signals
(or other waveforms) generated on a given output with any other available timer. This is
interesting in the following cases:
• to generate a 6th PWM independent frequency with the master timer, as in the example
below;
• to work-around pin-out constraints, for instance using Timer E to generate waveforms
even if TE1 and TE2 outputs are not available (typically on small pin-count package).
It is mandatory to have the same prescaling factors for all timer sharing resources (for
instance master timer and timer A must have identical CKPSC[2:0] values if master timer is
controlling TA1 or TA2 outputs).
DocID026506 Rev 1
15/33
32