Esempio n. 1
0
/*********************************************************************//**
 * @brief		TIMER1 interrupt handler sub-routine
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void TIMER1_IRQHandler(void)
{
	if (TIM_GetIntCaptureStatus(LPC_TIM1,0))
	{
		TIM_ClearIntCapturePending(LPC_TIM1,0);
		_DBG("Time capture: ");
		_DBH32(TIM_GetCaptureValue(LPC_TIM1,0));_DBG_("");
	}
}
Esempio n. 2
0
void TIMER2_IRQHandler(void){
    if(upflag == 0){
      risVal = TIM_GetCaptureValue(LPC_TIM2, TIM_COUNTER_INCAP0);
      upflag = 1;
    }else{
      upflag = 0;
      ultradist = TIM_GetCaptureValue(LPC_TIM2, TIM_COUNTER_INCAP0) - risVal;
      if(ultradist < 0){
        ultradist = -1;
      }
      TIM_ResetCounter(LPC_TIM2);
    }
  TIM_ClearIntCapturePending(LPC_TIM2, TIM_CR0_INT);
}
/*********************************************************************//**
 * @brief	TIM1 interrupt handler sub-routine
 * @param	None
 * @return	None
 **********************************************************************/
void TIMER1_IRQHandler(void)
{
	if (TIM_GetIntCaptureStatus(LPC_TIM1,0))
	{
		TIM_ClearIntCapturePending(LPC_TIM1,0);
		if(first_capture==TRUE)
		{
			TIM_Cmd(LPC_TIM1,DISABLE);
			TIM_ResetCounter(LPC_TIM1);
			TIM_Cmd(LPC_TIM1,ENABLE);
			count++;
			if(count==20)first_capture=FALSE; //stable
		}
		else
		{
			count=0; //reset count for next use
			done=TRUE;
			capture = TIM_GetCaptureValue(LPC_TIM1,0);
		}
	}
}
Esempio n. 4
0
void TIMER0_IRQHandler(void)
{
static signed int comodin = 10;       //Se usa comodin para dar el valor inicial
									  //ya que se debe asignar un valor fijo al momento de
									  //compilación.-


static signed int valor_relativo = 0; //Almacenará el valor del timer capturado cuando interrumpe
static signed int valor_absoluto = 0; //Almacenará el valor en useg acumulados entre flancos
static signed int cero = 0;           //Es el cero que tomará el valor final del nivel anterior




if (habilitacion==TRUE){              //Estoy habilitado para operar?

	if (comodin==10){ cero = TIM_GetCaptureValue(LPC_TIM0,0); //Es la primera vez?
					  comodin=20;                             //Cambio el valor para no volver
					}

	valor_relativo=TIM_GetCaptureValue(LPC_TIM0,0);	//Copio el valor del timer capturado
	valor_absoluto=valor_relativo-cero; //Me quedo con el valor absolito de tiempo en useg

	if (valor_absoluto>MAX_FULL_BIT) //Me fijo si ese valor está fuera del valor máximo según norma
		{							 //Si era mayor es un error. Acá puede caer, si por ejemplo
		sys = 0;					 //habilito la medición y decodificación y justo cae en medio
		cmd = 0;                     //de un código.
		}

	if (GPIO_ReadValue(0) & (1<<24)) // Chequeo el GPIO P0.24 para ver que tipo de flanco es
		{
		if (sys == 0) // Es el primer pulso?
			{
			low_time = HALF_BIT_TIME; // Asumo tiempo corto en nivel bajo
			high_time = HALF_BIT_TIME; // Asumo tiempo corto en nivel alto
			half_bit = 1; // Asumo que es la mitad de un bit
			cmd = 0x02; // = 00000010, Preparo el byte del comando
			}
		else
		{
			low_time = valor_absoluto; // Es flanco positivo, copio valor bajo
		}
		RC5_Decode();
		}
	else
		high_time = valor_absoluto; //Sino en flanco negativo, copio valor alto

	cero=valor_relativo; //El valor del final del nivel (alto o bajo) será mi nuevo cero
	TIM_ClearIntCapturePending(LPC_TIM0,0); //Reseteo la interrupción
}

if (habilitacion==FALSE){ //Si estoy acá, estoy en el tiempo donde no habilito la ,
						  //edición y decodificación. Lo hago para que no detecte muchos pulsos
					      //en un pulsado.

	valor_relativo=TIM_GetCaptureValue(LPC_TIM0,0); //Analizo cuanto tiempo pasó desde el último
	valor_absoluto=valor_relativo-cero;				//flanco.
	if (valor_absoluto>RETARDO) //Si es mayor a RETARDO useg
	{
		habilitacion=TRUE;  //Ya pasó el tiempo de resguardo
		cero=valor_relativo; //Actualizo el cero
		TIM_ClearIntCapturePending(LPC_TIM0,0); //Reseteo interrupción
	}
	else TIM_ClearIntCapturePending(LPC_TIM0,0); //Si no pasó el tiempo sólo reseteo interrupción

}

}