3 Şubat 2010 Çarşamba

pic 16f877A ile servo motor kontolü

Carson cs 502000 servo motoru ile yapılmış bir uygulamadır.Bu servo motor 20ms lik bir gecikme periyodunun 2400us si 1 olduğu durumda tam sol yapar.Eğer bu 20ms lip periyodun 540us si 1 ise tam sağ yapar.1500us de ise orta pozisyona gelir.
Aşağıdaki kodda servo motorun pwm ucu pic'in A5 pinine bağlanmıştır.Ayrıca B0 ve B1 pinlerinede birer buton bağlanmıştır.İsteyen olursa proteus çizimlerini gönderebilirim.

#include <16F877A.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES RESERVED //Used to set the reserved FUSE bits

#use delay(clock=20000000)

#define servo PIN_A5


void sagadon()
{
output_high(servo);
delay_us(540);
output_low(servo);
delay_us(20000-540);

return;
}
void soladon()
{

output_high(servo);
delay_us(2400);
output_low(servo);
delay_us(20000-2400);

return;
}

void main()
{
int1 a,b;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

set_tris_a(0x00);
set_tris_b(0b00000011);
output_a(0x00);
output_b(0x00);
for(;;)
{
a=input(pin_b0);
b=input(pin_b1);
delay_ms(20);
while(!a)
{
sagadon();
a=input(pin_b0);
delay_us(20);
}
while(!b)
{
soladon();
b=input(pin_b0);
delay_us(20);
}

}



}

2 yorum:

Adsız dedi ki...

mrb. proteus çizimlerini gönderebilirmisiniz teşekkürler..

a.brknn@msn.com

Hasan Bozok dedi ki...

Merabalar yeni gönderi olarak paylaştım iyi çalışmalar