RZT Flexible Software Package Documentation  Release v2.2.0

 
Temperature Sensor Unit (r_tsu)

Functions

fsp_err_t R_TSU_Open (adc_ctrl_t *p_ctrl, adc_cfg_t const *const p_cfg)
 
fsp_err_t R_TSU_ScanCfg (adc_ctrl_t *p_ctrl, void const *const p_extend)
 
fsp_err_t R_TSU_ScanStart (adc_ctrl_t *p_ctrl)
 
fsp_err_t R_TSU_ScanGroupStart (adc_ctrl_t *p_ctrl, adc_group_mask_t group_mask)
 
fsp_err_t R_TSU_ScanStop (adc_ctrl_t *p_ctrl)
 
fsp_err_t R_TSU_StatusGet (adc_ctrl_t *p_ctrl, adc_status_t *p_status)
 
fsp_err_t R_TSU_Read (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint16_t *const p_data)
 
fsp_err_t R_TSU_Read32 (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint32_t *const p_data)
 
fsp_err_t R_TSU_Close (adc_ctrl_t *p_ctrl)
 
fsp_err_t R_TSU_InfoGet (adc_ctrl_t *p_ctrl, adc_info_t *p_adc_info)
 
fsp_err_t R_TSU_Calibrate (adc_ctrl_t *const p_ctrl, void const *p_extend)
 
fsp_err_t R_TSU_OffsetSet (adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, int32_t offset)
 
fsp_err_t R_TSU_CallbackSet (adc_ctrl_t *const p_ctrl, void(*p_callback)(adc_callback_args_t *), void const *const p_context, adc_callback_args_t *const p_callback_memory)
 

Detailed Description

Driver for the TSU peripheral on RZ microprocessor. This module implements the ADC Interface.

Overview

Features

The TSU module supports the following features:

Configuration

Build Time Configurations for r_tsu

The following build time configurations are defined in fsp_cfg/r_tsu_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Analog > ADC (r_tsu)

This module can be added to the Stacks tab via New Stack > Analog > ADC (r_tsu).

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_tsu0 Module name.

Clock Configuration

The TSU clock is PCLKL. The clock is configurable on the Clocks tab.

Pin Configuration

This module does not use I/O pins.

Usage Notes

Using the Temperature Sensor with the TSU

The TSU HAL module supports reading the data from the on-chip temperature sensor. The value returned from the sensor can be converted into degrees Celsius in the application program using the following formula, T = (Ds - D1) / Slope + T1, where:

To ensure accuracy, this 2-point calibration and also averaging the data obtained at least 8 times continuously are required.

Examples

Temperature Sensor Example

This example shows how to calculate the microprocessor temperature using the TSU.

#define TSU_EXAMPLE_SCAN_COUNT (8U)
#define TSU_EXAMPLE_CONVERSION_DELAY (20U)
#define TSU_EXAMPLE_D1 (1545)
#define TSU_EXAMPLE_SLOPE_x10000 (625)
#define TSU_EXAMPLE_10000 (10000)
#define TSU_EXAMPLE_T1 (25)
#define TSU_EXAMPLE_LOWER_LIMIT (0)
#define TSU_EXAMPLE_UPPER_LIMIT (50)
void tsu_temperature_example (void)
{
/* The following example calculates the temperature on an RZ device using the data provided in the section
* "Preparation for Using the Temperature Sensor" of the RZ microprocessor manual. */
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TSU_Open(&g_tsu0_ctrl, &g_tsu0_cfg);
/* Handle any errors. This function should be defined by the user. */
handle_error(err);
/* Enable temperature sensor and start scans by calling R_TSU_ScanStart(). */
(void) R_TSU_ScanStart(&g_tsu0_ctrl);
/* Wait for conversion to complete and read converted data. To ensure accuracy, averaging the data obtained
* at least 8 times continuously are required. */
uint16_t temperature_conversion_result[TSU_EXAMPLE_SCAN_COUNT];
uint16_t ds = 0;
for (uint8_t i = 0; i < TSU_EXAMPLE_SCAN_COUNT; i++)
{
R_BSP_SoftwareDelay(TSU_EXAMPLE_CONVERSION_DELAY, BSP_DELAY_UNITS_MICROSECONDS);
/* Read converted data. */
err = R_TSU_Read(&g_tsu0_ctrl, ADC_CHANNEL_TEMPERATURE, (temperature_conversion_result + i));
handle_error(err);
ds = (uint16_t) (ds + temperature_conversion_result[i]);
}
ds /= TSU_EXAMPLE_SCAN_COUNT;
/* Formula for calculating temperature copied from section "Preparation for Using the Temperature Sensor"
* of the RZ microprocessor manual:
*
* The measured temperature can be calculated according to the following formula.
*
* T = (Ds - D1) / Slope + T1
* T: Measured temperature (C)
* Ds: Code output (TSUSAD.DOUT) by the temperature sensor at the time of temperature measurement
* T1 = 25 C: Temperature experimentally measured at one point (C)
* D1: Code output (TSUSAD.DOUT) by the temperature sensor at the time of measurement of T1
* T2 = 85 C: Temperature at the experimental measurement of another point (C)
* D2: Code output (TSUSAD.DOUT) by the temperature sensor at the time of measurement of T2
* Slope: Temperature gradient by the temperature sensor (digit/C)
* For temperature more than or equal to 25 C (for example, if Ds >= D1)
* Slope = (D2 - D1) / (T2 - T1)
* For temperature below 25 C (for example, if Ds < D1)
* Slope = (D2 - D1) / (T2 - T1) x 63 / 65
*
* NOTE: Characteristics vary from sensor to sensor. Therefore, the measurement at two different temperatures
* (T1 = 25 C and T2 = 85 C) is recommended. This example uses the typical Slope and D1 provided in Table
* "Temperature sensor characteristics" in the RZ microprocessor manual.
*/
int32_t temperature_c = ((int32_t) ds - TSU_EXAMPLE_D1) * TSU_EXAMPLE_SLOPE_x10000 / TSU_EXAMPLE_10000 +
TSU_EXAMPLE_T1;
/* Break if temperature is outside the expected range. */
if ((temperature_c < TSU_EXAMPLE_LOWER_LIMIT) || (temperature_c > TSU_EXAMPLE_UPPER_LIMIT))
{
__BKPT(0);
}
}

