Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

servo motor + DC motor using UART

Status
Not open for further replies.

gold12star

Junior Member level 3
Joined
Sep 27, 2010
Messages
28
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,451
hello to everyone
I kown how to control servo motor and DC motor using h-bridge
but I don't know how to combaine these two code together
and can I control them usnig only one port such as B
because I use UART and I can't control more than one port when I send the data through UART
using PIC16f877A and MikroC Pro
please help me
thank you

Servo motor
Code:
char i;
void main() {
 for (i=0; i<=50; i++){
   	trisb=0b00000000;
     	portb=0b10000000; //b7 input signal for servo motor
     	Delay_us(1500);
     	portb=0b00000000;
     	Delay_ms(18); }
}

DC motor

Code:
void main() {
TRISC = 0b00000000;
PORTC = 0b00001000;  // c3 for enable pin in h-bridge ,c2 for input pin in h-bridge
TRISD = 0b00000000;
PORTD = 0b00000010; // d1 for output pin in h-bridge
}
 

what I want is to control servo and DC motor at the same time using port B if I send some data through UART
 

You are aware that the method of controlling DC motors and servo motors are very different?
 

dc motor is controlled using pwm and servo motor is controlled by triggering the angle of movement....

from UART you can send some code as 1 that will control DC motor and 2 for controlling servo motor...

so you need l293 or ULN 2803 for dc motor and servo can be connected directly to port pin..

when you give command from terminal give the code as 1 or 2 to distinguish the command for servo and dc motor
 
You are aware that the method of controlling DC motors and servo motors are very different?
I know and I can control them at the same time using different port
but when I use UART I can control only one port at a time
so can I control both of them using one port??
also I contorl DC motor just for clockwise and anti-clockwise not speed so no need for PWM
 

this code I used to control Dc and servo motor and work perfectly
but when I used same code with UART
it dosn't work
any help please???
Code:
void main() {

TRISC = 0b00000000;
PORTC = 0b00001100;
TRISD = 0b00000000;
PORTD = 0b00000000;

trisb=0b00000000;
while(1){
portb=0b10000000;
delay_us(1500);
portb=0b00000000;
delay_ms(20);

}
}

the code with UART
Code:
char i;
void main() {
     
     UART1_Init(9600);               // Initialize UART module at 9600 bps
     delay_ms(100);              // Wait for UART module to stabilize

while(1){                     // Endless loop
      if (UART1_Data_Ready()==1) {     // If data is received,
      i= UART1_Read();    // read the received data,
      if(i=='U'){

      TRISC = 0b00000000;
      PORTC = 0b00001100;
      TRISD = 0b00000000;
      PORTD = 0b00000000;

      trisb=0b00000000;
      while(1){
      portb=0b10000000;
      delay_us(1500);
      portb=0b00000000;
      delay_ms(20);

      }
                   }

      else{
      TRISb=0b00000000;
      PORTB=0b01000000;}
      
  }

}
}

thanks
but I need help as soon as possible:-(
because this is my final year project
 

anyone have a reason why that happend with me??
please I need helpppppppppppppp :(
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top