Buenas Tardes acudo ante ustedes para solicitar su ayuda acerca de este pic 18f452, estoy intentando usar el TIMER0 y el TIMER1 como contadores independientes que detecten un flanco de bajo a alto, con ellos quiero crear dos variables de 32 bits, el problema es que el pic se esta reseteando cuando dejo contando con cualquiera de los 2 contadores, al paso de un tiempo se resetea el equipo, y me manda el tipo de reseto, MCLR_FROM_RUN, no se como quitar este error y evitar que se este reseteando el pic agradezco su ayuda de ante mano, mi codigo es el siguiente
//////// Fuses: LP,XT,HS,RC,EC,EC_IO,H4,RC_IO,PROTECT,NOPROTECT,OSCSEN
//////// Fuses: NOOSCSEN,NOBROWNOUT,BROWNOUT,WDT1,WDT2,WDT4,WDT8,WDT16,WDT32
//////// Fuses: WDT64,WDT128,WDT,NOWDT,BORV20,BORV27,BORV42,BORV45,PUT,NOPUT
//////// Fuses: CCP2C1,CCP2B3,NOSTVREN,STVREN,NODEBUG,DEBUG,NOLVP,LVP,WRT
//////// Fuses: NOWRT,NOWRTD,WRTD,NOWRTB,WRTB,WRTC,NOWRTC,CPD,NOCPD,CPB
//////// Fuses: NOCPB,EBTR,NOEBTR,EBTRB,NOEBTRB
#include <18F452.h>
#device ADC=10
#include <stdlib.h>
#fuses HS
#fuses NOPROTECT
#fuses OSCSEN
#fuses NOBROWNOUT
#fuses NOWDT
#fuses NOPUT
#fuses NOSTVREN
#fuses NODEBUG
#fuses NOLVP
#fuses NOWRT
#fuses NOWRTD
#fuses NOWRTB
#fuses NOWRTC
#fuses NOCPD
#fuses NOCPB
#fuses NOEBTR
#fuses NOEBTRB
#use delay(clock=20000000)
#use rs232(baud=19200, xmit=PIN_C6, RCV=PIN_C7)
//--------------------------------------------
#byte T0CON = 0xFD5
//Definicion de Constantes
#define NUM_PULSES_0 0x00
#define NUM_PULSES_1 0x0000
//Variables Globales
// static long CntRight=0,CntLeft=0;
// int32 gasometro=0,odometro;
// int16 gas1=0,gas2=0;
int8 g4=0,g3=0,g2=0,g1=0;
int16 odo1=0,odo2=0;
int32 gasometro=0,odometro=0;
//Esta interrupcion es llamada en forma automatica por el TIMER0 cuando se desborda(0xFF).
#INT_TIMER0
void timer0(){
g3++; //EN ESTA FUNCION TRANFORMAMOS EL CONTADOR DE 8 BITS A UN CONTADOR DE 32 BITS
//--------------------
if(g3==0){ //CON LA AYUDA DE 4 VARIABLES DE 8 BITS
g2++;
if(g2==0){
g1++;
}
}
//--------------------
gasometro=make32(g1,g2,g3,g4); //FUNCION make32 CONVIERTE 4 VARIABLES DE 8 BITS A UNA DE 32 BITS Y LA ASIGNA A LA VARIABLE1
// gasometro++;
printf("\n\rSOBREFLUJO TIMER0 gasometro:%lu ",gasometro);
set_timer0(NUM_PULSES_0);
}
//Esta interrupcion es llamada en forma automatica por el TIMER1 cuando se desborda(0xFFFF).
#INT_TIMER1
void wave_timer1(){
odo1++; //EN ESTA FUNCION TRANFORMAMOS EL CONTADOR DE 16 BITS A UN CONTADOR DE 32 BITS
odometro=make32(odo1,odo2); //FUNCION make32 CONVIERTE 2 VARIABLES DE 16 BITS A UNA DE 32 BITS Y LA ASIGNA A LA VARIABLE2
printf("\n\rSOBREFLUJO TIMER1 odometro:%lu ",odometro);
set_timer1(NUM_PULSES_1);
}
//Inicializa interrupciones
void inicializa_interrupciones(){
set_timer1(NUM_PULSES_1); //inicializamos el valor con el que inicia el contador del Timer1
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1); //configuramos el Timer1 como contador y preescalador de 1.
enable_interrupts(INT_TIMER1); //Habilitamos la interrupcion para cuando se desborde el Timer1
set_timer0(NUM_PULSES_0); //Inicializamos el valor con el que inicia el contador del Timer0
setup_timer_0(RTCC_INTERNAL|RTCC_EXT_L_TO_H|RTCC_8_BIT|RTCC_DIV_1);
enable_interrupts(INT_TIMER0); //Habilitamos la interrupcion para cuando se desborda el Timer0
enable_interrupts(GLOBAL); //Habilitamos las interrupciones del Pic si no no servirian las interrupcciones de los Timers
}
void main(){
////
switch ( restart_cause() ) {
case WDT_TIMEOUT:
printf("\n\rWDT_TIMEOUT");
break;
case MCLR_FROM_SLEEP:
printf("\n\rMCLR_FROM_SLEEP");
break;
case MCLR_FROM_RUN:
printf("\n\rMCLR_FROM_RUN");
break;
case NORMAL_POWER_UP:
printf("\n\rNORMAL_POWER_UP");
break;
case BROWNOUT_RESTART:
printf("\n\rBROWNOUT_RESTART");
break;
case WDT_FROM_SLEEP:
printf("\n\rWDT_FROM_SLEEP");
break;
case RESET_INSTRUCTION:
printf("\n\rRESET_INSTRUCTION");
break;
default: break;
}
//////////////////////////////////////////////////
inicializa_interrupciones();
while(1){
g4=get_timer0(); //Leemos el contenido del contador del Timer1
gasometro=make32(g1,g2,g3,g4); //FUNCION make32 CONVIERTE 4 VARIABLES DE 8 BITS A UNA DE 32 BITS Y LA ASIGNA A LA VARIABLE1
odo2=get_timer1(); //Leemos el contenido del contador del Timer1
odometro=make32(odo1,odo2);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////