RL78/G14 Timer Array Unit (TAU) as Interval Timer
RL78/G14 Timer Array Unit (TAU) as Interval Timer
Hi, good day!
I’m trying to create a microsecond delay function and I’m using the following:
e2 studio IDE
GCC for Renesas RL78 v4.9.202201
R5F104ML (RL78/G14 Fast Prototyping Board) – On-chip memory: 512-KB ROM, 48-KB RAM, 8-KB data flash memory
I hope you can help me with my following questions.
I configured the TAU using the code generator. Clock is 32MHz with no prescaler used so every clock cycle is around 31.25ns.
My first question is not actually related to TAU. I just noticed that the time setting a pin HIGH is smaller than setting it LOW. There’s a ~100ns difference. HIGH is around 393.2ns while LOW is 494.8ns.
(I hope I can attach a screenshot here but the site won’t allow me)
Now for my 2nd question, I understand that I cannot achieve a 1us delay due to the overhead that the compiler generates. For a 1us value (0x001F / 31 in decimal) loaded in the TDR register, I’m getting around 3.85us for HIGH and 3.95us for LOW. I’m planning to round it off to 4us by adding 3 or 4 in the TDR value. However, it doesn’t work. There’s only change in the width of the signal when I add another 32 to the TDR value adding another 1us to the delay.
Here’s my code:
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED “AS IS” AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2011, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_main.c
* Version : CodeGenerator for RL78/G14 V2.05.06.02 [08 Nov 2021]
* Device(s) : R5F104ML
* Tool-Chain : GCCRL78
* Description : This file implements main function.
* Creation Date: 22/09/2022
***********************************************************************************************************************/
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include “r_cg_macrodriver.h”
#include “r_cg_cgc.h”
#include “r_cg_timer.h”
/* Start user code for include. Do not edit comment generated here */
#include “r_cg_timer.h”
/* End user code. Do not edit comment generated here */
#include “r_cg_userdefine.h”
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
void TAU_delay(uint16_t TDR_value);
/* End user code. Do not edit comment generated here */
void R_MAIN_UserInit(void);
/***********************************************************************************************************************
* Function Name: main
* Description : This function implements main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
PM5_bit.no3 = 0;
TAU0EN = 1U; /* supplies input clock */
TPS0 = _0000_TAU_CKM0_FCLK_0 | _0000_TAU_CKM1_FCLK_0 | _0000_TAU_CKM2_FCLK_1 | _0000_TAU_CKM3_FCLK_8;
/* Stop all channels */
TT0 = _0001_TAU_CH0_STOP_TRG_ON | _0002_TAU_CH1_STOP_TRG_ON | _0004_TAU_CH2_STOP_TRG_ON |
_0008_TAU_CH3_STOP_TRG_ON | _0200_TAU_CH1_H8_STOP_TRG_ON | _0800_TAU_CH3_H8_STOP_TRG_ON;
/* Mask channel 0 interrupt */
TMMK00 = 1U; /* disable INTTM00 interrupt */
TMIF00 = 0U; /* clear INTTM00 interrupt flag */
/* Channel 0 used as interval timer */
TMR00 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_COMBINATION_SLAVE |
_0000_TAU_TRIGGER_SOFTWARE | _0000_TAU_MODE_INTERVAL_TIMER | _0000_TAU_START_INT_UNUSED;
TO0 &= ~_0001_TAU_CH0_OUTPUT_VALUE_1;
TOE0 &= ~_0001_TAU_CH0_OUTPUT_ENABLE;
while (1U)
{
P5_bit.no3 = 1;
TAU_delay(33);
P5_bit.no3 = 0;
TAU_delay(33);
}
/* End user code. Do not edit comment generated here */
}
/***********************************************************************************************************************
* Function Name: R_MAIN_UserInit
* Description : This function adds user code before implementing main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_MAIN_UserInit(void)
{
/* Start user code. Do not edit comment generated here */
EI();
/* End user code. Do not edit comment generated here */
}
/* Start user code for adding. Do not edit comment generated here */
void TAU_delay(uint16_t TDR_value)
{
TDR00 = TDR_value;
TS0 |= _0001_TAU_CH0_START_TRG_ON;
while (TMIF00 != 1) { }
TT0 |= _0001_TAU_CH0_STOP_TRG_ON;
TMIF00 = 0;
}
/* End user code. Do not edit comment generated here */
I didn’t use interrupt here. I only polled the TMIF00 flag. Do you have any idea why TAU doesn’t respond to small changes? Thank you in advance for the answers.
Regards,
June
Hi June,
Thank you for reaching out to us!
Unfortunately, the problem reported above does not seem to be related to the functionality of the RL78 compilers. All we can do is suggest you try to get the information you need from the documentation page provided on the Renesas website: https://www.renesas.com/sg/en/document/rln/code-generator-rl78-release-note or try to contact their support team directly.
Another communication channel with the Renesas community may be found here: https://community.renesas.com/
__
Best regards,
The Open Source Tools Team
Hi Open Source Tools Team!
Oh I’m sorry, I didn’t know this. But thank you for the response!
Regards,
June