Calib
Listing index
Chk2
Routine:        Chk1            
Function:       Finds the maximum motor speed, where angle > 170.       
Called by:      Range
Calls:          Error, Read, Sub        
Entry:          None    
Exit:           Mtrmax is set; C flag set on error
Preserved:      None


CHK1    XOR     A
        LD      (MTRMAX),A
        OUT     (142),A
        OUT     (143),A
; Start at the maximum motor speed, ie output zero to the DAC. 
        LD      DE,NUM4
        LD      HL,NUM5
        LD      B,10
        CALL    READ
Do ten revolutions initially to get the motor up to speed.
        JR      NC,CHK1C
CHK1A   LD      A,(MTRMAX)
        OUT     (143),A
        LD      DE,NUM4
        LD      HL,NUM5
        LD      B,3
; 3 revolutions per subsequent reading.
        CALL    READ
        JR      NC,CHK1C
; On error jump.
        LD      BC,NUM4
        LD      DE,ONE70
        LD      HL,NUM1
        CALL    SUB
; Subtract 170 degrees to see if the measured angle is < 170.
        LD      IX,NUM1
        BIT     7,(IX+3)
        JR      NZ,CHK1B
; If angle > 170 then decrease the motor speed and try again.
        LD      A,(MTRMAX)
        ADD     A,8
        LD      (MTRMAX),A
        JR      CHK1A
CHK1B   LD      A,255
        OUT     (143),A
; Stop the motor and return.
        OR      A
        RET
CHK1C   LD      A,255
        OUT     (143),A
; Decide the cause of the error: viscosity too small or too large. Call subroutine Error to display the error code.
        LD      A,(MTRMAX)
        OR      A
        LD      A,4
        JR      Z,CHK1D
        LD      A,3
CHK1D   CALL    ERROR
        SCF
        RET
 
Calib
Listing index
Chk2