Advertisement

When S1 is pressed, the microcontroller sends low logic to port pin P2.5. The high output of inverter N2 drives transistor T1 into saturation and relay RL1 energises. So the output of NE555 is fed to inputs IN1 and IN2 of L293D through both the contacts of relay RL2. Now at the same time, after RL1 energises, the microcontroller starts generating PWM signal on port pin P2.4, which is fed to trigger pin 2 of NE555 through inverter N3. The base frequency of the generated PWM signal is 500 Hz, which means the time period is 2 ms (2000μs). The output pulse width varies from 500 μs to 1500μs. The R-C time constant of the monostable multivibrator is kept slightly less than 500 μs to generate exactly the same inverted PWM as is generated by the microcontroller.

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 S3 is pressed again, 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 S4 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

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.

Download PCB and component layout PDFs: click here

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.

8. ‘dectime’ function is the same as ‘inctime’ but it decreases reversible time by one second.

Delay

It uses the following functions:

1. ‘keydly’ function generates a fix delay of around 50 ms for key debouncing.

2. ‘delay’ function generates a variable delay by timer 0. The basic delay is of 100 μs. It is rotated in loop from five to 15 times to generate minimum 500μs and maximum 1500μs delay.

3. ‘time’ function again generates a variable delay by timer 1. The basic delay is of 50 ms. It is rotated in multiples of 20 from 20 to 180 to generate minimum 1-second and maximum 9-second delay.

EFY note. The source code and other relevant files of this article are included in the link below:

Download source code: click here


This article was first published in June 2009 and is recently updated.

Advertisement


6 COMMENTS

  1. The entire circuit does not contain, apparently, a feed back arrangement to govern RPM of, and Power applied to the dc motor, in case of sudden load variation, either side.
    Will be grateful, if a fellow in line exhibits some practical solutions, either with back-emf of the motor and/or with shaft-speed counter of the motor, please.

SHARE YOUR THOUGHTS & COMMENTS

Please enter your comment!
Please enter your name here