Controle de velocidade do motor DC com microcontrolador 8051 (89c51,89c52) usando técnica PWM e driver de motor l293d

DC motor speed control with 8051 microcontroller (89c51,89c52) using PWM technique and l293d motor driver

This is a simple project/tutorial on how to control DC motor speed using 8051 (89c51,89c52) microcontroller. The speed of the DC motor or fan is controlled using Pwm (Pulse Width Modulation) technique. There are two ways to generate pulse width modulation signal using 8051 (89c51,89c52) microcontrollers. You can generate it using 8051 microcontroller timers (89c51,89c52) OR you can switch a specific pin (high and low) so quickly with some arbitrary delay in switching, that a pulse is generated as output on the pin. The best and easiest controlled way to generate PWM signal is using internal timers of 89c51 microcontroller and in this project I will generate PWM using timers of 8051 microcontroller (89c51,89c52).
PWM, in simple words, changes the output voltage at a specified pin to which it is applied by varying the duty cycle of the output waveform. The frequency and duty cycle of PWM signal can be easily varied using 8051 microcontroller timers . The figure below will enlighten you about PWM signals and duty cycle. The duty cycle of the original signal varies in the diagram below.
PWM signal

PWM signal

What exactly is the duty cycle?

The duty cycle is the time during which the output signal remains high for a wave period. Period is the total time/duration of a single wave/clock cycle. Hence, the duty cycle is the time/duration in a single clock cycle during which the output remains high.
Duty cycle

Duty cycle

Motor speed control with 8051 microcontroller – Project requirements

  • 8051 Microcontroller(89c51 or 89c52)
  • Crystal (11.0592 MHz)
  • Capacitors 2 (33pf)
  • 9 push buttons
  • DC Motor – Fan (small toy motor)
  • Power supply (5v)
  • L293D (DC motor driver)

Photograph

I am generating PWM signal of different duty cycles 00%, 10%, 20%, 50%, 80% and 90%. 200 knots is my base. For an 80% duty cycle, my delay is 160 knots. PWM for delays greater than 200 us are also generated 500 us, 800 us and 1000 us.

Now, how to generate these delays using 8051 microcontroller timers (89c51,89c52)? There are two timers in 89c51 microcontroller, Timer-0 and Timer-1. You can use them for delay purposes or to count an event, etc. You can use these timers in four modes. I'm using them in 16-bit mode. To learn more about timers, their modes and initialization follow the tutorial

  • 8051(89c52,89c51) Microcontrol Timers

8051(89c52,89c51) are 8-bit microcontrollers. But you can use your timers as 16 bits. To load 16-bit values ​​into timers you use two registers THx and TLx associated with the timers. Where THx represents Timer High Byte and TLx represents Timer Low Byte (Note x is 0 or 1 depending on the timer you want to use). Here I am using Timer-0, so I will use registers TH0 and TL0.

My base duty cycle is 200 us which means at 100 us the duty cycle will be 50%. 50% duty cycle means that the positive and negative signals have the same length (time). You can see two (digital) sine waves with duty cycles of 50% and 75% in the figure on the left. Notice the difference between the two waves.

I calculated the delay for 00, 20 us, 40 us, 100 us, 160 us, 180 us, 500 us, 800 us and 100 us and loaded the values ​​obtained by the result into the TH0 and TL0 registers. The formulas for calculating delay are given below with an example.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.