使用例
ワンショットタイマとして使用する
[GUI設定例]
タイマ |
使用する | |||
TAU0 |
使用しない | |||
WUTM |
使用する | |||
16ビット・ウエイクアップ・タイマ動作設定 |
使用する | |||
カウント・クロック設定 |
自動 | |||
インターバル時間 |
100ms (実際の値:100) | |||
設定した周期毎に通知する (INTWUTM) |
使用する | |||
優先順位(INTWUTM) |
低 |
[API設定例]
r_main.c
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
/* Start WUTM counter */
R_WUTM_Start();
while (1U)
{
;
}
/* End user code. Do not edit comment generated here */
}
r_cg_timer_user.c
static void __near r_wutm_interrupt(void)
{
/* Start user code. Do not edit comment generated here */
/* Stop WUTM counter */
R_WUTM_Stop();
/* End user code. Do not edit comment generated here */
}
PWM出力を10回発生させる
main.c
#include "r_smc_entry.h"
void main(void)
{
/* Start MTU channel 0 counter */
R_Config_MTU0_Start();
while (1U)
{
nop();
}
}
Config_MTU0_user.c
/* Start user code for global. Do not edit comment generated here */
volatile uint8_t g_mtu0_cnt;
/* End user code. Do not edit comment generated here */
void R_Config_MTU0_Create_UserInit(void)
{
/* Start user code for user init. Do not edit comment generated here */
/* Reset the countor */
g_mtu0_cnt = 0U;
/* End user code. Do not edit comment generated here */
}
static void r_Config_MTU0_tgia0_interrupt(void)
{
/* Start user code for r_Config_MTU0_tgia0_interrupt. Do not edit comment generated here */
if ((++g_mtu0_cnt) > 9U)
{
/* Stop MTU channel 0 counter */
R_Config_MTU0_Stop();
}
/* End user code. Do not edit comment generated here */
}
2相の入力パルスにより、エンコーダ回転方向の確定を行う
main.c
#include "r_smc_entry.h"
void main(void)
{
/* Start the MTU1 channel counter */
R_Config_MTU1_Start();
while (1U)
{
nop();
}
}
Config_MTU1_user.c
/* Start user code for global. Do not edit comment generated here */
volatile uint8_t g_mtu1_dir;
/* End user code. Do not edit comment generated here */
void R_Config_MTU1_Create_UserInit(void)
{
/* Start user code for user init. Do not edit comment generated here */
/* Clear state */
g_mtu1_dir = 0U;
/* End user code. Do not edit comment generated here */
}
static void r_Config_MTU1_tgia1_interrupt(void)
{
/* Start user code for r_Config_MTU1_tgia1_interrupt. Do not edit comment generated here */
/* Set CW state */
g_mtu1_dir = 1U;
/* End user code. Do not edit comment generated here */
}
static void r_Config_MTU1_tgib1_interrupt(void)
{
/* Start user code for r_Config_MTU1_tgib1_interrupt. Do not edit comment generated here */
/* Set CCW state */
g_mtu1_dir = 2U;
/* End user code. Do not edit comment generated here */
}
U相の波を上限まで徐々に大きくした後は下限まで徐々に小さくする処理を繰り返す
main.c
#include "r_smc_entry.h"
void main(void)
{
/* Start the MTU6 channel counter */
R_Config_MTU6_MTU7_Start();
while (1U)
{
nop();
}
}
Config_MTU6_MTU7_user.c
/* Start user code for global. Do not edit comment generated here */
volatile uint16_t gu_pulse_u;
volatile int8_t g_pulse_dir_u;
/* End user code. Do not edit comment generated here */
void R_Config_MTU6_MTU7_Create_UserInit(void)
{
/* Start user code for user init. Do not edit comment generated here */
gu_pulse_u = _xxxx_6TGRB_VALUE;
g_pulse_dir_u = 1U;
/* End user code. Do not edit comment generated here */
}
static void r_Config_MTU6_MTU7_tgib6_interrupt(void)
{
/* Start user code for r_Config_MTU6_MTU7_tgib6_interrupt. Do not edit comment generated here */
gu_pulse_u += g_pulse_dir_u;
if(gu_pulse_u == _xxxx_TCDRB_VALUE)
{
g_pulse_dir_u = -1;
}
else if(gu_pulse_u == _xxxx_TDDRB_VALUE)
{
g_pulse_dir_u = 1;
}
MTU6.TGRB = gu_pulse_u;
MTU6.TGRD = gu_pulse_u;
/* End user code. Do not edit comment generated here */
}
MTU6,MTU7 を使用した相補 PWM 動作時の PWM 出力波形に対するデッドタイムを補償する
main.c
#include "r_smc_entry.h"
void main(void)
{
/* Start the MTU5 channel counter */
R_Config_MTU5_Start();
/* Start the MTU6 channel counter */
R_Config_MTU6_MTU7_Start();
while (1U)
{
nop();
}
}
Config_MTU5_user.c
static void r_Config_MTU5_tgiu5_interrupt(void)
{
/* Start user code for r_Config_MTU5_tgiu5_interrupt. Do not edit comment generated here */
/* Write the corrected value */
if ( MTU6.TGRB > MTU5.TGRU )
{
MTU6.TGRD = (MTU6.TGRB - MTU5.TGRU);
}
/* End user code. Do not edit comment generated here */
}