///////////////////////////////////////////
// Lectura de Encoder de 2 canales //
// SIMPLE PRECISION //
// //
// Por: JJcorps //
///////////////////////////////////////////
#include <16F876.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#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 NODEBUG //No Debug mode for ICD
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
char BorraLCD=12;
int16 pasos=0;
int sentido=1;
#int_EXT
void EXT_isr(void)
{
if(input(PIN_B1)) //Miro el estado de el otro canal q me indica el sentido
{
sentido=1;
pasos=pasos+1;
}
else
{
sentido=0;
pasos=pasos-1;
}
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
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);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
// TODO: USER CODE!!
while(1)
{
printf("%cPasos: %Li\rSentido: ",BorraLCD,pasos);
if(sentido==1)
printf("derecha");
else
printf("izquierda");
delay_ms(100);
}
}#include <16F876.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#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 NODEBUG //No Debug mode for ICD
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use fast_io(b)
char BorraLCD=12;
unsigned int16 pasos=0;
#int_RB
void RB_isr(void)
{
pasos=pasos+1;
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
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);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
SET_TRIS_B(0x00);
// TODO: USER CODE!!
while(1)
{
printf("%cPasos: %Lu",BorraLCD,pasos);
delay_ms(100);
}
}NO se si es la respuesta correcta o si la he entendido yo bien la cuestión pero el terminar con lo de "algún otro chip "...., ´¿has mirado la serie de pics 18F2331,2431, 4331, 4431; todos estos llevan incorporado en hardware un modulo de control QEI que funcionan a x4.
Un saludo