使用例
割り込み&リセット・モードを使用し、リセット前に行うべき処理を割り込みで行う
[GUI設定例]
電圧検出回路 |
||||
LVD |
使用する | |||
電圧検出動作設定 |
使用する | |||
動作モード設定 |
割込み&リセットモード | |||
INTLVI優先順位 |
低 | |||
リセット発生電圧(VLVDL) |
2.75(V) | |||
割込み発生電圧(VLVDH) |
3.15(V) |
[API設定例]
r_main.c
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
/* Enable the voltage detector interrupt */
R_LVD_InterruptMode_Start();
while (1U)
{
;
}
/* End user code. Do not edit comment generated here */
}
r_cg_lvd_user.c
static void __near r_lvd_interrupt(void)
{
/* Start user code. Do not edit comment generated here */
/*** Processing to be performed before the reset ***/
/* 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 */
}