280/317
9 - A Carrier-current System for domestIc Remote Control
the interrupts, for whatever the initial value of TBOC2R, there will necessarily be a Compare
2 event before the free-running counter overflows. This would trigger an interrupt request as
soon as the interrupt mask bit is set. To avoid this, the Compare 2 event flag is also cleared
though it is not actually used.
The complete code of the function is:
void WaitDelay ( Word Time )
{
asm
{
clr TBCLR /* Any write to free-running timer sets it
to FFFC. */
ld a, TBSR /* Clear pending interrupt for compare 2 */
ld a, TBOC2LR
ld a, Time /* Set time to go, high byte. Compares are
now inhibited. */
ld TBOC1HR, a
ld a, TBSR /* First step to clear pending interrupt. */
ld a, Time:1
ld TBOC1LR, a /* Write low byte to re-enable compare. */
bset TBCR1, #OCIE /* Enable interrupt on compare */
}
while ( ! TimeElapsed )
WaitForInterrupt ; /* Keep asleep until time elapsed. */
}
When the comparison occurs, it triggers an interrupt that is served by the following code:
void CoilEndOfPulse ( void )
{
COILS = DE_ENERGIZE ;
TBCR1 &= ~( 1 << OCIE ) ; /* Inhibit further interrupts. */
}
This function masks out the interrupt requests generated by Timer B, and also switches off all
the relay coils. Since these two functions are mainly used to produce current pulses within the
relay coils, the de-energizing of the coils is done right in the interruptservice routine.As stated
above, the correct behavior of the power supply makes it essential that the duration of the cur-
rent pulses in the relay coils be strictly limited to the necessary time, i.e. 5 ms.
Analog to digital converter control
The analog to digital converter is used to measuretwo differentvoltages: the output of the car-
rier detector, and the motor winding voltage. The latter measurement is necessary for
checking whether the blind motor is currently running, or stopped by its integral end-of-stroke