Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

servo control using port

Status
Not open for further replies.

daisordan

New Member
Hi, i connected a servo signal to RD7 in PIC18F4455. I have done the experiment for the servo movement left = 500us, right = 2ms. I use the delay to work out the pulse but it doesnt work. The servo was just stop here. Is there any problem with my code? how can i fix it?

void main (void){
TRISD=0b00000000;
PORTD=0b00000000;

PORTDbits.RD7=0;
Delay1KTCYx(5); //delay for 20ms
PORTDbits.RD7=1;
Delay100TCYx(5); //delay for 2ms
while(1)
}

PS:using Fosc=1MHz
 
Last edited:
while is at the beginning of a loop, not the end. You should encapsulate the stuff that loops like this

while(1)
{
//code that loops goes here
}

as is, your program sets the ports, then turns RD7 off and on once, then loops at that while(1) at the end forever.
 
Try connecting it an LED in series with 220 ohm resistor instead of the servo pin. Set the delays to what you think will make it blink at 1 Hz. This will tell you if the chip is running, if the port is working as an output, and if the timing is what you think it is.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top