View previous topic :: View next topic |
Author |
Message |
aman kelip Guest
|
hardware problems of 16f876a |
Posted: Wed Dec 30, 2009 2:47 am |
|
|
This program to generate the pulse for control digital servo. I have done it with 16f877a without problem. When I change to more small PIC, 16f876a the pulse can't be generate. I have simulate the program in proteus and it can generate pulse. When I download the program into pic16876a, its fail... can anyone help to solve this?
Code: |
#include <16f876a.h>
#include <stdio.h>
#use delay(clock=20000000)
#fuses hs,noprotect,nowdt,nolvp,NOBROWNOUT,PUT
#byte porta=5
#byte portb=6
#byte portc=7
int count;
void main()
{
set_tris_b(0);
//portb=0b00000000;
while(true)
{
//0deg both servo
for(count=0;count<170;count++)
{
output_high(pin_b0); //right servo
output_high(pin_b1); //left servo
delay_ms(1);
output_low(pin_b0);
output_low(pin_b1);
delay_ms(1);
}
//40 degree for both servo
for(count=0;count<170;count++)
{
output_high(pin_b0);
output_high(pin_b1);
delay_ms(1);
delay_us(950);
output_low(pin_b0);
output_low(pin_b1);
delay_ms(1);
delay_us(950);
}
}
}
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Dec 30, 2009 7:16 am |
|
|
Most servo motors like a pulse rate of about 50 pulses per second. In your first loop you are sending 500 pulses and 250 pulses in the second loop.
Change both loops to take about 20ms each, or have a look at some example programs here: http://www.ccsinfo.com/forum/viewtopic.php?t=40239 |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Wed Dec 30, 2009 4:23 pm |
|
|
As ckielstra already wrote your problem is in pulses you send to servo. You have to send a pulse every 20ms to the servo and with width you control how much servo moves. Pulse length will roughly be between 1ms for full left and 2ms for full right (it may be other way around) and at about 1.5ms it will be in the middle.
These times depends on servo model. I have posted some time ago an example written for PIC18F4550 how to control 8 servos with timer interrupt function. This could be rewritten to your PIC and if you have only two servos it will be easier.
If you still need help don't hesitate to ask |
|
|
|