A phase difference between external input signals from two pins TRGCLKA and TRGCLKB is detected and the TRG register is incremented/decremented.
Count the number of TRG register overflow and underflow.
[Waveform example]
[GUI setting example]
TimerRG |
Used | |||
TMRG |
Used | |||
Functions |
Phase counting mode | |||
Initial count |
0 | |||
Counter clear |
Clear disabled | |||
CNTEN0 |
Used | |||
CNTEN1 |
Used | |||
CNTEN2 |
Used | |||
CNTEN3 |
Used | |||
CNTEN4 |
Used | |||
CNTEN5 |
Used | |||
CNTEN6 |
Used | |||
CNTEN7 |
Used | |||
Enable TRG overflow interrupt |
Used | |||
Enable TRG under flowinterrupt |
Used | |||
INTTRG priority |
Low/ level3 (low priority level) |
[API setting example]
r_cg_main.c
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
/* Start the TMRG module operation */
R_TMRG0_Start();
while (1U)
{
;
}
/* End user code. Do not edit comment generated here */
}
r_cg_tmrg_user.c
/* Start user code for global. Do not edit comment generated here */
volatile uint8_t inttrg_over_cnt = 0U;
volatile uint8_t inttrg_under_cnt = 0U;
/* End user code. Do not edit comment generated here */
static void __near r_tmrg0_interrupt(void)
{
/* Start user code. Do not edit comment generated here */
uint8_t temp_trg = 0U;
/* === Count number of overflow or under flow === */
/* Mask TRGSR resister to check overflow or underflow occurred */
temp_trg = TRGSR & 0x0CU;
if (temp_trg == 0x08U)
{
/* --- Count up number of overflow --- */
inttrg_over_cnt++;
/* --- Clear overflow Flag --- */
TRGSR &= 0x07U;
}
else
{
/* --- Count up number of underflow --- */
inttrg_under_cnt++;
/* --- Clear under flow Flag --- */
TRGSR &= 0x0BU;
}
/* End user code. Do not edit comment generated here */
}