Saturday, April 20, 2024

AT89C51 Based DC Motor Controller

When switch S2 is pressed, port-pin P2.5 goes high and RL1 de-energises to stop the motor.

When switch S3 is pressed, relay RL2 energises. Pin IN1 of motor driver L293D receives the PWM signal and pin IN2 connects to ground. As a result, the motor rotates in one direction (say, clockwise).

When switch S4 is pressed, relay RL2 de-energises. Pin IN2 of motor driver L293D receives the PWM signal and pin IN1 connects to ground. The motor now rotates in opposite direction (anti-clockwise).

When switch S3 is pressed, different modes are selected in cyclic manner as given below:

1. Continuous mode. The motor rotates continuously with the set speed in either direction

- Advertisement -

2. Reversible mode. The motor reverses automatically after the set time

3. Jogging mode. The motor rotates for the set time in either direction and then stops for a few seconds and again rotates for the set time. It is also called ‘pulse rotation’

Switches S5 and S6 are used to set the speed of the motor, either in increasing order or decreasing order, in continuous mode only. Switches S7 and S8 are used to set the time either in increasing order or decreasing order.

- Advertisement -

Software

The program is written in ‘C’ language and compiled using Keil μVision3 compiler. It is well commented and easy to understand. The program has three major sections: initialisation and key press, display and motor control.

Initialisation and key press. It consists of the main function that initialises timers, ports, LCD module and LED indication and then waits for key press. When any key is pressed, the program calls that particular function.

In the main function, first the ports are initialised as input/ output, then the LCD is initialised and cleared. At power-on reset or manual reset, message “DC motor controller” is displayed on the LCD and LED1 through LED4 turn off. When start switch S1 is pressed, message “Motor Start” is displayed for a second, and then the mode and current speed are displayed. Run LED and clockwise-direction LED are ‘on.’ Now the program waits for key press. When any key is pressed, the program jumps to one of the functions (start, direction, mode, etc).

Display. It uses the following functions:

1. ‘writecmd’ function sends command byte to the LCD. It takes one argument byte and sends it to P0.
2. ‘writedata’ function sends data byte to be displayed on the LCD. It also takes one argument byte and sends it to P0.
3. ‘writestr’ function writes the whole string (message) on the LCD. It takes pointer as an argument that points address of the first character of the string, then through the pointer it sends all the characters one by one to P0.
4. ‘busy’ function checks the status of the busy flag of the LCD. If the flag is set, the LCD is not ready and the program remains within the loop. When the flag is reset, the LCD is ready and the program comes out of the loop.

Motor control. It uses the following functions:

1. ‘start’ function starts motor rotation in one of the modes (continuous, reversible or jogging). The mode is selected by mode-selection flag ‘m.’ As explained earlier, in continuous mode the motor keeps rotating with the set speed. In reversible mode, the motor changes direction automatically after the set time. In jogging mode, the motor rotates for the set time, stops for a few seconds and then rotates.
2. ‘stop’ function stops rotating the motor and displays the message on the LCD module. This is indicated by glowing of the stop LED.
3. ‘direction’ function increments the counter by ‘1’ every time and checks whether the count is even or odd. If the count is even, it selects clock-wise direction, and if the count is odd, it selects anticlockwise direction. This is also indicated on direction CLK and ACLK LEDs.
4. ‘mode’ function changes modes in cyclic manner. It increases mode-selection flag ‘m’ every time. If m=0 it selects continuous mode, if m=1 it selects reversible mode and if m=2 it selects jogging mode. If m=3 it is reset to ‘0’ again and selects continuous mode and likewise.
5. ‘incspeed’ function increases the width of the pulse by 100 μs. The generated PWM is of 500 Hz. That means total time is 2 ms=2000 μs. The width of the pulse is varied from 500 μs to 1500 μs in steps of 100 μs. To display the speed, the variable is first converted into speed factor ‘1’ to ‘9’ and then into ASCII.
6. ‘decspeed’ function is the same as ‘incspeed’ but here the width of the pulse is decreased by 100 μs.
7. ‘inctime’ function increases the reversible time of the motor by one second. It increases the variable in multiples of 20. To display it on the LCD module, it is first divided by 20 and then converted into ASCII.

4 COMMENTS

SHARE YOUR THOUGHTS & COMMENTS

Unique DIY Projects

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components

Calculators

×