CHAPTER 4 PROGRAM LIST
Application Note U17209EJ1V0AN
174
nop
# #
#-------------------------- end of start up module ----------------------------#
# #
4.5.5 Main processing function
#include "Common.h"
#include "Motor.h"
#pragma ioreg /* Peripheral I/O register definition */
static int save_psw;
/****************************************************************************** /
/* 3-phase motor control program */
/****************************************************************************** /
void main()
{
unsigned char proc_no ; /* Present processing number */
signed int speed ; /* Indication speed rms */
signed int accel_spd ;
int sw, sw_mode ;
/* */
hinit() ; /* Hardware initialization */
ainit() ; /* Initialization of area used */
proc_no = 0 ;
_ _EI();
while( 1 ) {
accel_spd = ( SPEED_MAX - SPEED_MINI ) / 100;
speed = ( ( SPEED_MAX - SPEED_MINI ) * volume / 1024 )
+ SPEED_MINI ; /* Indication speed calculation by */
/* volume */
sw = ~IN_data( SW ) & 0x07 ; /* Read operation button */
if ( sw == 1 ) {
sw_mode = CW ;
} else if ( sw == 2 ) {
sw_mode = CCW ;
} else if ( sw == 4 ) {
sw_mode = STOP ;
}
switch( proc_no ) {
/* STOP processing */
case 0 :
if ( sw_mode == CW ) {
_ _DI() ;
object_speed = SPEED_MINI ; /* Set target speed to minimum value */
stop_flag = OFF ;
timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */
accel_count = ACCEL_VAL_1ST ; /* Set acceleration/deceleration counter */