Page 236 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 236

7,6 Fuzzy Logic                                                     21.3

               If quiz 1 is A, quiz 2 is A, homework assignment is A, then course is A.+,

            Rules can be weighted. The confidence value for a rule is determined as usual by
        finding the smallest rule antecedent. Before applying this value to the consequents for the
        rule, the value is multiplied by a fraction from zero (rule disabled) to $FF (rule fully
        enabled). The resulting modified confidence value is then applied to the fuzzy outputs,
        Equation (19) illustrates that the output for a set of rules is the output Sj for each rule
        times a weight Fj, divided by the sum of the weights.
            The rules can reflect nonlinear, but deterministic, relationships. For instance, if a
        student gets a B on the first quiz and an A on the second quiz, the instructor may decide
        that the course grade is A-, but if a student gets an A on the first quiz and a B on the
        second quiz, the instructor may decide that the course grade is B+. But if the student also
        did poorly in lab work, then the course grade might be B-, to give the student some
        incentive to get to work. That is, if quiz 1 is A, quiz 2 is B, and lab is not C, then
        course is B+, but if quiz 1 is A, quiz 2 is B, and lab is C, then course is B-. In the
        limit, if there are n input variables and each input variable is associated with m linguistic
        *
        * Fuzzification step:
        *
        FUZZIFY:      LDX    #INPUT_MFS         ;Point at member function definitions
                      LDY    #FUZ_INS           ;Point at fuzzy input vector
                      LDAA   CURRENT__INS       ;Get first input value
                      LDAB #7                   ;7 fuzzy values per input
        GRADJLOOP: MEM                          ;Evaluate a member function
                      DBNE   B,GRAD_LOOP        ;For 7 labels of 1 input
                      LDAA CURRENT_INS+1        ;Get second input value
                      LDAB #7                   ;7 fuzzy values per input
        GRAD_LOOP 1: MEM                        ;Evaluate a member function
                      DBNE   B,GRAD_LOOP1       ;For 7 fuzzy values of 1 input
        * Rule Evaluation step:
                      LDAB #7                   ;Loop count
        RULE_EVAL: CLR       1,Y+               ;Clr a fuzzy out & inc ptr
                      DBNE   B,RULE_EVAL        ;Loop to clr all fuzzy Outs
                      LDX    #RULE_START        ;Point at first rule element
                      LDY    #FUZ_INS           ;Point at fuzzy ins and outs
                      LDAA #$FF                 ;Init A (and clears V-bit)
                      REV                       ;Process rule list
        * Defuzzification step:
        DEFUZ s       LDY    #FUZ_OUT           ;Point at fuzzy outputs
                      LDX    #SGLTN_POS         ;Point at singleton positions
                      LDAB #7                   ;7 fuzzy outs per COG output
                      WAV                       ;Calculate sums for weighted av
                      EDIV                      ;Final divide for weighted av
                      TFR    Y,D                ;Move result to accumulator D
                      STAB   COG_OUT            ;Store system output

                            Figure 7.23. A Fuzzy Inference Kernel
   231   232   233   234   235   236   237   238   239   240   241