No te ha pasado por la cabeza la idea de un controlador de servos USB?
if(Servo_Idx==0 && SERVO1_ON) output_high(SERVO1);
if(Servo_Idx==1 && SERVO2_ON) output_high(SERVO2);
if(Servo_Idx==2 && SERVO3_ON) output_high(SERVO3);
if(Servo_Idx==3 && SERVO4_ON) output_high(SERVO4);
if(Servo_Idx==4 && SERVO5_ON) output_high(SERVO5);
if(Servo_Idx==5 && SERVO6_ON) output_high(SERVO6);
if(Servo_Idx==6 && SERVO7_ON) output_high(SERVO7);
if(Servo_Idx==7 && SERVO8_ON) output_high(SERVO8);
Enhorabuena RedPIC.
Me surge una duda al leer tu código. En lugar de usar este tipo de if consecutivos de los que, obviamente, no pueden ser ciertos más de uno a la vez, ¿en los PICs también sería más eficiente recurrir a estructuras switch...case o if...else if?Código: [Seleccionar]if(Servo_Idx==0 && SERVO1_ON) output_high(SERVO1);
if(Servo_Idx==1 && SERVO2_ON) output_high(SERVO2);
if(Servo_Idx==2 && SERVO3_ON) output_high(SERVO3);
if(Servo_Idx==3 && SERVO4_ON) output_high(SERVO4);
if(Servo_Idx==4 && SERVO5_ON) output_high(SERVO5);
if(Servo_Idx==5 && SERVO6_ON) output_high(SERVO6);
if(Servo_Idx==6 && SERVO7_ON) output_high(SERVO7);
if(Servo_Idx==7 && SERVO8_ON) output_high(SERVO8);
Y hablando de "temblar". De los cinco Servos tengo uno que tiembla en el extremo de máxima señal a 2.3 ms. No es el canal al que lo conecte ya que intercambiándolo con cualquier otro sigue vibrando siempre el mismo y no el canal al que lo tenía puesto. Imagino que el pobre ya está viejo ya que tiene mas de 15 años y estuvo algunos años montado en un avión. Le tengo mucho cariño. :mrgreen:
Y tienes razón, con algún medio para poder monitorizar o controlar lo que ocurre en el PIC es todo mucho mas fácil.
Y tienes razón, con algún medio para poder monitorizar o controlar lo que ocurre en el PIC es todo mucho mas fácil.
Es como si supiera lo que piensa mi cucaracha en cada momenoto :mrgreen:
////////////////////////////////////////////////////////////////////////////////////
//
// Moviendo 8 servos con un solo timer
//
//
// Propósito: Mover hasta 8 servos eficientemente
//
// Conectar 8 servos al PORT_B
//
////////////////////////////////////////////////////////////////////////////////////
#include <16f876.h>
#fuses HS,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP,NOCPD,NODEBUG,NOWRT
#use delay(clock=20000000) //Cambiar segun el cristal utilizado
#define VAL_TIMER1 53000 // 65536-53000=12536 * 0,0002 = 2,5 milisegundos
float const uSxTick = 0.2; // Microsegundos por Tick de TMR1 a 20 Mhz
int8 servo=0; // Numero de servo
int1 flag_timer1=FALSE;
#int_timer1
void handle_timer1_int() // Se activa cada 2,5 ms
{
flag_timer1=TRUE;
set_timer1(VAL_TIMER1); // 65536-53000=12536*0,0002 = 2,5 ms
}
#int_ccp2 // Interrupción timer1 modo compare
void handle_ccp2_int()
{
bit_clear(*6,servo); // Pone en bajo el servo. Igual que output_low(PIN_Bx) pero le puedo pasar un parametro. *6=PORTB
}
////////////////////////////////////////////////////////////////////////////////////
//
// PROGRAMA PRINCIPAL
//
////////////////////////////////////////////////////////////////////////////////////
void main()
{
////////////////////////////////////////// INICIALIZACIONES GENERALES
delay_ms(333); // Espero a que todo se estabilice e ...
disable_interrupts(global); // Inicializo el Micro y ...
disable_interrupts(int_timer1); // deshabilitando todo lo no necesario ...
disable_interrupts(int_rda);
disable_interrupts(int_ext);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp2(CCP_COMPARE_INT); // Configura CCP2 en modo COMPARE
set_timer1(VAL_TIMER1); // 65536-53000=12536*0,0002 = 2,5 ms
// Habilito las interrupciones necesarias
enable_interrupts(int_timer1); //Int timer 1
enable_interrupts(int_ccp2); // Habilito la interrpción INT_CCP2
enable_interrupts(global); //Habilita interrupciones
do
{
if(flag_timer1==TRUE) // Cuando se activa la int_timer1 -> cada 2,5 ms
{
servo++; //Controla secuencialmente cada servo
if (servo>=9) servo=1;
bit_set(*6,servo); // Pongo en alto el servo. Igual que output_high(PIN_Bx) pero le puedo pasar un parametro. *6=PORTB
CCP_2 = VAL_TIMER + pos_servo(servo); // Cargo CCP con el tiempo que tiene que estar en alto el servo
// La funcion pos_servo() debe devolver la posicion del servo en microsegundos
flag_timer1=FALSE;
}
}
while (TRUE);
}
Creo que se puede simplificar un poco el codigo utilizando bit_set() y bit_clear, en vez de output_high() y output_low() para poner el servo en alto y en bajo respectivamente, siempre que se disponga de un puerto completo para ello.
Si me permites un consejo, Don Diego, coloca los componentes SMD en la cara bottom, y te ahorrarás un huevo de vías.
..
Una dudilla y aviso que la hago desde el más profundo de los desconocimientos en el tema. Sería posible generar las señales para controlar los servos de la misma forma en que se controlan los leds RGB por software? ...
#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,PUT
#use delay (clock=20000000)
#USE RS232 (baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#byte RCSTA= 0x018
#bit CREN= RCSTA.4 // Se activa para recepción continua
#bit OERR= RCSTA.1 // Error de Overrun
#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_01 = PORTB.0
#bit servo_02 = PORTB.1
#bit servo_03 = PORTB.2
#bit servo_04 = PORTB.3
#bit servo_05 = PORTB.4
#bit servo_06 = PORTB.5
#bit servo_07 = PORTB.6
#bit servo_08 = PORTB.7
#bit servo_09 = PORTD.0
#bit servo_10 = PORTD.1
#bit servo_11 = PORTD.2
#bit servo_12 = PORTD.3
#bit servo_13 = PORTD.4
#bit servo_14 = PORTD.5
#bit servo_15 = PORTD.6
#bit servo_16 = PORTD.7
#define n 16// números de servos
#define multiplo 1// Podemos cambiarlo para ajustar
#define max_theCount 1000000
#define retardo 300// Son us
int8 servo[n];// Contiene los bytes bajo y alto de los servos
int8 i=0;// es el índice exclusivo de servo[] en la recepción serial
// Declaración de Funciones
void theDelay(void);
// Recepción de datos
#int_rda
void serial_isr(void){//Está listo para recibir 32 bytes
servo[i]=getc();
i++;
if (i>(2*n-1)) i=0;
}
/////////////////////////////////////// PRINCIPAL /////////////////////////////////////
void main()
{
int32 theCount = 0;
int8 k;
int32 duty[n];// Cargamos el ciclo útil de los servos
set_tris_b(0x00);
set_tris_c(0b10000000);
set_tris_d(0x00);
PORTB=0x00;
PORTD=0x00;
port_b_pullups(FALSE);
enable_interrupts(int_rda);
enable_interrupts(global);
for(k=0;k<=(2*n-1);k++)
servo[k]=200;// **VALOR INCIAL** por ejem: 200
while (1)
{
theCount++;
if (theCount>max_theCount) theCount=0;
for (k=0;k<=(n-1);k++) duty[k]=(int32)((servo[2*k+1]*256+servo[2*k])*multiplo);
servo_01= (duty[0] > theCount);
servo_02= (duty[1] > theCount);
servo_03= (duty[2] > theCount);
servo_04= (duty[3] > theCount);
servo_05= (duty[4] > theCount);
servo_06= (duty[5] > theCount);
servo_07= (duty[6] > theCount);
servo_08= (duty[7] > theCount);
servo_09= (duty[8] > theCount);
servo_10= (duty[9] > theCount);
servo_11= (duty[10] > theCount);
servo_12= (duty[11] > theCount);
servo_13= (duty[12] > theCount);
servo_14= (duty[13] > theCount);
servo_15= (duty[14] > theCount);
servo_16= (duty[15] > theCount);
//theDelay();
}
}
// Rutina de retardo
void theDelay(void){
delay_us(retardo);//
}Debo tener algun problema, no veo las imagenes, Diego... :? :shock:
Extraordinaria, Diego.
....Código: [Seleccionar]
////////////////////////////////////////////////////////////////////////////////////
//
// Moviendo 8 servos con un solo timer
//
//
// Propósito: Mover hasta 8 servos eficientemente
//
// Conectar 8 servos al PORT_B
//
////////////////////////////////////////////////////////////////////////////////////
#include <16f876.h>
#fuses HS,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP,NOCPD,NODEBUG,NOWRT
#use delay(clock=20000000) //Cambiar segun el cristal utilizado
#define VAL_TIMER1 53000 // 65536-53000=12536 * 0,0002 = 2,5 milisegundos
float const uSxTick = 0.2; // Microsegundos por Tick de TMR1 a 20 Mhz
int8 servo=0; // Numero de servo
int1 flag_timer1=FALSE;
#int_timer1
void handle_timer1_int() // Se activa cada 2,5 ms
{
flag_timer1=TRUE;
set_timer1(VAL_TIMER1); // 65536-53000=12536*0,0002 = 2,5 ms
}
#int_ccp2 // Interrupción timer1 modo compare
void handle_ccp2_int()
{
bit_clear(*6,servo); // Pone en bajo el servo. Igual que output_low(PIN_Bx) pero le puedo pasar un parametro. *6=PORTB
}
////////////////////////////////////////////////////////////////////////////////////
//
// PROGRAMA PRINCIPAL
//
////////////////////////////////////////////////////////////////////////////////////
void main()
{
////////////////////////////////////////// INICIALIZACIONES GENERALES
delay_ms(333); // Espero a que todo se estabilice e ...
disable_interrupts(global); // Inicializo el Micro y ...
disable_interrupts(int_timer1); // deshabilitando todo lo no necesario ...
disable_interrupts(int_rda);
disable_interrupts(int_ext);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp2(CCP_COMPARE_INT); // Configura CCP2 en modo COMPARE
set_timer1(VAL_TIMER1); // 65536-53000=12536*0,0002 = 2,5 ms
// Habilito las interrupciones necesarias
enable_interrupts(int_timer1); //Int timer 1
enable_interrupts(int_ccp2); // Habilito la interrpción INT_CCP2
enable_interrupts(global); //Habilita interrupciones
do
{
if(flag_timer1==TRUE) // Cuando se activa la int_timer1 -> cada 2,5 ms
{
servo++; //Controla secuencialmente cada servo
if (servo>=9) servo=1;
bit_set(*6,servo); // Pongo en alto el servo. Igual que output_high(PIN_Bx) pero le puedo pasar un parametro. *6=PORTB
CCP_2 = VAL_TIMER + pos_servo(servo); // Cargo CCP con el tiempo que tiene que estar en alto el servo
// La funcion pos_servo() debe devolver la posicion del servo en microsegundos
flag_timer1=FALSE;
}
}
while (TRUE);
}
CCP_2 = VAL_TIMER + pos_servo(servo);....lo que pasa es que no sé cuánto tiempo se tarda una instrucción en C ó mejor dicho no sé cómo medirla, alguién sabe como hacer? ...
#include <16f877.h>
#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)
#byte RCSTA= 0x018
#bit CREN= RCSTA.4 // Se activa para recepción continua
#bit OERR= RCSTA.1 // Error de Overrun
#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_01 = PORTB.0
#bit servo_02 = PORTB.1
#bit servo_03 = PORTB.2
#bit servo_04 = PORTB.3
#bit servo_05 = PORTB.4
#bit servo_06 = PORTB.5
#bit servo_07 = PORTB.6
#bit servo_08 = PORTB.7
#bit servo_09 = PORTD.0
#bit servo_10 = PORTD.1
#bit servo_11 = PORTD.2
#bit servo_12 = PORTD.3
#bit servo_13 = PORTD.4
#bit servo_14 = PORTD.5
#bit servo_15 = PORTD.6
#bit servo_16 = PORTD.7
#define n 16// número de servos, para otro número de servos hay que hacer mediciones de tiempo
#define max_theCount 50//
#define derecha 37
#define izquierda 18//
int8 servo[n];
int8 i=0;// es el índice exclusivo de servo[] en la recepción serial
// Recepción de datos
#int_rda
void rda_isr(void){//Está listo para recibir 16 bytes
servo[i]=getc();
if (servo[i]>derecha)// Nos aseguramos que el dato recibido esté en los limites
{
servo[i]=derecha;
};
if (servo[i]<izquierda)
{
servo[i]=izquierda;
};
i++;
if (i>(n-1)) i=0;
}
/////////////////////////////////////// PRINCIPAL /////////////////////////////////////
void main()
{
int8 theCount = 0;
int k;
set_tris_b(0x00);
set_tris_c(0b10000000);
set_tris_d(0x00);
PORTB=0x00;
PORTD=0x00;
port_b_pullups(FALSE);
for(k=0;k<=(n-1);k++)
servo[k]=izquierda;//
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(int_rda);
enable_interrupts(global);
while (1)
{
delay_us(13);
#asm
nop
nop
#endasm
servo_01= (servo[0] >= theCount);// Cada 50us llega aqui de forma cíclica
servo_02= (servo[1] >= theCount);
servo_03= (servo[2] >= theCount);
servo_04= (servo[3] >= theCount);
servo_05= (servo[4] >= theCount);
servo_06= (servo[5] >= theCount);
servo_07= (servo[6] >= theCount);
servo_08= (servo[7] >= theCount);
servo_09= (servo[8] >= theCount);
servo_10= (servo[9] >= theCount);
servo_11= (servo[10] >= theCount);
servo_12= (servo[11] >= theCount);
servo_13= (servo[12] >= theCount);
servo_14= (servo[13] >= theCount);
servo_15= (servo[14] >= theCount);
servo_16= (servo[15] >= theCount);
theCount++;
if (theCount>max_theCount) theCount=0;
}
}
#include <16f877.h>
#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)
#byte RCSTA= 0x018
#bit CREN= RCSTA.4 // Se activa para recepción continua
#bit OERR= RCSTA.1 // Error de Overrun
#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_01 = PORTB.0
#bit servo_02 = PORTB.1
#bit servo_03 = PORTB.2
#bit servo_04 = PORTB.3
#bit servo_05 = PORTB.4
#bit servo_06 = PORTB.5
#bit servo_07 = PORTB.6
#bit servo_08 = PORTB.7
#bit servo_09 = PORTD.0
#bit servo_10 = PORTD.1
#bit servo_11 = PORTD.2
#bit servo_12 = PORTD.3
#bit servo_13 = PORTD.4
#bit servo_14 = PORTD.5
#bit servo_15 = PORTD.6
#bit servo_16 = PORTD.7
#define n 16// número de servos, para otro número de servos hay que hacer mediciones de tiempo
#define max_theCount 50//
#define derecha 45
#define izquierda 8//
int8 duty[n];
int8 i=0;// es el índice exclusivo de servo[] en la recepción serial
int1 band=0;
// Recepción de datos
#int_rda
void rda_isr(void){//1er byte recibido indica el servo y el 2do byte el ciclo
if (band==0){
i=getc();
band=1;
}
else{
band=0;
duty[i]=getc();
}
}
/////////////////////////////////////// PRINCIPAL /////////////////////////////////////
void main()
{
int8 theCount=0;
int k;
set_tris_b(0x00);
set_tris_c(0b10000000);
set_tris_d(0x00);
PORTB=0x00;
PORTD=0x00;
port_b_pullups(FALSE);
for(k=0;k<=(n-1);k++)
duty[k]=izquierda;//
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(int_rda);
enable_interrupts(global);
while (1)
{
delay_us(13);
#asm
nop
nop
#endasm
servo_01= (duty[0] >= theCount);// Cada 50us llega aqui de forma cíclica
servo_02= (duty[1] >= theCount);
servo_03= (duty[2] >= theCount);
servo_04= (duty[3] >= theCount);
servo_05= (duty[4] >= theCount);
servo_06= (duty[5] >= theCount);
servo_07= (duty[6] >= theCount);
servo_08= (duty[7] >= theCount);
servo_09= (duty[8] >= theCount);
servo_10= (duty[9] >= theCount);
servo_11= (duty[10] >= theCount);
servo_12= (duty[11] >= theCount);
servo_13= (duty[12] >= theCount);
servo_14= (duty[13] >= theCount);
servo_15= (duty[14] >= theCount);
servo_16= (duty[15] >= theCount);
theCount++;
if (theCount>max_theCount) theCount=0;
}
}
#include <16f877.h>
#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)
#byte RCSTA= 0x018
#bit CREN= RCSTA.4 // Se activa para recepción continua
#bit OERR= RCSTA.1 // Error de Overrun
#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 25// 25*100us=2,5ms
#define centro 15// 15*100us=1,5ms
#define izquierda 5// 5*100us =0,5ms
/////////////////////////////////////// PRINCIPAL /////////////////////////////////////
void main()
{
int8 theCount=1;
int k;
int8 duty[n];
int8 i=0;// es el índice exclusivo de duty[] en la recepción serial
int1 band=0;
set_tris_b(0x00);
set_tris_c(0b10000000);
set_tris_d(0x00);
PORTB=0x00;
PORTD=0x00;
port_b_pullups(FALSE);
for(k=0;k<=(n-1);k++)
duty[k]=izquierda;//
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
disable_interrupts(global);
while (1)
{
delay_us(70);
#asm
nop
nop
nop
nop
#endasm
// Cada 100us llega aqui de forma cíclica
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
{
servo_09=0;
#asm
nop
#endasm
}
if (duty[10] >= theCount)
{
servo_10=1;
}
else
{
servo_10=0;
#asm
nop
#endasm
}
if (duty[11] >= theCount)
{
servo_11=1;
}
else
{
servo_11=0;
#asm
nop
#endasm
}
if (duty[12] >= theCount)
{
servo_12=1;
}
else
{
servo_12=0;
#asm
nop
#endasm
}
if (duty[13] >= theCount)
{
servo_13=1;
}
else
{
servo_13=0;
#asm
nop
#endasm
}
if (duty[14] >= theCount)
{
servo_14=1;
}
else
{
servo_14=0;
#asm
nop
#endasm
}
if (duty[15] >= theCount)
{
servo_15=1;
}
else
{
servo_15=0;
#asm
nop
#endasm
}
theCount=theCount+1;
if (theCount>max_theCount)
{
theCount=1;
}
else
{
delay_us(1);
#asm
nop
#endasm
}
// Recepción de datos
// Las rutinas delays y los nop son para normalizar los tiempos
if (kbhit()){
if (band==0){
i=getc();
band=1;
delay_us(1);
#asm
nop
nop
#endasm
}
else{
duty[i]=getc();
band=0;
}
}
else{
delay_us(3);
#asm
nop
#endasm
}
}
}
PD: Alguién me podría decir para que quieren controlar tantos servos? y perdonen mi desconocimiento.
...
Así que me he tirado a diseñar una PCB para 16 Servos y a ver qué resulta de ello, veremos si soy capaz de abrir un hilo titulado Algoritmo para controlar hasta 16 servos con una sola interrupción en C (o dos si son pequeñas)
...
Está montado alrededor de un 18F4550 con conexión USB y/o TTL Serie. Para los servos he destinado los puertos B y D completos, y he puesto otros de A y del C para poder recibir info de sensores y cosas así.
...
#include <16f877.h>
#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
{
servo_09=0;
#asm
nop
#endasm
}
if (duty[10] >= theCount)
{
servo_10=1;
}
else
{
servo_10=0;
#asm
nop
#endasm
}
if (duty[11] >= theCount)
{
servo_11=1;
}
else
{
servo_11=0;
#asm
nop
#endasm
}
if (duty[12] >= theCount)
{
servo_12=1;
}
else
{
servo_12=0;
#asm
nop
#endasm
}
if (duty[13] >= theCount)
{
servo_13=1;
}
else
{
servo_13=0;
#asm
nop
#endasm
}
if (duty[14] >= theCount)
{
servo_14=1;
}
else
{
servo_14=0;
#asm
nop
#endasm
}
if (duty[15] >= theCount)
{
servo_15=1;
}
else
{
servo_15=0;
#asm
nop
#endasm
}
theCount=theCount+1;
if (theCount>max_theCount)
{
theCount=1;
}
else
{
delay_us(1);
#asm
nop
#endasm
}
set_timer0(val_timer0);
}
/////////////////////////////////////// PRINCIPAL /////////////////////////////////////
void main()
{
int k;
int8 i=0;// es el índice exclusivo de duty[] en la recepción serial
int1 band=0;
set_tris_b(0x00);
set_tris_c(0b10000000);
set_tris_d(0x00);
PORTB=0x00;
PORTD=0x00;
port_b_pullups(FALSE);
for(k=0;k<=(n-1);k++)
duty[k]=izquierda;//
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_0(RTCC_DIV_2);
set_timer0(val_timer0);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while (1)
{
// Recepción de datos
if (kbhit()){
if (band==0){
i=getc();
band=1;
}
else{
duty[i]=getc();
band=0;
}
}
}
}
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN,NOBROWNOUT
#use delay(clock=48000000)//48MHz
#USE RS232 (baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
//#build(reset=0x000800,interrupt=0x000808:0x000818)
// Necesario para indicarle al compilador a partir de donde alojar mi programa
// Si se quiere usar bootloader se pueden habilitar estás dos líneas
//#ORG 0x000, 0x07FF {} // Espacio reservado para alojar el bootloader
#byte PORTA = 0xF80// Son las direcciones de memoria de los puertos en este PIC
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
/////////////////////////////////////////////////////////////////////////////
//
// CCS Library dynamic defines. For dynamic configuration of the CCS Library
// for your application several defines need to be made. See the comments
// at usb.h for more information
//
/////////////////////////////////////////////////////////////////////////////
#define USB_HID_DEVICE FALSE //deshabilitamos el uso de las directivas HID
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 2 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 2 //size to allocate for the rx endpoint 1 buffer
/////////////////////////////////////////////////////////////////////////////
//
// If you are using a USB connection sense pin, define it here. If you are
// not using connection sense, comment out this line. Without connection
// sense you will not know if the device gets disconnected.
// (connection sense should look like this:
// 100k
// VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
// |
// +----/\/\/\/\/\-----GND
// 100k
// (where VBUS is pin1 of the USB connector)
//
/////////////////////////////////////////////////////////////////////////////
//#define USB_CON_SENSE_PIN PIN_B2 //CCS 18F4550 development kit has optional conection sense pin
/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries. See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////
#include <pic18_usb.h> //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <PicUSB.h> //Configuración del USB y los descriptores para este dispositivo
#include <usb.c> //handles usb setup tokens and get descriptor reports
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#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 i_usb recibe[0]// es el índice que se recibe vía usb
#define pos_usb recibe[1]// es la posición que se recibe vía usb
#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 25// 25*100us=2,5ms
#define centro 15// 15*100us=1,5ms
#define izquierda 5// 5*100us =0,5ms
#define val_timer0 127
int8 theCount=1;
int8 duty[n];
#INT_TIMER0
void isr_timer0(){
delay_cycles(5);
if (duty[0] >= theCount)// Cada 100us llega aqui de forma cíclica
{
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
{
servo_09=0;
#asm
nop
#endasm
}
if (duty[10] >= theCount)
{
servo_10=1;
}
else
{
servo_10=0;
#asm
nop
#endasm
}
if (duty[11] >= theCount)
{
servo_11=1;
}
else
{
servo_11=0;
#asm
nop
#endasm
}
if (duty[12] >= theCount)
{
servo_12=1;
}
else
{
servo_12=0;
#asm
nop
#endasm
}
if (duty[13] >= theCount)
{
servo_13=1;
}
else
{
servo_13=0;
#asm
nop
#endasm
}
if (duty[14] >= theCount)
{
servo_14=1;
}
else
{
servo_14=0;
#asm
nop
#endasm
}
if (duty[15] >= theCount)
{
servo_15=1;
}
else
{
servo_15=0;
#asm
nop
#endasm
}
theCount=theCount+1;
if (theCount>max_theCount)
{
theCount=1;
}
else
{
delay_us(1);
#asm
nop
#endasm
}
set_timer0(val_timer0);
}
/////////////////////////////////////// PRINCIPAL /////////////////////////////////////
void main()
{
int k;
int8 i=0;// es el índice exclusivo de duty[] en la recepción serial
int1 band=0;
int8 recibe[2];// Buffer de recepción vía usb
//int8 envia[2];// Habilitar en caso de necesitar
set_tris_b(0x00);
set_tris_c(0b10000000);
set_tris_d(0x00);
PORTB=0x00;
PORTD=0x00;
port_b_pullups(FALSE);
for(k=0;k<=(n-1);k++)
duty[k]=centro;//
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_DIV_8 | RTCC_8_BIT);
set_timer0(val_timer0);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
usb_init();//inicializamos el USB
usb_task();//habilita periférico usb e interrupciones
usb_wait_for_enumeration();//esperamos hasta que el PicUSB sea configurado por el host
while (TRUE)
{
if(usb_enumerated())//si el PicUSB está configurado
//if (TRUE)
{
// Recepción de datos via rs232
if (kbhit()){
if (band==0){
i=getc();
band=1;
}
else{
duty[i]=getc();
band=0;
}
}
// Recepción vía USB
if (usb_kbhit(1))//El endpoint de salida contiene datos del host (EP1)?
{
usb_get_packet(1, recibe, 2);// Recibimos los 2 bytes: (servo,pos)
duty[i_usb]=pos_usb;
}
}
}
}
Hola Guillermo
Felicitaciones!!! lo trato de probar ahora :-/
... esta muy padre
...
...
Agregando
En teoria :D , bueno bueno en mi mente soñadora :D ... tenemos 2.5 ms por maximo que estarian trabajando los servos y 17.5 ms libres para realizar todas las operaciones necesarias.
Estoy zombie :shock:...
Bueno aquí está el código para controlar 16 servos con el pic18f4550, le podemos enviar comandos tanto vía serial RS232 como vía USB, la trama es (SERVO,POSICIÓN), SERVO=[0..15] y POSICIÓN=[5..25], donde 5=extremo izquierdo y 25=extremo derecho.Código: [Seleccionar]#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN,NOBROWNOUT
#use delay(clock=48000000)//48MHz
#USE RS232 (baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
//#build(reset=0x000800,interrupt=0x000808:0x000818)
// Necesario para indicarle al compilador a partir de donde alojar mi programa
// Si se quiere usar bootloader se pueden habilitar estás dos líneas
//#ORG 0x000, 0x07FF {} // Espacio reservado para alojar el bootloader
#byte PORTA = 0xF80// Son las direcciones de memoria de los puertos en este PIC
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
/////////////////////////////////////////////////////////////////////////////
//
// CCS Library dynamic defines. For dynamic configuration of the CCS Library
// for your application several defines need to be made. See the comments
// at usb.h for more information
//
/////////////////////////////////////////////////////////////////////////////
#define USB_HID_DEVICE FALSE //deshabilitamos el uso de las directivas HID
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 2 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 2 //size to allocate for the rx endpoint 1 buffer
/////////////////////////////////////////////////////////////////////////////
//
// If you are using a USB connection sense pin, define it here. If you are
// not using connection sense, comment out this line. Without connection
// sense you will not know if the device gets disconnected.
// (connection sense should look like this:
// 100k
// VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
// |
// +----/\/\/\/\/\-----GND
// 100k
// (where VBUS is pin1 of the USB connector)
//
/////////////////////////////////////////////////////////////////////////////
//#define USB_CON_SENSE_PIN PIN_B2 //CCS 18F4550 development kit has optional conection sense pin
/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries. See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////
#include <pic18_usb.h> //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <PicUSB.h> //Configuración del USB y los descriptores para este dispositivo
#include <usb.c> //handles usb setup tokens and get descriptor reports
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#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 i_usb recibe[0]// es el índice que se recibe vía usb
#define pos_usb recibe[1]// es la posición que se recibe vía usb
#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 25// 25*100us=2,5ms
#define centro 15// 15*100us=1,5ms
#define izquierda 5// 5*100us =0,5ms
#define val_timer0 127
int8 theCount=1;
int8 duty[n];
#INT_TIMER0
void isr_timer0(){
delay_cycles(5);
if (duty[0] >= theCount)// Cada 100us llega aqui de forma cíclica
{
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
{
servo_09=0;
#asm
nop
#endasm
}
if (duty[10] >= theCount)
{
servo_10=1;
}
else
{
servo_10=0;
#asm
nop
#endasm
}
if (duty[11] >= theCount)
{
servo_11=1;
}
else
{
servo_11=0;
#asm
nop
#endasm
}
if (duty[12] >= theCount)
{
servo_12=1;
}
else
{
servo_12=0;
#asm
nop
#endasm
}
if (duty[13] >= theCount)
{
servo_13=1;
}
else
{
servo_13=0;
#asm
nop
#endasm
}
if (duty[14] >= theCount)
{
servo_14=1;
}
else
{
servo_14=0;
#asm
nop
#endasm
}
if (duty[15] >= theCount)
{
servo_15=1;
}
else
{
servo_15=0;
#asm
nop
#endasm
}
theCount=theCount+1;
if (theCount>max_theCount)
{
theCount=1;
}
else
{
delay_us(1);
#asm
nop
#endasm
}
set_timer0(val_timer0);
}
/////////////////////////////////////// PRINCIPAL /////////////////////////////////////
void main()
{
int k;
int8 i=0;// es el índice exclusivo de duty[] en la recepción serial
int1 band=0;
int8 recibe[2];// Buffer de recepción vía usb
//int8 envia[2];// Habilitar en caso de necesitar
set_tris_b(0x00);
set_tris_c(0b10000000);
set_tris_d(0x00);
PORTB=0x00;
PORTD=0x00;
port_b_pullups(FALSE);
for(k=0;k<=(n-1);k++)
duty[k]=centro;//
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_DIV_8 | RTCC_8_BIT);
set_timer0(val_timer0);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
usb_init();//inicializamos el USB
usb_task();//habilita periférico usb e interrupciones
usb_wait_for_enumeration();//esperamos hasta que el PicUSB sea configurado por el host
while (TRUE)
{
if(usb_enumerated())//si el PicUSB está configurado
//if (TRUE)
{
// Recepción de datos via rs232
if (kbhit()){
if (band==0){
i=getc();
band=1;
}
else{
duty[i]=getc();
band=0;
}
}
// Recepción vía USB
if (usb_kbhit(1))//El endpoint de salida contiene datos del host (EP1)?
{
usb_get_packet(1, recibe, 2);// Recibimos los 2 bytes: (servo,pos)
duty[i_usb]=pos_usb;
}
}
}
}
Adjunto archivos de simulación en Proteus, Driver y Aplicación.
Adicionalmente realicé una sencilla interfaz (Gracias a J1M (http://www.todopic.com.ar/foros/index.php?topic=2260.0)) para controlar los servos vía usb, aquí una imagen funcionando:
(http://img134.imageshack.us/img134/3444/pic18servo16pq7.jpg)Hola Guillermo
Felicitaciones!!! lo trato de probar ahora :-/
... esta muy padre
...
Gracias nuevamente :lol: en verdad es muy agradable cuando reconocen nuestro trabajo y no cualquier trabajo sino el que se hace con esfuerzo, empeño y por supuesto con cariño también, así como muchos foristas que todavía no me sé todos los nombres porque soy relativamente nuevo en el mismo pero si me pidieran nombres estos son los que me suenan (no hay ningún orden en específico): Palitroquez, Nocturno, RedPic, Maunix, J1M, JLIGUAL, MGLSOFT, PICmouse, Modulay, entre otros destacados y a todos los foristas en general porque cada día hacemos que éste foro sea el mejor foro en internet en cuanto a pic y un poco más ;-), saludos a todos, pero absolutamente a todos y gracias!, muchas gracias!!!
Que la pasen bien.
#include <18f4550.h>
#fuses HS,NOMCLR,PUT,NOWDT,NOPROTECT,BROWNOUT,NOLVP,NOCPD,NODEBUG,NOWRT
#use delay(clock=20000000)
#use fast_io(D)
#use fast_io(B)
#priority timer1
#define SERVO1 PIN_D7
#define SERVO2 PIN_D6
#define SERVO3 PIN_D5
#define SERVO4 PIN_D4
#define SERVO5 PIN_D3
#define SERVO6 PIN_D2
#define SERVO7 PIN_D1
#define SERVO8 PIN_D0
const int16 TOTAL = 12500; // PWM Window for servo = 2.5 ms x 8 = 20 ms
//const int16 Ticks4Minimum = 3500; // PWM High for Minimum Position = 0.7 ms
//const int16 Ticks4Center = 7500; // PWM High for Center Position = 1.5 ms
///const int16 Ticks4Maximum = 11500; // PWM High for Maximum Position = 2.3 ms
int16 TIEMPOS[8]={7500,3500,7500,0,0,0,0,0};
static int8 NUMSERVO=0;
static int1 SERVO1_ON=1;
static int1 SERVO2_ON=1;
static int1 SERVO3_ON=1;
static int1 SERVO4_ON=0;
static int1 SERVO5_ON=0;
static int1 SERVO6_ON=0;
static int1 SERVO7_ON=0;
static int1 SERVO8_ON=0;
static int1 ENTRADAS;
static int16 SIGUIENTEINT=53036;
#int_timer1
void timer1_isr(void){
if(ENTRADAS==0){
if(NUMSERVO==0 && SERVO1_ON) output_high(SERVO1);
if(NUMSERVO==1 && SERVO2_ON) output_high(SERVO2);
if(NUMSERVO==2 && SERVO3_ON) output_high(SERVO3);
if(NUMSERVO==3 && SERVO4_ON) output_high(SERVO4);
if(NUMSERVO==4 && SERVO5_ON) output_high(SERVO5);
if(NUMSERVO==5 && SERVO6_ON) output_high(SERVO6);
if(NUMSERVO==6 && SERVO7_ON) output_high(SERVO7);
if(NUMSERVO==7 && SERVO8_ON) output_high(SERVO8);
SIGUIENTEINT = 65535 - TIEMPOS[NUMSERVO];
set_timer1(SIGUIENTEINT);
}
if(ENTRADAS==1){
if(NUMSERVO==0 && SERVO1_ON) output_low(SERVO1);
if(NUMSERVO==1 && SERVO2_ON) output_low(SERVO2);
if(NUMSERVO==2 && SERVO3_ON) output_low(SERVO3);
if(NUMSERVO==3 && SERVO4_ON) output_low(SERVO4);
if(NUMSERVO==4 && SERVO5_ON) output_low(SERVO5);
if(NUMSERVO==5 && SERVO6_ON) output_low(SERVO6);
if(NUMSERVO==6 && SERVO7_ON) output_low(SERVO7);
if(NUMSERVO==7 && SERVO8_ON) output_low(SERVO8);
SIGUIENTEINT = 65535 - TOTAL + TIEMPOS[NUMSERVO];
set_timer1(SIGUIENTEINT);
if(++NUMSERVO>7) NUMSERVO=0;
}
++ENTRADAS;
}
void main(void) {
disable_interrupts(global);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_0(RTCC_OFF);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED);
port_b_pullups(TRUE);
set_tris_D(0b00000000);
set_tris_B(0b11111111);
output_low(SERVO1);
output_low(SERVO2);
output_low(SERVO3);
output_low(SERVO4);
output_low(SERVO5);
output_low(SERVO6);
output_low(SERVO7);
output_low(SERVO8);
delay_ms(1000);
set_timer1(SIGUIENTEINT);
enable_interrupts(int_timer1);
enable_interrupts(global);
do {
IF(INPUT(PIN_B0)&&TIEMPOS[0]<11000){
IF(!INPUT(PIN_B0)&&TIEMPOS[0]<11000){
TIEMPOS[0]=TIEMPOS[0]+ 250;
}
}
IF(INPUT(PIN_B1)&&TIEMPOS[0]>3800){
IF(!INPUT(PIN_B1)&&TIEMPOS[0]<11000){
TIEMPOS[0]=TIEMPOS[0] - 250;
}
}
} while (TRUE);
}
por favor estoy algo desesperado con esto espero que me puedan ayudar a encontrar la solucion.