|
~: DC Motor Control with VC++ :~
Abstract:- The above project was dos based and now this is window based program written in Visual C++ to control DC motor. Very efficient, effective more user friendly software. Let us see the main function as well as the additional features of this application.
-
Totally windows based application so very powerful GUI. More user friendly program
-
Mouse as well as keyboard interface provided. All the controlling actions at your fingertips
-
Four degree of motion control is achieved for single motor. (1) Motor rotates continuously at constant speed (2) pulse wise rotation means motor rotates for less then one revolution (3) motor rotates with desired speed for fix duration of time (4) motor rotates till mouse button is pressed and moved.
-
One can vary both the parameters of motor speed and direction
-
DC motor will rotate like stepper motor in pulse wise rotation mode
_____________________________________________
General Description:-
Again there are two parts of the project (1) hardware part (2) software part. The hardware part remains same used in previous project only change in software part and that is instead of C++ now it is build using VC++. All the function of previous project are included here (like direction change, speed increase/decrease) and also some additional features are included like pulse wise rotation.
Hardware Part:-
Same H-Bridge circuit is used as a DC motor driver and it is connected with LPT port. Connections, operation, working all thing remains same. The figure given below will tell you
everything. If you want more about this then click here
Software Description:-
Complete software is built on the platform of visual C++ programming language. So one must be familiar with VC++ if he wants to develop this project. He must be knowing all the tools, commands as well as operating of VC++. I am explaining a step by step procedure to develop this application so that one can (even a newvoice) build it very easily. Follow the step by step procedure to build an application
-
Open a file menu and click on new tab
-
Choose project tag and select MFC appwizard standard exe
-
Give a suitable name of project like "DCMC" or any else
-
In the first step chose dialog based application
-
In the second step uncheck 3D controls and ActiveX control boxes
-
Give suitable title of dialog based application like "DC Motor Control".
-
Leave all the options on third step as it is
-
In the last step you will see that VC++ has created two classes for your dialog based application named 'CDCMCApp' & 'CDCMCDlg'. Leave these name as it is and click finish tab. Finally summary of all the details will appear then click OK button.
-
You will see VC++ has created standard dialog based exe and you will see this screen shot

On right hand side you will see application background with two buttons and one text message. On the left hand side you will find three viewing tags class view, resource view & file view. By default you will be in resource view tag. Now the first thing you have to do is to modify the application as per our requirement. So delete both the buttons and the text message and insert the items and set their property as given in table. We shall add 8 push buttons, 1 group box, 1 edit box and last 1 static text. You can add all these using control toolbar. To set the property just right click on any object (button, group box etc.) and choose property from popup menu.
| Sr. No. |
Object |
Property |
Setting |
| 1 |
Button |
ID |
IDC_FWD |
| Caption |
Start &Forward |
| 2 |
Button |
ID |
IDC_REW |
| Caption |
Start &Reverse |
| 3 |
Button |
ID |
IDC_UP |
| Caption |
Speed &Up |
| 4 |
Button |
ID |
IDC_DWN |
| Caption |
Speed &Down |
| 5 |
Button |
ID |
IDC_FRW |
| Caption |
F&orward |
| 6 |
Button |
ID |
IDC_RWS |
| Caption |
R&everse |
| 7 |
Button |
ID |
IDC_STP |
| Caption |
&Stop |
| 8 |
Button |
ID |
IDC_XIT |
| Caption |
E&xit the program |
| 9 |
Static text |
ID |
IDC_STATIC |
| Caption |
Speed Factor |
| 10 |
Edit box |
ID |
IDC_SF |
| Caption |
0 |
| 11 |
Group Box |
ID |
IDC_STATIC |
| Caption |
Motor rotate continuously at constant speed |
| |
|
|
|
After setting the properties of all these 11 objects build and run the application our application will look like

Uptill now we haven't done any coding but now the coding part will start. You have to attach a function with each button. For this open class wizard from view menu. Follow the steps
-
Select the button ID like "IDC_FWD" or any other and click on BN_CLICKED event
-
Then press add function button. A message box will appear with name of function. leave it as it is and click OK. You will be diverted in source code to this edit function.
-
Right now don't edit but follow the same procedure and attach function to each button.
-
Now you have to attach a variable to edit box. For this again open class wizard and select member variable tag.
-
You will find all the IDC will appear in dialog box. Select IDC of edit box ' IDC_SF '.
-
Now click add member variable button. Second dialog box will appear. Give the name of variable as "m_speedfact". In a category choose value and in type choose CString click ok.
-
Now select class view tag. Right click on CDCMCDlg class and choose add member variable from popup menu. Specify int as variable type and give a name m_sf. choose private access for this variable.
-
Finely open DCMCDlg.cpp file and move to the top of file. Define variable a of type int above the class CAboutDlg starts.
-
Finely edit code of all function as given in program code page given at the end
Refer the table given below to know the application of each function in program
|
Sr.No. |
Function name |
Application |
|
1 |
OnXit |
Used to quit the application |
|
2 |
OnUp |
Used to increase speed by 5 |
|
3 |
OnDwn |
Used to decrease speed by 5 |
|
4 |
OnFwd |
Rotate a motor in forward direction for 5 second with desired speed |
|
5 |
OnRev |
Rotate a motor in reverse direction for 5 second with desired speed |
|
6 |
OnFwrd |
Starts rotating motor in forward direction at constant speed |
|
7 |
OnRe |
Starts rotating motor in reverse direction at constant speed |
|
8 |
OnStop |
Stops rotating motor |
These all are main features of program like speed increase or decrease rotate motor forward or reverse or stop the motor etc. Now we shall talk about additional features that are not included in DOS version. And these are pulse wise rotation and rotation of motor till mouse button is pressed and moved. For these additional features we have to add extra functions. These functions are
-
OnLButtonDown
-
OnRButtonDown
-
OnMouseMove
To add these three function you have to again open class wizard and choose Object ID CDCMCDlg. You will see number of messages in near dialog box. Scroll to down and find out WM_LBUTTONDOWN event. Select is and click on to ' add function ' button. OnLButtonDown function will be generated and you will be told to edit it's code. Right now don't edit the code but do the same procedure to add next two function with WM_RBUTTONDOWN & WM_MOUSEMOVE events.
Now modify the code as as given in program code page given at the end
| Sr.No. |
Function Name |
Description |
| 1 |
OnLButtonDown |
It is used to rotate motor pulse wise in forward direction |
| 2 |
OnRButtonDown |
It is used to rotate motor pulse wise in reverse direction |
| 3 |
OnMouseMove |
When you move the mouse with pressing left button motor will rotate forward till button is pressed. Same way with right button pressed moving a mouse will rotate motor reverse. |
After finishing all these build and run the application. Connect the LPT port with hardware circuit. Connect the DC Motor and switch on the supply. Now observe whether all the functionalities are working or not !!!!!!! ??????
click here for program code |