Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

DC Motor Control with VC++

By Ashutosh Bhatt

 

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.

1) Totally windows based application so very powerful GUI. More user friendly program

2) Mouse as well as keyboard interface provided. All the controlling actions at your fingertips

3) 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.

4)One can vary both the parameters of motor speed and direction

5) 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 & Software Description

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 in circuit tab 1 will tell you everything.

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 new voice) build it very easily. Follow the step by step procedure to build an application

A) Open a file menu and click on new tab

B) Choose project tag and select MFC app wizard standard exe

Visual C++ Dialog Box

C) Give a suitable name of project like “DCMC” or any else

D) In the first step chose dialog based application

E) In the second step uncheck 3D controls and ActiveX control boxes

F) Give suitable title of dialog based application like “DC Motor Control”.

G) Leave all the options on third step as it is

H) In the last step you will see that VC++ has created two classes for your dialog based application named ‘CDCMCApp’ & ‘CDCMCDlg’. Leave these names as it is and click finish tab. Finally summary of all the details will appear then click OK button.

I) You will see VC++ has created standard dialog based exe and you will see this screen shot

Constant speed remote motor

 

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

 

 

 

 

 Software Description contd..

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

  1. Select the button ID like “IDC_FWD” or any other and click on BN_CLICKED event
  2. 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.
  3. Right now don’t edit but follow the same procedure and attach function to each button.
  4. Now you have to attach a variable to edit box. For this again open class wizard and select member variable tag.
  5. You will find all the IDC will appear in dialog box. Select IDC of edit box ‘ IDC_SF ‘.
  6. 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.
  7. 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.
  8. Finely open DCMCDlg.cpp file and move to the top of file. Define variable a of type int above the class CAboutDlg starts.
  9. 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

  1. OnLButtonDown
  2. OnRButtonDown
  3. 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  !!!!!!! ??????  

 

 

Project Source Code

 

Project Source Code

 ###


void CTest2Dlg::OnXit() 

 

     {
         // TODO: Add your control notification handler code here
             int r;
             r = _outp(0x0378,0x00);
             OnOK();
     }
 void CTest2Dlg::OnUp() 
     {
         // TODO: Add your control notification handler code here
             UpdateData(TRUE);
             if(a<45) a+=5;
             else MessageBox("Maximum speed limit");
             m_speedfact.Format("%d", a);
             UpdateData(FALSE);
     }
 void CTest2Dlg::OnDwn() 
     {
         // TODO: Add your control notification handler code here
             UpdateData(TRUE);
             if(a>-45) a-=5;
             else MessageBox("Minimum speed limit");
             m_speedfact.Format("%d", a);
             UpdateData(FALSE);
     }
 void CTest2Dlg::OnFwd() 
     {
         // TODO: Add your control notification handler code here
             int p;
             int z = 5000/(2*m_sf);
             for(int i=0;i<z;i++) 
                 {
                     p = _outp(0x0378,0x03);
                     Sleep(m_sf + a);
                     p = _outp(0x0378,0x00);
                     Sleep(m_sf - a);
                  }
     }
 void CTest2Dlg::OnRew() 
     {
         // TODO: Add your control notification handler code here
             int p;
             int z = 5000/(2*m_sf);
             for(int i=0;i<z;i++)
                 {
                     p = _outp(0x0378,0x0C);
                     Sleep(m_sf + a);
                     p = _outp(0x0378,0x00);
                     Sleep(m_sf - a);
                 }
     }

void CTest2Dlg::OnFwrd() 
     {
         // TODO: Add your control notification handler code here
         int r;
         r = _outp(0x0378,0x03);
     }
 void CTest2Dlg::OnRe() 
     {
         // TODO: Add your control notification handler code here
             int r;
             r = _outp(0x0378,0x0C);
     }
 void CTest2Dlg::OnStop() 
     {
         // TODO: Add your control notification handler code here
         int r;
         r = _outp(0x0378,0x00);
     }

void CTest2Dlg::OnLButtonDown(UINT nFlags, CPoint point) 
     {
         // TODO: Add your message handler code here and/or call default
         int p;
         if((nFlags & MK_LBUTTON) == MK_LBUTTON)
             {
                 p = _outp(0x0378,0x03);
                 Sleep(50);
                 p = _outp(0x0378,0x00); 
             }
         CDialog::OnLButtonDown(nFlags, point);
     }
 void CTest2Dlg::OnRButtonDown(UINT nFlags, CPoint point) 
     {
         // TODO: Add your message handler code here and/or call default
         int p;
         if((nFlags & MK_RBUTTON) == MK_RBUTTON)
             {
                 p = _outp(0x0378,0x0C);
                 Sleep(50);
                 p = _outp(0x0378,0x00); 
             }
         CDialog::OnRButtonDown(nFlags, point);
     }
 void CTest2Dlg::OnMouseMove(UINT nFlags, CPoint point) 
     {
         // TODO: Add your message handler code here and/or call default
         int p;
         if((nFlags & MK_LBUTTON) == MK_LBUTTON)
             {
                 p = _outp(0x0378,0x03);
                 Sleep(m_sf + a);
                 p = _outp(0x0378,0x00);
                 Sleep(m_sf - a);
             }
         else if((nFlags & MK_RBUTTON) == MK_RBUTTON)
             {
                 p = _outp(0x0378,0x0C);
                 Sleep(m_sf + a);
                 p = _outp(0x0378,0x00);
                 Sleep(m_sf - a); 
             }
     CDialog::OnMouseMove(nFlags, point);
 }

 

 

###

 


Circuit Diagrams

tip-h-bridge-1


Filed Under: Electronic Projects
Tagged With: dc motor, motor, vc++
 

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • PS2 Keyboard To Store Text In SD Card Using Arduino Circuit Setup On Breadboard
    How To Use PS2 Keyboard To Store Text In SD Card Using Arduino- (Part 42/49)
  • Wireless Path Tracking System Using Mouse, XBee And Arduino Circuit Setup On Breadboard
    How To Make A Wireless Path Tracking System Using Mouse, XBee And Arduino- (Part 43/49)
  • How to Make a Wireless Keyboard Using Xbee with Arduino- (Part 44/49)
  • Making Phone Call From GSM Module Using Arduino Circuit Setup On Breadboard
    How to Make Phonecall From GSM Module Using Arduino- (Part 45/49)
  • How to Make a Call using Keyboard, GSM Module and Arduino
    How To Make A Call Using Keyboard, GSM Module And Arduino- (Part 46/49)
  • Receiving SMS Using GSM Module With Arduino Prototype
    How to Receive SMS Using GSM Module with Arduino- (Part 47/49)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • Renesas delivers intelligent sensor solutions for IoT applications
  • Microchip Technology releases AVR-IoT Cellular Mini Development Board
  • Qualcomm acquires Cellwize to accelerate 5G adoption and spur infrastructure innovation
  • MediaTek’s chipset offers high-performance option for 5G smartphones
  • Nexperia’s new level translators support legacy and future mobile SIM cards

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Adaptive filters fundamental
  • Using LTspice to check Current sense transformer reset?
  • Thermal pad construction on pcb
  • lna+mixer noise figure problem
  • Reference driver for negative/above rail voltages.

RSS Electro-Tech-Online.com Discussions

  • Capacitor to eliminate speaker hum
  • Identify a circuit.
  • How is this tester made?
  • undefined reference header file in proteus
  • Control Bare LCD With ATmega328p
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering