Showing posts with label step by step. Show all posts
Showing posts with label step by step. Show all posts

Saturday, January 24, 2015

Usb Communication With PIC Microcontroller [step by step tutorial]



usb connection with pic microcontroller
mikroc usb tutorial

USB communication is better than serial communication. Hardware interfacing is very easier than Rs 232 . In USB 1.0 communication  Low Speed is-1.5Mbit/second  & High Speed is -12Mbit/second . The upgrade version provides more speed than older version. USB-3.0  has higher speed, 5Gbit/second and it's called super speed. For more information you can visit this page >>  Wikipedia Usb.

In this tutorial I will use pic18f2550 microcontroller & it is very popular for usb. Now you can ask a question, how do we get our MCU to work with high speed or low seed ?
At 6MHz clock we will get low speed and at 48MHz Clock we will get High speed. In this tutorial we will try to make higher speed connection. We are not going to use 48MHz clock, because it is very noisy. We will try another technique instead of it. Microchip company provides internal PLL( Phase Locked Loop ) circuit  in some of specific  products and  pic18f2550 has internal PLL Circuit. Now look at the picture :

Phase Locked Loop Cuit
PLL Circuit
The PLL circuit  converts 4MHz clock to 48MHz clock. So, we need 4MHz clock. We have to divide the clock in such way so that we can get  result 4MHz. Look at here, If we use 20MHz divide it by 5 and we get 4. Example : (20/5)=4 ,(12/3)=4. We have to define this in the  source code.

Now let's create a project in Proteus 8.

Proteus 8 Circuit :

Step 1:
How to Create Project in Proteus 8
How to Create Project in Proteus _1
Step 2:
How to Create Project in Proteus 8
How to Create Project in Proteus 8_2

Step3 :
How to Create Project in Proteus 8_3
How to Create Project in Proteus 8_3

 Step 4:
Usb Communication With PIC Microcontroller [step by step tutorial]


Step 5:
How to find parts in Proteus 8
How to find parts in Proteus 8
 Step 6:
How to find parts in Proteus 8_3
How to find parts in Proteus 8
Step 7:

usb interfacing with pic microcontroller Circuit
Usb  Interfacing With PIC Microcontroller Circuit

Now let's create a project in MikroC.

MikroC Code :

Step 1:
Create New Project in MikroC_1
Create New Project in MikroC_1
Step 2:
Create New Project in MikroC_2
Create New Project in MikroC_2
Step 3:
Create New Project in MikroC_3
Create New Project in MikroC_3
Step 4:
 Include All Library in mikroc
Include All Library
Step 5:
Editing MikroC project
Editing MikroC project settings_1
Step 6:
USB Communication With PIC Microcontroller
USB Communication With PIC Microcontroller


1. As we know PLL circuit takes input 4MHz clock. So we have to divide 12MHz by 3 so that we can get 4MHz clock. If we use 4MHz we have no need  this part .
2 & 3 . We are using USB 1.0 and it's High Speed clock 48MHz. So we have to devide it by 2.

4 . Here we are using 12MHz Crystal clock and the oscillator selection should be HS Oscillator.          

5 . We have to enable voltage regulator. Basically it is an internal  3.3 voltage regulator of pic18f2550. If we enable this, it is required to connect vusb pin with a 220 nf capacitor.

#Source Code :

 

unsigned char receivedata[64] absolute 0x500;  //  <--Variable Declaration  
 unsigned char senddata[64] absolute 0x580;  
 int i=0;  
 void Interrupt(){  
 USB_Interrupt_Proc();    //<--Interrupt function  
 }  
 void main()   //<--The Main Function  
 {  
 HID_Enable(&receivedata,&senddata);  //<--To Enable HID  
 while(1){             //<-- Infinity LOOP  
 while(!HID_Read());   //<--for reading  
 for(i=0;i<64;i++){  
 senddata[i]=receivedata[i];   //<--Sending received data to senddata[i] variable  
 }  
 while(!HID_Write(&senddata,64)); //<--for writting  
 }  
 }  
 

1. unsigned char receivedata[64] absolute 0x500;

    unsigned char senddata[64] absolute 0x580;


Here we have created character type two array variable senddata & receivedata. During USB Communication we must have to keep all data in USB RAM. PIC 18F2550 microcontroller's USB RAM memory address begins with 0x500 and ends with 0x7F. That's why, we kept the receivedata[64]  in 0x500 location and senddata[64] in 0x580.
2. 

void Interrupt(){


USB_Interrupt_Proc();}


void Interrupt() is one user defined function which contains USB_Interrupt_Proc()  function inside . Interrupt means restriction for something. When  interrupt is enabled, microcontrller doesn't perform main function. It will perform only interrupt function or ISR(interrupt service routine). After clearing the flag main method works.

3. HID_Enable(&receivedata,&senddata); 

This function will initialize USB. It locates receivedata variable and  send data variable.

Note : HID means "Human Interface Device"

4. char HID_Read();

This function receives data. If receiving is failed, it returns 0. Otherwise it returns character .

while(!HID_Read());

It means, this function tries to receive data until  data are being received .

char HID_Write();


This function receive data. If receiving is failed, it returns 0. Otherwise it returns the numbers of data .while(!HID_Write());


 It means, this function tries to send data until  data are being sent. 

5.for(i=0;i<64;i++>

senddata[i]=receivedata[i];    

}

