Design and Implementation of Real Time
                DC Motor Speed Control using Fuzzy Logic

                           Waleed Abd El-Meged El-Badry
                                 Mechatronics Department
                               Faculty of Engineering, MUST
                                  wbadry@must.edu.eg
                                       3rd June, 2008


Abstract
        In this paper, we try to implement a fuzzy logic controller (FLC) for DC motor
        using Laptop, tower or industrial PC. The feedback is taken via tachometer
        connected directly to motor of interest by coupling. Interfacing between PC and
        DC Motor-Tachometer is done using NI USB 6008 and additional signal
        conditioning circuitry. This system could assist students and novices to evaluate
        rapidly Fuzzy Logic concepts and application using this low cost case study.

1. Introduction
        Speed control of DC motors has been one of the crucial topics in Mechatronics
        engineering, starting from simple Cartesian Robots, to giant industries such as
        steel where maintaining motor speed of rollers affects drastically the shape of
        rolled bars[1-2]. Due to non linearity of DC motors, designing control system
        based on system identification is difficult and all system parameters are
        approximated [2].

        The heuristic knowledge based system, Fuzzy Logic proved to have the flexibility
        of modelling nonlinear systems with fair or no knowledge of systems
        identification. As the fuzzy logic core is based on “how people can do it”, many
        legacy control systems are nowadays converted to be “fuzzy based systems” for
        ease of maintenance and enhancement.

        Fuzzy Logic Controllers can be practically implemented using several techniques,
        using Microcontroller [3] where all fuzzy rules are placed by means of assembly
        language, or a FL chip that is configurable using accompanying software, and
        finally using PC where education mainly takes place in development process.




    1
