283/317
9 - A Carrier-current System for domestIc Remote Control
case STOP_CLOSE:
StopMotor () ;
break ;
case START_OPEN:
COILS = OPEN ;
WaitDelay ( COIL_PULSE ) ;
COILS = START ;
WaitDelay ( COIL_PULSE ) ;
WaitDelay(5*TENTH_SECOND ) ;
break ;
case START_CLOSE:
COILS = CLOSE ;
WaitDelay ( COIL_PULSE ) ;
COILS = START ;
WaitDelay ( COIL_PULSE ) ;
WaitDelay(5*TENTH_SECOND ) ;
break ;
}
}
When the message means “stop”, the function StopMotor above is called. Otherwise, the ap-
propriate coil is energized, then the timer is started for 5 ms, then an additional delay is in-
cluded. This delay guarantees that the cycle could not be repeated to fast, to avoid having the
power supply voltage fall dangerously. This also allows the motor to start, and the motor
stopped detector to work properly.
Main function.
Now we can look at the main program. It is made of a few lines, because most of the
processing is done in functions called from it. This both saves the code size and improves the
clarity of the code for later modification.
After initializing, the program enters an endless loop. Each time a remote command is re-
ceived that requests either to open or close the blind,the motor is started in the appropriate di-
rection. Then, if the button is pressed, the current state is changed for the next start in this
cycle: open, stop, close, stop, open...
Eventually, if the state is
START_OPEN or START_CLOSE, and if the motor is found stopped, this
means that the motion is complete and that the end-of-stroke switch has been actuated. The
state is then changed to the corresponding
STOP_ state, so that the system is ready to start in
the opposite direction the next time the button is pressed.
The main program is the following:
void main ( void )
{