void EXT_isr(void) { unsigned int16 pulse_buff =0; pulse_buff = get_timer1(); //printf("\r\n %lu \t\t %d \r\n",pulse_buff,pulse_count); if(pulse_count == 0) { enable_timer1(); // enable_interrupts(INT_TIMER1); pulse_count++; } else { if(pulse_buff < MIN_PULSE_WIDTH) { if(pulse_count>FILTER_VALUE) { printf("a"); } // printf("\r\n %lu \t\t %d \r\n",pulse_buff,pulse_count); IDLE_MODE(); } else { pulse_count++ ; } } }
void baseTime( void ) { static unsigned long int cnt1s = 0; set_timer1( 34285 + get_timer1() ); cnt1s++; //Para testes, coloquei a base de tempo para contar somente 1 segundo. O valor correto da comparação abaixo deve ser // 1200 if( cnt1s >= 20 ) { cnt1s = 0; Clock.time.minuto++; if( Clock.time.minuto > 59 ) { Clock.time.minuto = 0; Clock.time.hora++; if( Clock.time.hora > 23 ) { Clock.time.hora = 0; } } } }
void main() { setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard // enable_interrupts(INT_EXT); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); //32.7 ms overflow enable_interrupts(INT_TIMER0); enable_interrupts(INT_RDA); //enable_interrupts(INT_TIMER1); enable_interrupts(GLOBAL); // setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//128ms overflow ext_int_edge( H_TO_L ); // Sets up EXT setup_timer_1 (T1_DISABLED ); printf("NguyenHung \n \r DT5 - K53 - DHBKHN \n \r"); printf("Ready to use !! \n\r "); TC3 = 0; RC3 = 1; while(true) { if(get_timer1() > MAX_PULSE_WIDTH) { if(pulse_count>FILTER_VALUE) { printf("W"); IDLE_MODE(); } } } }
void baseTime( void ) { static unsigned long int cnt1s = 0; set_timer1( TIMER_CONFIGURATIONS + get_timer1() ); //Se o laço 1 da via 1 tiver sido acionado, começo a contar o tempo if( via1.flgs.laco == 1 ) { via1.flgs.tempo++; } //se o laço 2 da via 1 tiver sido acionado, paro de contar o tempo e indico a máquina principal que a velocidade deve ser mostrada else if( via1.flgs.laco == 2 ) { via1.flgs.laco = 3; } //Se o laço 1 da via 2 tiver sido acionado, começo a contar o tempo if( via2.flgs.laco == 1 ) { via2.flgs.tempo++; } //se o laço 2 da via 2tiver sido acionado, paro de contar o tempo e indico a máquina principal que a velocidade deve ser mostrada else if( via2.flgs.laco == 2 ) { via2.flgs.laco = 3; printf("\n\rFINAL \n\r"); } }
void baseTime( void ) { static unsigned long int cnt1s = 0; set_timer1( TIMER_CONFIGURATIONS + get_timer1() ); //Se o laço 1 tiver sido acionado, começo a contar o tempo }
void timeproc() { set_timer1(get_timer1() + 15536); // 10msec at 20MHz dcfpulsetime++; dcfdeltatimer++; timeout10msec = 1; if (!(--timer400msec)) { timer400msec = 40; timeout400msec = 1; } }
// look at step and direction data inputs at timers 1&5 to generate new position void CalculateExtCount() { int16 t1count; int16 t5count; if (!STATUS.pid_lock || STATUS.error) return; t1count = prev_t1count; t5count = prev_t5count; prev_t1count = get_timer1(); prev_t5count = get_timer5(); servo_cmd+= (signed long)((prev_t1count-t1count)-(prev_t5count-t5count)); }
void int_trigger(void) { #if TRIGGER_TYPE == ULTRASONIC_SENSOR if (usonic_state == USONIC_STATE_START) { // Tomo el tiempo en que comienza el pulso pulseStart = get_timer1(); // Cambio el tipo de flanco ext_int_edge(H_TO_L); // Cambio el estado usonic_state = USONIC_STATE_STOP; } else { // Tomo el tiempo y guardo el valor values[5] = (get_timer1() - pulseStart)/2; // Deshabilita la interupcion disable_interrupts(INT_EXT); } #elif TRIGGER_TYPE == SWITCH_SENSOR triggerAlarm = 1; #endif }
void Ultras(){ output_high(trig); delay_us(20); output_low(trig); while(!input(echo)) {} set_timer1(0); while(input(echo)) {} tiempo=get_timer1(); distancia=(tiempo*10)/(58.0); output_high(trig2); delay_us(20); output_low(trig2); while(!input(echo2)) {} set_timer1(0); while(input(echo2)) {} tiempo2=get_timer1(); distancia2=(tiempo2*10)/(58.0); }
void main(void) { long time; float a, b, c; a = 5; b = 100; setup_timer_1(T1_INTERNAL | T1_DIV_BY_1); set_timer1(0); c = a * b; //printf("test"); time = get_timer1(); time -= 2; printf("\r\n The program takes %lu clock cycles", time); printf("\r\n Each clock cycle is %lu microseconds \r\n", (time+2)/5); printf("\r\n Total time is %lu microseconds \r\n", time * (time+2)/5); }
void trata_t1 () { led = !led; // inverte o led - pisca a cada 0,5 seg. output_bit (pin_b7,led); set_timer1(3036 + get_timer1()); }