CHAPTER 4 PROGRAM LIST
Application Note U17209EJ1V0AN
150
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 */
init_flag = 2 ; /* CCW initial request */
start_init() ; /* Initialize revolution start */
_ _EI() ;
proc_no = 1 ; /* Set next processing number */
} else if ( sw_mode == CCW ) {
_ _DI() ;
stop_flag = OFF ; /* Stop flag off */
object_speed = -SPEED_MINI ; /* Set target speed to minimum value */
timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */
accel_count = ACCEL_VAL_1ST ;/* Set acceleration/deceleration counter */
init_flag = 3 ; /* CCW initial request */
start_init() ; /* Initialize revolution start */
_ _EI() ;
proc_no = 4 ; /* Set CCW processing number */
}
break ;
/* CW processing, acceleration */
case 1 :
if ( accel_count == 0 ) {
accel_count = ACCEL_VAL ; /* Set acceleration/deceleration counter */
if ( object_speed < speed ) {
object_speed += accel_spd ;
if ( object_speed > speed ) object_speed = speed;
timer_count = WATCH_START ;/* Set speed monitor start time to 5 SEC */
} else if ( object_speed > speed ) {
object_speed -= accel_spd ;
if ( object_speed < speed ) object_speed = speed;
timer_count = WATCH_START ;/* Set speed monitor start time to 5 SEC */
} else {
proc_no = 2 ; /* Constant-speed processing */
}