DC Motor Speed control using 8051
|In this blog we will see how to control speed of DC motor using 8051 controller. We can develop sophisticated code using the timers present in the 8051, but here i will be using simple delay to generate the PWM.
System description
The functions are very simple, we have 2 buttons to control the motor directions , 2 buttons to stop the motor ( we can achieve this with a single button as well) and 2 more buttons to control the speed.
The state of the system will be displayed on LCD (you can use any LCD library compatible with 8051 ,you might need to change some function signatures in the main.c or in your LCD library).
Code organization
We have infinite loop in which we are generating the PWM pulse, at the end of each loop we will check if any button is pressed on the keyboard. Here we are using polling method to find if any button is pressed, instead one can use the interrupts to find the button press.
checkKeyBoard() method handles the button press and display appropriate information on the LCD. This function also calls the motor control functions according to the button pressed.