Showing posts with label DC Motor. Show all posts
Showing posts with label DC Motor. Show all posts

Wednesday, April 13, 2016

DC Motor's Speed Controlling Using PWM of Microcontroller




We can control the speed of a DC motor through a microcontroller. All we need to know about PWM .That means " Pulse Width Modulation ". It is a very popular technique and most important part of a microcontroller.  In this tutorial we will use PWM to create signal. By changing pulse width of a signal ,we can control the speed  .




Basic Description:

At first we will connect a DC motor with PIC microcontroller and we will also connect two push buttons with it. One of those buttons will be used for increasing speed and another one for decreasing speed. That's all .

Now listen to me carefully, Just keep this in your mind 
1. Increasing duty or Pulse Width will increase the speed of  DC motor .
2.Decreasing duty or Pulse Width will decreasing the speed of DC motor.

Now, we need to know about PWM [ Pulse Width Modulation ]



 

Pulse Width Modulation (PWM)




 We can create various signal through PWM. If we want to create 36KHz signal, that can be done by PWM .We can create any type signal. When we write program for creating signal through MCU, the CPP pin of microcontroller generate the signal according to the instructions. Lets consider, we have a 2Hz frequency signal. That means time period is 1/2=0.5 sec. This signal can be in various form. Look at the pictures :
 DC Motor's Speed Controlling Using PWM and Microcontroller
Pulse width modulation

 DC Motor's Speed Controlling Using PWM and Microcontroller
when Set_Duty(127);
 DC Motor's Speed Controlling Using PWM and Microcontroller
PWM

Pic microcontroller's has two PWM or CPP module look at the picture .


In L293D's  EN1  pin we provide the signal. If you will provide highest pulse width, the speed will be highest. When you will decrease pulse width, the speed will also be decreased.
So if you don't know how to interface DC motor with microcontroller. It's recommended to read this tutorial ,

DC Motor Interfacing with PIC Microcontroller in Proteus [step by step]



 Time Period = Times of ON state + Times of OFF state .



PWM has four functions

1. PWM1_Init( Set_Frequency );

2.  PWM1_Start();

3.PWM1_Set_Duty( Count );

4.PWM1_Stop();

Here most important thing is PWM1_Set_Duty(count) , If we increase the value of count, the speed increases. If we decrease the value of count, the speed decreases. Another important thing is the highest value of count is 255 and lowest is 0.

count proportional to PW
So, count = K * PW ----eq(1) where K = constant .

count/PW=K  

When PW=T , count=255  and when PW=T/2 , count=127.5 or 127

255/T=127/(T/2) = K

and , inserting values of PW and count in eq(1)

255=K * T----eq(2)
127.5=K * (T/2)------eq(3)

Now eq(2)+eq(3) : 382.5= K { T +(T/2)}

or 382.5=K*(3T/2)
or 765=3*K*T
or T*K=255
or K=255/T
Now inserting value of  K into eq(1) , we get

Finally we get,  count =255*(PW/T), This is the relation between count, PW & T.
That was not very necessary for this tutorial. But I've shared all I knew.



When pulse width is equal to   T it means total time period it remains ON .  Now look at the picture given below :


Now create a project in proteus

# Proteus Circuit :




#MikroC Code :


 void main() {  
  unsigned int count=0;  
 ADCON1=0x0F;  
 CMCON=7;  
 TRISA.F0=1;  
 TRISA.F1=1;  
 TRISC.F1=0;  
 TRISC.F0=0;  
 PWM1_Init(1000);  
  PWM1_Start();  
   PORTC.F0=1;  
   PORTC.F1=0;  
    PWM1_set_duty(count);  
   while(1){  
    if(PORTA.F0==0){  
      delay_ms(100);  
    if(count>=255) {  
    count=255; }else{  
    count=count+15;  
     PWM1_set_duty(count);  
    }  
    }  
    if(PORTA.F1==0){  
      delay_ms(100);  
      if(count<=0){  
      count=0;  }else{  
      count=count-15;  
       PWM1_set_duty(count);  
      }  
    }  
   }  
 }



Watch The Video in You Tube

Download Link of  this Project 

Thank You!

Thursday, January 15, 2015

DC Motor Interfacing with PIC Microcontroller ( PIC18F2550 ) in Proteus [step by step]


mikroc code to start and stop dc motor
DC Motor

This tutorial will describe,  how to interface a DC motor with a Microcontroller and in this tutorial, I will use pic18f2550 microcontroller. Generally, to control a DC motor we need voltage 12v with 300mA current. Basically a microcontroller works on 5v and can't provide the current follow to operate a DC motor.As we know a motor can produce back emf, we need other technique to operate .The solution will be a H-Bridge circuit or L293D ic.

H-Bridge Circuit for dc motor
H-Bridge Circuit 
L293D IC pin out
L293D


We can operate two motors through this IC. Here pin 1 is to enable input 1(pin1)&2(pin7) for input and 3&6 pins for output. Pin9 enables 3(pin 10)&4(15) as input and 14&11 pins as output. We will connect pin2 & pin7 with our microcontroller's pin RC0 and RC1 respectively. Now, look at the picture given below.
 DC Motor Interfacing with PIC Microcontroller ( PIC18F2550 ) in Proteus [step by step]
