SLAA235A February   2005  – August 2018 MSP430F147 , MSP430F147 , MSP430F148 , MSP430F148 , MSP430F149 , MSP430F149

 

  1.   Fuzzy Logic Motor Control With MSP430™ MCUs
    1.     Trademarks
    2. 1 Background Information
      1. 1.1 Fuzzification
      2. 1.2 Fuzzy Inference
      3. 1.3 Centroid Calculation Defuzzification Method
    3. 2 Hardware Description
    4. 3 Software Description
    5. 4 References
  2.   Revision History

Software Description

The software performs these operations:

  1. Configures the MCU clock system
  2. Configures the peripherals
  3. Uses Timer_A to determine the actual motor speed.
    1. The rising edge of the CCI0B input (port pin P2.2) triggers capture events with Timer_A capture/compare block 0.
    2. In the associated ISR function, the precise, hardware-generated timestamp is read and processed.
    3. After passing this value through an 8-tap moving average filter, the newly calculated speed value is then stored in the global variable CurrentSpeed.
    4. Capture/compare block 1 is configured to compare mode and used to provide a time-out mechanism for the speed measurement.
    5. This timeout is needed if the motor is not running, because no capture events would be generated, and the software would wrongly assume that the motor is still running. However, this timeout updates the global variable CurrentSpeed, and the control algorithm continues to work. Timer_A is operated in continuous mode to avoid that any software latency affects the measurements.

    6. Capture/compare block 2 of Timer_B is configured to compare mode and used for PWM signal generation.
    7. Timer_B is operated in up mode and driven by the 8-MHz clock source. With the period register set to 3999, the effective PWM output frequency is 8 MHz / (3999 + 1) = 2 kHz. This frequency gives a fine granularity to adjust the motor power, resulting in a smoother control. For this application, the capture/compare block selection of Timer_A and Timer_B is arbitrary.

      For detailed information on timer configuration and operation, see the MSP430x1xx Family User’s Guide.

  4. Configures the MSP430 watchdog timer (WDT) module as interval timer. Its associated ISR function is called 244 times per second and wakes the CPU from low-power mode LPM0. This mechanism provides the time interval between each control cycle.
  5. Enters the control loop. Immediately upon entering, the MCU enters LPM0 to turn off the CPU and stop program execution while waiting for the wakeup from the WDT ISR.
  6. On wakeup, calculates the absolute and differential control loop errors Error and dError based on target speed (variable SetSpeed), current speed (variable CurrentSpeed), and the previous error value (variable LastError).
  7. The function Fuzzification() transforms these error values into fuzzy vectors X1[ ] and X2[ ].
  8. The fuzzy inference rules are applied, and the function FuzzyInference() generates the fuzzy output vector Y[ ].
  9. The function Defuzzification() transforms this output vector back into a single control loop output value that is added to the current PWM duty cycle. This process closes the control loop.
  10. The two definitions PWM_Min and PWM_Max are used to limit the motor duty cycle and may need to be adjusted depending on the application and load conditions.

For a discussion of the fuzzy algorithms, see Section 1.

Figure 7 and Figure 8 show example motor startup operations using the test setup developed to verify this application report. The motor target speed is set to 50 rotations per second. The graphs show the startup without a mechanical load and with a mechanical load.

fig07_slaa235.gifFigure 7. Motor Startup (No Load)
fig08_slaa235.gifFigure 8. Motor Startup (Loaded)