This loop will run from 0 to 63 and will keeps the received data to senddata variable from receivedata variable.  

  #Descriptor File Addition

Descriptor File : This file will make your pc understand about device's informations. Like
Manufacture Name, Product ID, Vendor ID  etc.
Now i will show you. How to create a Descriptor file .



Step 7:
Create Descriptor FIle_1
Create Descriptor File_1
Step 8:
Create Descriptor FIle_2
Create Descriptor FIle_2
Step 9:
Adding descriptor file with MikroC Project .
Adding Descriptor File
Adding Descriptor File
Step 10:
Step 11:

Usb Communication With PIC Microcontroller [step by step tutorial]
Step 12:
usb interfacing with pic microcontroller
How to upload hex file in proteus_1
Step 13:
How to upload hex file in proteus
How to upload hex file in proteus_2
Step 14:
How to upload hex file in proteus
How to upload hex file in proteus_3
Step 15:
In proteus Simulation we need to install virtual usb .
How to install Virtual USB in proteus
Install Virtual USB in proteus
Step 16:
Run Proteus Project
Run Project

Now go to the Proteus Circuit and Just Run the project .

Output:

Now go to the Tool >>HID Terminal >> click on Terminal .
HID Terminal of MikroC
HID Terminal of MikroC
HID Terminal of MikroC
HID Terminal Output




                                          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!



Wednesday, January 14, 2015

Bipolar Stepper Motor Interfacing With PIC Microcontroller (PIC18F2550) in Proteus [step by step]

                                            

Stepper Motor (animation source : wikipedia)

Stepper Motors and It's Working Principles :

In this tutorial I will show , how to interface stepper motor with microcontroller and in this case I will use pic18f2550 microcontroller .Basically stepper motor works step by step .It can rotate 360 degree by the movements of equal steps.They are available stepper motor with steps 200, 180, 144, 72, 24 with rotation angles 1.8°, 2°, 2.5°, 5°, 15° respectively. Stepper motor moves each step at a time where every steps are equal .
Generally stepper motor works on the principle of electromagnetic induction. A internal rotor is surrounded by electromagnetic stators where rotor and stator like to be stable by achieving different poles.In this way the stepper motor rotate .If one stator gets power , thetab stator attracts the rotor .At this situation the rotor rotates so that the stable state can be achieved .If next stator is on and others are off .The motor will complete the next step .

Generally Stepper Motors are Divided into Three Types :



1.Hybrid Stepper Motor
2.Permanent Magnet Stepper Motor
3.Variable Reluctance  Stepper Motor

[Note : If you would like to learn more about Stepper motor with more details ,please follow the link  wikipedia  ]

According to the arrangement of windings the stepper motors are divided into two types :

1.Unipolar Motor
2.Bipolar Motor

Unipolar : 

This type of stepper motor is very popular and  most preferable for the hobbyists .Unipolar stepper motor contains centre tapped  windings inside .In this case coils are connected through a common wire and the poles can be changed without changing the direction of current .That's why the commutation circuit is very simple for unipolar stepper motor .To control a motor through microcontroller we need H-bridge circuit and we use L293D IC  as a replacement of h-bridge circuit . You know motor is one kind generator of electricity  .Due to the effect of magnetic field the rotation makes back emf  and we shouldn't use a MCU to interface directly with motor.That's why we will use L293D .

Bipolar :

This types of motor have no centre taped windings .For achieving reverse magnetic poles the current should be reversed in direction .In order to control this motor we need L293D ic because it is more complex to control .Basically L293D is used  as the alternative of H-bridge circuit .H-bridge circuit is also used to controlling dc motor .


[Note : If you would like to see "How to Interface Unipolar Stepper Motor " ,Please follow the link]

Now at this situation , we have got necessary information  to create a Project .

Proteus Circuit for Bipolar Stepper Motor:

Let's Create a Project on Proteus .Please Follow the instructions given in the pictures .



Please Complete the circuit as Given below . This Circuit is for Unipolar Stepper Motor
 Bipolar Stepper Motor Interfacing With PIC Microcontroller (PIC18F2550) in Proteus [step by step]
 Bipolar Stepper Motor Interfacing With PIC Microcontroller (PIC18F2550) in Proteus [step by step]

Now Create a Project in MikroC .If you are a beginner , you can follow the instruction :

MikroC Code  for Bipolar Stepper Motor:


Source Code :


\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
void main() {
CMCON = 0x07;
ADCON1 = 0x0F;
Trisb=0x00;
delay_ms(1000);
while(1){
PORTB.F0=0;
PORTB.F1=0;
PORTB.F2=0;
PORTB.F3=1;
delay_ms(1000);
PORTB.F0=0;
PORTB.F1=1;
PORTB.F2=0;
PORTB.F3=0;
delay_ms(1000);
PORTB.F0=0;
PORTB.F1=0;
PORTB.F2=1;
PORTB.F3=0;
delay_ms(1000);
PORTB.F0=1;
PORTB.F1=0;
PORTB.F2=0;
PORTB.F3=0;
delay_ms(1000);
}
}

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

How to run the MikroC and save hex file .

Now go to the proteus circuit to load the hex file
Run the Project

Result :

 Bipolar Stepper Motor Interfacing With PIC Microcontroller (PIC18F2550) in Proteus [step by step]
 Bipolar Stepper Motor Interfacing With PIC Microcontroller (PIC18F2550) in Proteus [step by step]



                                                      Download Proteus File

                                                       Download Source Hex



                      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