DC Motor Rotation Controlling


Now Create a new project in Proteus. If you are a beginner, just follow the instructions.

Proteus Circuit:

How to Create a New Project in Proteus 8_Step1
How to Create a New Project in Proteus 8_Step1
How to Create a New Project in Proteus 8_Step2
How to Create a New Project in Proteus 8_Step2

How to Create a New Project in Proteus 8_Step3
How to Create a New Project in Proteus 8_Step3
How to Pick parts from Proteus library
How to Pick parts from Proteus library
How to find Power ,Ground etc
Now just complete the circuit as I have given below.

 DC Motor Interfacing with PIC Microcontroller ( PIC18F2550 ) in Proteus [step by step]
Interface DC Motor with pic Microcontroller
Now we need source code to run this microcontroller. So let's create a project in MikroC.

MikroC Project :

Create a project in mikroC_Step_1
Create a project in mikroC_Step_2
Create a project in mikroC_Step_3
#Source Code :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


void main() {
CMCON = 0x07; // To turn off comparators
ADCON1 = 0x0F;
Trisc=0x00;
delay_ms(1000);
while(1){
/////// Step1: Rotate Motor Clockwise
PORTC.F0=1;
PORTC.F1=0;
delay_ms(4000);   //delay for 4 sec
/////// Step2: Stop the Motor
PORTC.F0=0;
PORTC.F1=0;
delay_ms(4000);   //delay for 4 sec
 /////// Step3: Rotate Motor Anti-Clockwise
PORTC.F0=0;
PORTC.F1=1;
delay_ms(4000);   //waiting for 4 sec
  /////// Step4: Again Stop The Motor
PORTC.F0=1;
PORTC.F1=1;
delay_ms(4000);   //delay for 4 sec
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Now run the program and save the hex file on your computer .
Run project in mikroC
Now go to the proteus circuit and load the hex to microcontroller
Load hex to microcontroller
Run the proteus project.
Run Proteus Project

Result :

 mikroc code to start and stop dc motor
DC motor in Clockwise direction
 DC Motor Interfacing with PIC Microcontroller ( PIC18F2550 ) in Proteus [step by step]
DC motor in Anti-Clockwise direction


      Download Proteus File & Hex file

                          Just Click on  '' SKIP ADD '' and You will get the download link

Thank You!



Please Share and Bookmark posts.

Tags

: (1) 18F2550 (1) 36KHz (3) and (1) arduino (1) Based (1) battery (1) Bipolar (1) Blinking (1) blinks (1) Bluetooth (1) bluetooth device interfacing (1) bluetooth module (1) button (1) circuit (1) clock (1) control (1) crystal oscillator (3) Db9 (1) DC Motor (2) digital (2) Digital Voting Machine (1) digital voting machine using pic (1) display (2) DS1307 (1) electronic (1) embedded c programming tutorial (11) embedded c tutorial (11) experiment kit (4) external interrupt (4) flash (1) flashing (1) Gas Leakage detector (1) HC-06 (1) home (1) how (1) How to (10) i2c tutorial (1) in (1) indicator (1) infrared Connection (3) interface (8) interfacing (3) Interrupt (3) Introduction (1) IR Connection (3) IR Receiver (4) IR Transmitter (4) key pad (1) keyboard (1) keypad (1) lavel (1) Lcd 16x2 (2) lcd 2x16 (2) led (1) lm35 (2) LPG (1) machine (1) make (1) Make bootloader (1) making (1) matrix (1) max232 (1) membrane keyboard (2) meter (2) Micocontroller (1) microchip (4) microchip pic (2) microchips (3) microcontroller (9) microcontroller based (3) microcontroller programming (3) Microcontroller Project (4) Microcontroller Projects (1) microcontroller_project (2) microcontrollers (4) Microprocessor (2) mikroC (5) mikroc code to start and stopstart and stop dc motor (1) mikroc pro for pic (2) Motion detector (1) MQ-9 Gas Sensor (1) musical (1) NEC Protocol (4) pcb (5) PIC (3) pic controller (11) pic microcontroller (11) pic microcontroller tutorial (11) pic programming (1) pic programming in c (12) pic proteus (1) Pic Tutorial (12) pic18 (2) pic18f2550 (11) picmicrocontroller (4) picRFモジュール (1) PIR Motion Sensor (1) printed circuit board (1) proteus (6) pulse width modulation (1) push (1) push button (1) PWM (1) real (1) rf transmitter (3) Rs 232 (1) Rs232 (1) scroll (1) scrolling (1) Serial communication (1) Serial Connection (1) Serial Port (1) serial port rs232 (1) Servo Motembedded c programming tutorial (1) simulation (2) Soil Moisture Meter (1) speed control (1) step by step (7) step bystep (1) Stepper Motor (2) text (2) Thief Detector (1) time (1) timer (4) timer0 (4) tone (1) TSOP38236 Receiver (4) tutorial (2) Unipolar (1) USART Connection (1) USB (1) usb 1.0 (1) USB bootloadere (1) USB HID (1) using (9) voltmeter (1) voting (1) water level indicator (3) with (2) work (1)

Traffic Feed


Live Traffic Feed
Visitor Tracking

Leave Your Message Here

Name

Email *

Message *

Like on Facebook