📄 vhz.c
字号:
/* pwm.period_max=750; */ /* This is based on 20kHz PWM frequency (30MHz) */
pwm.period_max=1000; /* This is based on 20kHz PWM frequency (40MHz) */
#endif /* TARGET */
/*-----------------------------------------------------------------------------
Initialize the VHZ_TI object. This is a call to the init method within the
VHZ_TI object vhz.
-----------------------------------------------------------------------------*/
VHZ_TI_Init(&vhz);
/*-----------------------------------------------------------------------------
Initialize the real time monitor
-----------------------------------------------------------------------------*/
rtmon_init(); /* Call the monitor init function */
enable_ints(); /* Set off the system running. */
/*-----------------------------------------------------------------------------
Initialize DRIVE -- Waiting for PWM enable flag setting
-----------------------------------------------------------------------------*/
while(drive.enable_flg==0)
{
drive.init(&drive);
}
/*-----------------------------------------------------------------------------
Initialize PWM Generator
-----------------------------------------------------------------------------*/
pwm.mfunc_c1=0;
pwm.mfunc_c2=0;
pwm.mfunc_c3=0;
pwm.init(&pwm);
/*-----------------------------------------------------------------------------
Initialize the capture interface
-----------------------------------------------------------------------------*/
cap.init(&cap);
/*-----------------------------------------------------------------------------
Set the dac pointers to the phases and alpha of the VHZ_TI object
phase outputs.
-----------------------------------------------------------------------------*/
dac.qptr0=&vhz.svgen.va;
dac.qptr1=&vhz.svgen.vb;
dac.qptr2=&vhz.svgen.vc;
dac.qptr3=&vhz.svgen.alpha;
/*-----------------------------------------------------------------------------
Initialize the DATALOG moddule. And set the dlog pointers to the
phases of the VHZ_TI object phase outputs.
-----------------------------------------------------------------------------*/
dlog.init(&dlog);
dlog.dlog_iptr1=&vhz.svgen.va;
dlog.dlog_iptr2=&vhz.svgen.vb;
#endif /* (BUILDLEVEL==LEVEL3) */
#if TARGET==F243
EVIFRA=0x0ffff; /* Clear all Group A EV interrupt flags */
#elif TARGET==F2407
EVAIFRA=0x0ffff; /* Clear all EV1 Group A EV interrupt flags*/
#endif /* TARGET */
/*---------------------------------------------------------------------------*/
while(1) /* Nothing running in the background at present */
{
}
} /* End: main() */
void interrupt c_int02()
{
asm(" CLRC XF ");
isr_ticker++;
#if (BUILDLEVEL==LEVEL1)
/*---------------------------------------------------------------------------*/
#if TARGET==F243
EVIFRA=0x0ffff; /* Clear all Group A EV interrupt flags */
#elif TARGET==F2407
EVAIFRA=0x0ffff; /* Clear all EV1 Group A EV interrupt flags*/
#endif /* TARGET */
/*------------------------------------------------------------------------------
Call the enable/disable PWM signal drive function.
------------------------------------------------------------------------------*/
drive.calc(&drive);
/*-----------------------------------------------------------------------------
Call the VHZ_TI_Run function to perform the runtime tasks of the VHZ_TI
algorithm.
-----------------------------------------------------------------------------*/
VHZ_TI_Run(&vhz);
/*-----------------------------------------------------------------------------
Call the diagnostic DAC utility update function.
-----------------------------------------------------------------------------*/
dac.update(&dac);
/*-----------------------------------------------------------------------------
Call the diagnostic DATALOG utility update function.
-----------------------------------------------------------------------------*/
dlog.update(&dlog);
/*---------------------------------------------------------------------------*/
#endif /* BUILDLEVEL==LEVEL1*/
#if (BUILDLEVEL==LEVEL2)
/*---------------------------------------------------------------------------*/
#if TARGET==F243
EVIFRA=0x0ffff; /* Clear all Group A EV interrupt flags */
#elif TARGET==F2407
EVAIFRA=0x0ffff; /* Clear all EV1 Group A EV interrupt flags*/
#endif /* TARGET */
/*------------------------------------------------------------------------------
Call the enable/disable PWM signal drive function.
------------------------------------------------------------------------------*/
drive.calc(&drive);
/*-----------------------------------------------------------------------------
Call the VHZ_TI_Run function to perform the runtime tasks of the VHZ_TI
algorithm.
-----------------------------------------------------------------------------*/
VHZ_TI_Run(&vhz);
/*-----------------------------------------------------------------------------
Connect output of the VHZ.SVGEN to the PWM Driver and call the PWM driver
update function.
-----------------------------------------------------------------------------*/
pwm.mfunc_c1=vhz.svgen.va;
pwm.mfunc_c2=vhz.svgen.vb;
pwm.mfunc_c3=vhz.svgen.vc;
pwm.update(&pwm);
/*-----------------------------------------------------------------------------
Call the diagnostic DAC utility update function.
-----------------------------------------------------------------------------*/
dac.update(&dac);
/*-----------------------------------------------------------------------------
Call the diagnostic DATALOG utility update function.
-----------------------------------------------------------------------------*/
dlog.update(&dlog);
/*---------------------------------------------------------------------------*/
#endif /* BUILDLEVEL==LEVEL2*/
#if (BUILDLEVEL==LEVEL3)
/*---------------------------------------------------------------------------*/
#if TARGET==F243
EVIFRA=0x0ffff; /* Clear all Group A EV interrupt flags */
#elif TARGET==F2407
EVAIFRA=0x0ffff; /* Clear all EV1 Group A EV interrupt flags*/
#endif /* TARGET */
/*------------------------------------------------------------------------------
Call the enable/disable PWM signal drive function.
------------------------------------------------------------------------------*/
drive.calc(&drive);
/*-----------------------------------------------------------------------------
Call the capture driver read function. Note, that this func returns the
status, as the return value, NOT the time_stamp. The time_stamp is returned
directly into CAPTURE object structure.
-----------------------------------------------------------------------------*/
if((cap.read(&cap))==0) /* Call the capture read function*/
{
speed.time_stamp=cap.time_stamp; /* Read out new time stamp */
speed.calc(&speed); /* Call the speed calulator */
vhz.speed_value=speed.speed_prd; /* Update vhz object speed info */
}
/*-----------------------------------------------------------------------------
Call the VHZ_TI_Run function to perform the runtime tasks of the VHZ_TI
algorithm.
-----------------------------------------------------------------------------*/
VHZ_TI_Run(&vhz);
/*-----------------------------------------------------------------------------
Connect output of the VHZ.SVGEN to the PWM Driver and call the PWM driver
update function.
-----------------------------------------------------------------------------*/
pwm.mfunc_c1=vhz.svgen.va;
pwm.mfunc_c2=vhz.svgen.vb;
pwm.mfunc_c3=vhz.svgen.vc;
pwm.update(&pwm);
/*-----------------------------------------------------------------------------
Call the diagnostic DAC utility update function.
-----------------------------------------------------------------------------*/
dac.update(&dac);
/*-----------------------------------------------------------------------------
Call the diagnostic DATALOG utility update function.
-----------------------------------------------------------------------------*/
dlog.update(&dlog);
/*---------------------------------------------------------------------------*/
#endif /* BUILDLEVEL==LEVEL3*/
asm(" SETC XF ");
} /* c_int02() */
void RstSystem(void)
{
/*----------------------------------------------------------------------------
First execute the initialization for the Wait Stage Genrator,
Global interrupt disable, Shut off the Watchdog,
and set up the Interupt Mask Register
-----------------------------------------------------------------------------*/
WSGR=WAIT_STATES; /* Initialize Wait State Generator */
disable_ints(); /* Make sure the interrupts are disabled */
wdog.disable(); /* Vccp/Wddis pin/bit must be high */
IMR=0x02; /* Set up interrupt mask to enable INT2
until an explicit enable. */
/*-----------------------------------------------------------------------------
Next we do the code for setting up the SCSR register, which is dependent
on the exact device the code is being compiled for (F243 / F2407).
-----------------------------------------------------------------------------*/
#if (TARGET==F243)
SCSR=0x40c0; /* Init SCSR */
EVIMRA=0x0200; /* Enable the timer underflow interrupt */
#endif
#if (TARGET==F2407)
SCSR1=0xc; /* Init SCSR */
EVAIMRA=0x0200; /* Enable the timer underflow interrupt */
#endif /* TARGET */
} /* RstSystem(void) */
void interrupt phantom(void)
{
static int phantom_count;
phantom_count ++;
/* Empty function: Used to handle any unwanted interrupts or events.
All unused interrupt vectors are pointed to this function so that
if any un-handled interrupts do get enabled, they are handled in a
benign manner, preventing un-intended branches, calls or execution
into garbage.
Note that this function is an ISR, not a ordinary function.
*/
} /* phantom() */
/*-----------------------------------------------------------------------------
This function just provides a c-interface to the asm RTMON init function
call. This function continues execution untill the user
-----------------------------------------------------------------------------*/
void rtmon_init(void)
{
asm(" CALL MON_RT_CNFG ");
} /* rtmon_init() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -