como programar x servos
Para entender todo lo que a continuación seexplicará es necesario de varias herramientas:
1.- Mplab + Plug-in del Ccs
2.- CCS Compiler
3.- Proteus (7.2 SP2)
4.- Y ganas de aprender
Después de tener todo instalado, abrimos el MPLAB y creamos un nuevo proyecto, elegimos nombre y ubicación, y le damos OK (yo elegí por ejemplo: pic_pwm):
[PIC16F877]
Luego vamos a File --> New y en la ventana que se nos abre copiamos éste código:Código:
#include
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,PUT
#use delay (clock=20000000)
#USE RS232 (baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#byte PORTA = 0x05
#byte PORTB = 0x06
#byte PORTC = 0x07
#byte PORTD = 0x08
#byte PORTE = 0x09
#bit servo_00 =PORTB.0
#bit servo_01 = PORTB.1
#bit servo_02 = PORTB.2
#bit servo_03 = PORTB.3
#bit servo_04 = PORTB.4
#bit servo_05 = PORTB.5
#bit servo_06 = PORTB.6
#bit servo_07 = PORTB.7
#bit servo_08 = PORTD.0
#bit servo_09 = PORTD.1
#bit servo_10 = PORTD.2
#bit servo_11 = PORTD.3
#bit servo_12 = PORTD.4
#bit servo_13 = PORTD.5
#bit servo_14 = PORTD.6
#bit servo_15 = PORTD.7
#define n 16// número de servos
//para otro número de servos hay que hacer mediciones de tiempo
#define max_theCount 200// 200*100us=20ms
#define derecha 26// Éste valor fué determinado simulando el proceso
// en el proteus pero en teoría debería ser (25) 25*100us=2,5ms
// Sería cuestión de probar con servos reales y ajustar valores;-)
#define centro 15// 15*100us=1,5ms
#define izquierda 5// 5*100us =0,5ms
#define val_timer0 88
int8 theCount=1;
int8 duty[n];
#INT_TIMER0
void isr_timer0(){// Cada 100us llega aqui de forma cíclica
#asm
nop
#endasm
if (duty[0] >= theCount)
{
servo_00=1;
}
else
{
servo_00=0;
#asm
nop
#endasm
}
if (duty[1] >= theCount)
{
servo_01=1;
}
else
{
servo_01=0;
#asm
nop
#endasm
}
if (duty[2] >= theCount)
{
servo_02=1;
}
else
{
servo_02=0;
#asm
nop
#endasm
}
if (duty[3] >= theCount)
{
servo_03=1;
}
else
{
servo_03=0;
#asm
nop
#endasm
}
if (duty[4] >= theCount)
{
servo_04=1;
}
else
{
servo_04=0;
#asm
nop
#endasm
}
if (duty[5] >= theCount)
{ servo_05=1;
}
else
{
servo_05=0;
#asm
nop
#endasm
}
if (duty[6] >= theCount)
{
servo_06=1;
}
else
{
servo_06=0;
#asm
nop
#endasm
}
if (duty[7] >= theCount)
{
servo_07=1;
}
else
{
servo_07=0;
#asm
nop
#endasm
}
if (duty[8] >= theCount)
{
servo_08=1;
}
else
{
servo_08=0;
#asm
nop
#endasm
}
if (duty[9] >= theCount)
{
servo_09=1;
}
else
{
...
Regístrate para leer el documento completo.