Data Structures

struct  tsu_instance_ctrl_t
 

Data Structure Documentation

◆ tsu_instance_ctrl_t

struct tsu_instance_ctrl_t

TSU instance control block. DO NOT INITIALIZE. Initialized in adc_api_t::open().

Function Documentation

◆ R_TSU_Open()

fsp_err_t R_TSU_Open ( adc_ctrl_t p_ctrl,
adc_cfg_t const *const  p_cfg 
)

Start the TSU module.

Return values
FSP_SUCCESSModule is ready for use.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_ALREADY_OPENThe instance control structure has already been opened.

◆ R_TSU_ScanCfg()

fsp_err_t R_TSU_ScanCfg ( adc_ctrl_t p_ctrl,
void const *const  p_extend 
)

adc_api_t::scanCfg is not supported on the TSU.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_ScanStart()

fsp_err_t R_TSU_ScanStart ( adc_ctrl_t p_ctrl)

Enable the temperature sensor and ADC. Start A/D conversion.

Note
Even if the A/D conversion starts, it takes time for the results to be stored. So wait until the result is stored and then read.
Return values
FSP_SUCCESSScan started.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.
FSP_ERR_IN_USEAnother scan is still in progress.

◆ R_TSU_ScanGroupStart()

fsp_err_t R_TSU_ScanGroupStart ( adc_ctrl_t p_ctrl,
adc_group_mask_t  group_mask 
)

adc_api_t::scanGroupStart is not supported on the TSU.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_ScanStop()

fsp_err_t R_TSU_ScanStop ( adc_ctrl_t p_ctrl)

Stop A/D conversion. Disable the temperature sensor and ADC.

Return values
FSP_SUCCESSScan stopped.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_TSU_StatusGet()

fsp_err_t R_TSU_StatusGet ( adc_ctrl_t p_ctrl,
adc_status_t p_status 
)

Provide the A/D conversion status.

Return values
FSP_SUCCESSModule status stored in the provided pointer p_status.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_TSU_Read()

fsp_err_t R_TSU_Read ( adc_ctrl_t p_ctrl,
adc_channel_t const  reg_id,
uint16_t *const  p_data 
)

Reads conversion results from a sensor.

Note
Specify ADC_CHANNEL_TEMPERATURE for reg_id.
Return values
FSP_SUCCESSData read into provided p_data.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.
FSP_ERR_INVALID_STATERead command not valid in the current state.

◆ R_TSU_Read32()

fsp_err_t R_TSU_Read32 ( adc_ctrl_t p_ctrl,
adc_channel_t const  reg_id,
uint32_t *const  p_data 
)

adc_api_t::read32 is not supported on the TSU.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_Close()

fsp_err_t R_TSU_Close ( adc_ctrl_t p_ctrl)

Stop the TSU module.

Return values
FSP_SUCCESSModule closed.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_TSU_InfoGet()

fsp_err_t R_TSU_InfoGet ( adc_ctrl_t p_ctrl,
adc_info_t p_adc_info 
)

adc_api_t::infoGet is not supported on the TSU.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_Calibrate()

fsp_err_t R_TSU_Calibrate ( adc_ctrl_t *const  p_ctrl,
void const *  p_extend 
)

adc_api_t::calibrate is not supported on the TSU.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_OffsetSet()

fsp_err_t R_TSU_OffsetSet ( adc_ctrl_t *const  p_ctrl,
adc_channel_t const  reg_id,
int32_t  offset 
)

adc_api_t::offsetSet is not supported on the TSU.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_CallbackSet()

fsp_err_t R_TSU_CallbackSet ( adc_ctrl_t *const  p_ctrl,
void(*)(adc_callback_args_t *)  p_callback,
void const *const  p_context,
adc_callback_args_t *const  p_callback_memory 
)

adc_api_t::callbackSet is not supported on the TSU.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.