2. Motivation
        Several reasons were beyond selection of this implementation, these are
        summarised below:
         Development of Class Library can be utilised by students to develop fuzzy
           logic systems easily with any .NET language (C#, VB, C++, Delphi and COBOL).
           This would enable many students whose skills are in one or more of the
           preceded languages rather than compulsory knowledge of MATLAB.
         Implementing knowledge gained from “Fuzzy Logic” course tutored.
         Studying the impact of fuzzy controller designed in real time environment.

3. Project Framework
        DC motor speed control was inspired by an article entitled “Fuzzy Logic for Plain
        Folks. Fig. 1 illustrates the proposed circuit connection [4].




                              Fig. 1 Proposed Circuit Connection

        The proposed system can be summarised in the below block diagram

                                         Knowledge Base

                         Fuzzification     Fuzzy Rules        Defuzzification

                                          Computer
         BJT Amplifier
                                           Coupling
                  D/A               M                     T                A/D

                          Fig.2 DC Motor Speed Control Block Diagram



    2
4. Project Setup
  Two Identical DC motor were used to implement the project (one as DC motor and
  the other works as tachometer), they are Toshiba 24V, 1.5A and Maximum of 180
  RPM. Other parameters were obtained experimentally. The NI USB 6008 has built in
  12 bits Analogue to Digital converter that can generate output voltage from 0- 5V
  with maximum sourcing current of 150 mA. It also has a 0-10V, 12 bits Analogue to
  Digital converter that were sufficient to measure the tachometer voltage directly.

  Additional Circuit were used to accomplish two objectives, to start with, to amplify
  the output analogue voltage generated from USB D/A from 0-5V into 0-12V, and
  secondly, to supplement the DC Motor with current necessary that USB device can’t
  afford. The figure shown illustrates how these problems were tackled by using
  TIP41C NPN transistor with variable resistor for tuning [5]. Value of resistance were
  evaluated experimentally
                                                                                +12V




         Fig. 3 Mapping 0-5V 150mA into
                                                                                   Q1
                 0-12V 2A Circuit                                      43%
                                                                                   TIP41

             (Created Using Proteus VSM)               From USB 6008




5. Experimental Work
  Common-Emitter BJT amplifier described in preceded section has a nonlinear
  relationship between Base Voltage (Vb) and Collector Voltage (Vc), the below chart
  describes the relation between output USB analogue voltage (0-5V) from NI USB
  6008 and Actual applied DC Motor voltage after amplification stage. The chart was
  drawn by applying different voltages from USB Card and measuring the
  corresponding applied voltage on DC motor simultaneously.




    3
Fig. 3 Relationship between PC output voltage and Actual Applied Motor Voltage

     Below 2V, “dead zone” is observed due coupling weight and friction, meanwhile,
     saturation takes place after 4V.

     Same procedure were followed to obtain chart depicts the DC Motor-
     Tachometer Relationship. The below figure yields the experimental results:

                                        9
     Tachometer Corresponding Voltage




                                        8



                                        7
                                                                                     Experimental Data
                                                                                     Trend Line
                                        6



                                        5



                                        4



                                        3
                                            6   7   8      9            10      11    12                 13
                                                        Applied Motor Voltage

                       Fig. 4 Motor-Tachometer Relationship
     Data obtained experimentally from both charts were added to “the knowledge
     base“was stored on software program to be utilised lately in implementation,
     data between points were extracted using interpolation. Charts were generated
     plotted using MATLAB.




 4
6. Fuzzy Variables and Rules
   Two fuzzy variables were used based on knowledge base:
   a- Input: Speed in (RPM) that maps current RPM and Desired RPM. Speed is
      normalised.




                               Fig. 5 Input Membership Functions

   b- Output: Output Voltage (V) for DC Motor. Voltage is normalised as well.




                              Fig. 6 Output Membership Functions

        The first and last fuzzy terms holds greater range from the universe of discourse
        for “fast response”, the other fuzzy terms were tuned by trial and error.




    5
Five fuzzy rules were used which maps each input linguistic value to and output
         linguistic peer as follows
                         If Speed is Very Slow then Speed Up Motor        (1)
                         If Speed is Slow then Slightly Speed Up Motor    (2)
                         If Speed is About Right then No Change Motor     (3)
                         If Speed is Fast then Slightly Slow Down Motor   (4)
                         If Speed is Very Fast then Slow Down Motor       (5)



7. Results and Conclusion
   The Fuzzy Logic Class Library was developed using Microsoft Visual Studio 2008. The
   library can be used for implementation of both Mamdani and Takagi-Sugeno Fuzzy
   Systems with both triangular and trapezoidal membership functions. A simple
   software were created for testing purposes to compare results with another made
   with MATLAB




                           Same result were
                           obtained using MATLAB
                           and developed fuzzy logic
                           library by researcher




            Fig. 7 Same result yielded by both MATLAB and developed Class Library

Fuzzy Variables and rules for DC motor control were programmed using Visual Basic
2008.




     6
Code Snippet 1 Formulation of Membership functions




                       Code Snippet 2 Formulation of Fuzzy Rules

The preceded code snippets were captured from the source code for case study;
researcher succeeded to obtain “user friendly” class library that is expected to be easily
comprehended by students.

A software were developed to control Motor Speed at 45 RPM, the below curve depicts
the fuzzy logic controller step input response.




                     Fig. 8 Screenshot from the developed software

     7
Fig. 9 Motor Response at Set Point 45 RPM
8. References
  1- Thiang and Andru Hendra, “Remote Fuzzy Logic Control System For a DC Motor
     Speed Control”, Jurnal Teknik Elektro Vol. 2, No. 1, Maret 2002: 8 – 12
  2- Bogumila Mrozek and Zbigniew Mrozek, “Modelling and Fuzzy Control of DC
     Drive”, 14-th European Simulation Multiconference ESM 2000, May 23-26,
     Ghent, pp186-190
  3- Yodyium Tipsuwan, “Fuzzy Logic Microcontroller Implementation for DC Motor Speed
     Control” .
  4- http://www.Fuzzy-Logic.com
  5- Jan Axelson, “Parallel Port Complete”, 2nd Ed., Lakeview Research.




    8

Design and Implementation of DC Motor Speed Control using Fuzzy Logic

  • 1.
    Design and Implementationof Real Time DC Motor Speed Control using Fuzzy Logic Waleed Abd El-Meged El-Badry Mechatronics Department Faculty of Engineering, MUST wbadry@must.edu.eg 3rd June, 2008 Abstract In this paper, we try to implement a fuzzy logic controller (FLC) for DC motor using Laptop, tower or industrial PC. The feedback is taken via tachometer connected directly to motor of interest by coupling. Interfacing between PC and DC Motor-Tachometer is done using NI USB 6008 and additional signal conditioning circuitry. This system could assist students and novices to evaluate rapidly Fuzzy Logic concepts and application using this low cost case study. 1. Introduction Speed control of DC motors has been one of the crucial topics in Mechatronics engineering, starting from simple Cartesian Robots, to giant industries such as steel where maintaining motor speed of rollers affects drastically the shape of rolled bars[1-2]. Due to non linearity of DC motors, designing control system based on system identification is difficult and all system parameters are approximated [2]. The heuristic knowledge based system, Fuzzy Logic proved to have the flexibility of modelling nonlinear systems with fair or no knowledge of systems identification. As the fuzzy logic core is based on “how people can do it”, many legacy control systems are nowadays converted to be “fuzzy based systems” for ease of maintenance and enhancement. Fuzzy Logic Controllers can be practically implemented using several techniques, using Microcontroller [3] where all fuzzy rules are placed by means of assembly language, or a FL chip that is configurable using accompanying software, and finally using PC where education mainly takes place in development process. 1
  • 2.
    2. Motivation Several reasons were beyond selection of this implementation, these are summarised below:  Development of Class Library can be utilised by students to develop fuzzy logic systems easily with any .NET language (C#, VB, C++, Delphi and COBOL). This would enable many students whose skills are in one or more of the preceded languages rather than compulsory knowledge of MATLAB.  Implementing knowledge gained from “Fuzzy Logic” course tutored.  Studying the impact of fuzzy controller designed in real time environment. 3. Project Framework DC motor speed control was inspired by an article entitled “Fuzzy Logic for Plain Folks. Fig. 1 illustrates the proposed circuit connection [4]. Fig. 1 Proposed Circuit Connection The proposed system can be summarised in the below block diagram Knowledge Base Fuzzification Fuzzy Rules Defuzzification Computer BJT Amplifier Coupling D/A M T A/D Fig.2 DC Motor Speed Control Block Diagram 2
  • 3.
    4. Project Setup Two Identical DC motor were used to implement the project (one as DC motor and the other works as tachometer), they are Toshiba 24V, 1.5A and Maximum of 180 RPM. Other parameters were obtained experimentally. The NI USB 6008 has built in 12 bits Analogue to Digital converter that can generate output voltage from 0- 5V with maximum sourcing current of 150 mA. It also has a 0-10V, 12 bits Analogue to Digital converter that were sufficient to measure the tachometer voltage directly. Additional Circuit were used to accomplish two objectives, to start with, to amplify the output analogue voltage generated from USB D/A from 0-5V into 0-12V, and secondly, to supplement the DC Motor with current necessary that USB device can’t afford. The figure shown illustrates how these problems were tackled by using TIP41C NPN transistor with variable resistor for tuning [5]. Value of resistance were evaluated experimentally +12V Fig. 3 Mapping 0-5V 150mA into Q1 0-12V 2A Circuit 43% TIP41 (Created Using Proteus VSM) From USB 6008 5. Experimental Work Common-Emitter BJT amplifier described in preceded section has a nonlinear relationship between Base Voltage (Vb) and Collector Voltage (Vc), the below chart describes the relation between output USB analogue voltage (0-5V) from NI USB 6008 and Actual applied DC Motor voltage after amplification stage. The chart was drawn by applying different voltages from USB Card and measuring the corresponding applied voltage on DC motor simultaneously. 3
  • 4.
    Fig. 3 Relationshipbetween PC output voltage and Actual Applied Motor Voltage Below 2V, “dead zone” is observed due coupling weight and friction, meanwhile, saturation takes place after 4V. Same procedure were followed to obtain chart depicts the DC Motor- Tachometer Relationship. The below figure yields the experimental results: 9 Tachometer Corresponding Voltage 8 7 Experimental Data Trend Line 6 5 4 3 6 7 8 9 10 11 12 13 Applied Motor Voltage Fig. 4 Motor-Tachometer Relationship Data obtained experimentally from both charts were added to “the knowledge base“was stored on software program to be utilised lately in implementation, data between points were extracted using interpolation. Charts were generated plotted using MATLAB. 4
  • 5.
    6. Fuzzy Variablesand Rules Two fuzzy variables were used based on knowledge base: a- Input: Speed in (RPM) that maps current RPM and Desired RPM. Speed is normalised. Fig. 5 Input Membership Functions b- Output: Output Voltage (V) for DC Motor. Voltage is normalised as well. Fig. 6 Output Membership Functions The first and last fuzzy terms holds greater range from the universe of discourse for “fast response”, the other fuzzy terms were tuned by trial and error. 5
  • 6.
    Five fuzzy ruleswere used which maps each input linguistic value to and output linguistic peer as follows If Speed is Very Slow then Speed Up Motor (1) If Speed is Slow then Slightly Speed Up Motor (2) If Speed is About Right then No Change Motor (3) If Speed is Fast then Slightly Slow Down Motor (4) If Speed is Very Fast then Slow Down Motor (5) 7. Results and Conclusion The Fuzzy Logic Class Library was developed using Microsoft Visual Studio 2008. The library can be used for implementation of both Mamdani and Takagi-Sugeno Fuzzy Systems with both triangular and trapezoidal membership functions. A simple software were created for testing purposes to compare results with another made with MATLAB Same result were obtained using MATLAB and developed fuzzy logic library by researcher Fig. 7 Same result yielded by both MATLAB and developed Class Library Fuzzy Variables and rules for DC motor control were programmed using Visual Basic 2008. 6
  • 7.
    Code Snippet 1Formulation of Membership functions Code Snippet 2 Formulation of Fuzzy Rules The preceded code snippets were captured from the source code for case study; researcher succeeded to obtain “user friendly” class library that is expected to be easily comprehended by students. A software were developed to control Motor Speed at 45 RPM, the below curve depicts the fuzzy logic controller step input response. Fig. 8 Screenshot from the developed software 7
  • 8.
    Fig. 9 MotorResponse at Set Point 45 RPM 8. References 1- Thiang and Andru Hendra, “Remote Fuzzy Logic Control System For a DC Motor Speed Control”, Jurnal Teknik Elektro Vol. 2, No. 1, Maret 2002: 8 – 12 2- Bogumila Mrozek and Zbigniew Mrozek, “Modelling and Fuzzy Control of DC Drive”, 14-th European Simulation Multiconference ESM 2000, May 23-26, Ghent, pp186-190 3- Yodyium Tipsuwan, “Fuzzy Logic Microcontroller Implementation for DC Motor Speed Control” . 4- http://www.Fuzzy-Logic.com 5- Jan Axelson, “Parallel Port Complete”, 2nd Ed., Lakeview Research. 8