Esempio n. 1
0
float TimerCapture(void){
  PINSEL_CFG_Type PinCfg;
  PinCfg.Funcnum = 3;
  PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinCfg.Pinmode = PINSEL_PINMODE_PULLDOWN;
  PinCfg.Portnum = 0;
  PinCfg.Pinnum = 4;
  PINSEL_ConfigPin(&PinCfg);


  TIM_CAPTURECFG_Type captcfg;
  captcfg.CaptureChannel = 0;
  captcfg.IntOnCaption = ENABLE;
  captcfg.FallingEdge = ENABLE;
  captcfg.RisingEdge = ENABLE;

  TIM_TIMERCFG_Type timercfg;
  timercfg.PrescaleOption = TIM_PRESCALE_USVAL;
  timercfg.PrescaleValue = 1;

  TIM_Init(LPC_TIM2, TIM_TIMER_MODE, &timercfg);
  TIM_ConfigCapture(LPC_TIM2, &captcfg);


  NVIC_SetPriority(TIMER2_IRQn, ((0x01<<3)|0x01));
  NVIC_EnableIRQ(TIMER2_IRQn);
  TIM_Cmd(LPC_TIM2, ENABLE);

  return ultradist;
}
Esempio n. 2
0
/*********************************************************************//**
 * @brief		c_entry: Main TIMER program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	//Config P1.26 as CAP0.0
	PinCfg.Funcnum = 3;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 1;
	PinCfg.Pinnum = 26;
	PINSEL_ConfigPin(&PinCfg);

	// Initialize timer 0, prescale count time of 1000000uS = 1S
	TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
	TIM_ConfigStruct.PrescaleValue	= 1000000;

	// use channel 0, CAPn.0
	TIM_CaptureConfigStruct.CaptureChannel = 0;
	// Enable capture on CAPn.0 rising edge
	TIM_CaptureConfigStruct.RisingEdge = ENABLE;
	// Enable capture on CAPn.0 falling edge
	TIM_CaptureConfigStruct.FallingEdge = ENABLE;
	// Generate capture interrupt
	TIM_CaptureConfigStruct.IntOnCaption = ENABLE;


	// Set configuration for Tim_config and Tim_MatchConfig
	TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
	TIM_ConfigCapture(LPC_TIM0, &TIM_CaptureConfigStruct);
	TIM_ResetCounter(LPC_TIM0);


	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01));
	/* Enable interrupt for timer 0 */
	NVIC_EnableIRQ(TIMER0_IRQn);
	// To start timer 0
	TIM_Cmd(LPC_TIM0,ENABLE);

	while (1);
	return 1;
}
Esempio n. 3
0
 void RC5_Init(void)
 {


		 reseteo_general=0;  // Esto estaba en el main() antes.


	     //Config P1.26 as CAP0.0
	     PinCfg.Funcnum = PINSEL_FUNC_3;
	     PinCfg.OpenDrain = 0;
	     PinCfg.Pinmode = 0;
	     PinCfg.Portnum = PINSEL_PORT_1;
	     PinCfg.Pinnum = PINSEL_PIN_26;
	     PINSEL_ConfigPin(&PinCfg);

	     //Config P0.24 como GPIO
	     PinCfg.Funcnum=PINSEL_FUNC_0;
	     PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
	     PinCfg.Pinmode = PINSEL_PINMODE_PULLUP;
	     PinCfg.Pinnum = PINSEL_PIN_24;
	     PinCfg.Portnum = PINSEL_PORT_0;
	     PINSEL_ConfigPin(&PinCfg);


	     // Initialize timer 0, prescale count time of 1000000uS = 1S lo cambio yo
	     TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
	     TIM_ConfigStruct.PrescaleValue   = 1;

	     // use channel 0, CAPn.0
	     TIM_CaptureConfigStruct.CaptureChannel = 0;
	     // Enable capture on CAPn.0 rising edge
	     TIM_CaptureConfigStruct.RisingEdge = ENABLE;
	     // Enable capture on CAPn.0 falling edge
	     TIM_CaptureConfigStruct.FallingEdge = ENABLE;
	     // Generate capture interrupt
	     TIM_CaptureConfigStruct.IntOnCaption = ENABLE;


	     // Set configuration for Tim_config and Tim_MatchConfig
	     TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
	     TIM_ConfigCapture(LPC_TIM0, &TIM_CaptureConfigStruct);
	     TIM_ResetCounter(LPC_TIM0);


	     /* preemption = 1, sub-priority = 1 */
	     NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01));
	     /* Enable interrupt for timer 0 */
	     NVIC_EnableIRQ(TIMER0_IRQn);
	     // To start timer 0
	     TIM_Cmd(LPC_TIM0,ENABLE);
} // --> RC5
/********************************************************************//**
* @brief		Configures the TIM1 peripheral according to the specified
*               parameters.
* @param[in]	None
* @return 		None
*********************************************************************/
void TIM1_Config (void)
{
	// TIM Configuration structure variable
	TIM_TIMERCFG_Type TIM_ConfigStruct;
	// TIM Match configuration Structure variable
	TIM_MATCHCFG_Type TIM_MatchConfigStruct;
	// TIM Capture configuration Structure variable
	TIM_CAPTURECFG_Type TIM_CaptureConfigStruct;

	// Initialize timer, prescale count time of 1mS
	TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
	TIM_ConfigStruct.PrescaleValue	= 100;

	// use channel 0, CAPn.0
	TIM_CaptureConfigStruct.CaptureChannel = 0;
	// Enable capture on CAPn.0 rising edge
	TIM_CaptureConfigStruct.RisingEdge = ENABLE;
	// Enable capture on CAPn.0 falling edge
	TIM_CaptureConfigStruct.FallingEdge = DISABLE;
	// Generate capture interrupt
	TIM_CaptureConfigStruct.IntOnCaption = ENABLE;


	// Use channel PCfg
	TIM_MatchConfigStruct.MatchChannel = 0;
	// Disable interrupt when MR0 matches the value in TC register
	TIM_MatchConfigStruct.IntOnMatch   = TRUE;
	// Enable reset on MR0: TIMER will reset if MR0 matches it
	TIM_MatchConfigStruct.ResetOnMatch = TRUE;
	// Stop on MR0 if MR0 matches it
	TIM_MatchConfigStruct.StopOnMatch  = FALSE;
	// Toggle MR0 pin if MR0 matches it
	TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_TOGGLE;
	// Set Match value, count value of 1000 (1000 * 100uS = 100mS --> 10Hz)
	TIM_MatchConfigStruct.MatchValue   = 1000;


	// Set configuration for Tim_config and Tim_MatchConfig
	TIM_Init(LPC_TIM1, TIM_TIMER_MODE,&TIM_ConfigStruct);
//	TIM_ConfigMatch(LPC_TIM1, &TIM_MatchConfigStruct);
	TIM_ConfigCapture(LPC_TIM1, &TIM_CaptureConfigStruct);
	TIM_ResetCounter(LPC_TIM1);

	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(TIMER1_IRQn, 1);
	/* Enable interrupt for timer 1 */
	NVIC_EnableIRQ(TIMER1_IRQn);

	TIM_Cmd(LPC_TIM1, ENABLE);
}
Esempio n. 5
0
File: timer.c Progetto: Q-Mart/EMPR
/* Config the capturing of TIM2, capture channel 1 (CAP2.1). */
void timer_configure_tim_capture(int channel, int rising, int falling, int interrupt)
{
    TIM_CAPTURECFG_Type TIM_CaptureConfigStruct;
    TIM_CaptureConfigStruct.CaptureChannel = channel;
    TIM_CaptureConfigStruct.RisingEdge = rising;
    TIM_CaptureConfigStruct.FallingEdge = falling;
    TIM_CaptureConfigStruct.IntOnCaption = interrupt;

    TIM_ConfigCapture(LPC_TIM2, &TIM_CaptureConfigStruct);
    TIM_ResetCounter(LPC_TIM2);

    if (interrupt == 1) {
        NVIC_SetPriority(TIMER2_IRQn, ((0x01<<3)|0x01));
        NVIC_EnableIRQ(TIMER2_IRQn);
    }

    TIM_Cmd(LPC_TIM2, ENABLE);
}
Esempio n. 6
0
void initSumReader(void)
{
	Recv.index = 0;
	tim_cr0_int_error = 0;

//	GPIO_SetDir(TRIG_PORT, TRIG_PIN, 1);	// Trigger signal for oscilloscope
//	GPIO_SetDir(TRIG_PORT, TRIG_PIN1, 1);	// Trigger signal for oscilloscope
//	GPIO_SetDir(TRIG_PORT, TRIG_PIN2, 1);	// Trigger signal for oscilloscope
//	GPIO_ClearValue(TRIG_PORT, TRIG_PIN);
//	GPIO_ClearValue(TRIG_PORT, TRIG_PIN1);
//	GPIO_ClearValue(TRIG_PORT, TRIG_PIN2);

	//Config P1.18 as CAP1.0 | LPC1769 (LQFP100) Pin 32 | LPCXpresso PAD1 (not linked to base board)
	PINSEL_CFG_Type PinCfg;
	PinCfg.Funcnum = 3;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 1;
	PinCfg.Pinnum = 18;
	PINSEL_ConfigPin(&PinCfg);

	TIM_TIMERCFG_Type TIM_ConfigStruct;
	TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
	TIM_ConfigStruct.PrescaleValue	= 1;
	TIM_Init(LPC_TIM1, TIM_TIMER_MODE, &TIM_ConfigStruct);

    TIM_CAPTURECFG_Type TIM_CaptureConfigStruct;
    TIM_CaptureConfigStruct.CaptureChannel = 0; // use channel 0, CAPn.0
    TIM_CaptureConfigStruct.RisingEdge = DISABLE; // Enable capture on CAPn.0 rising edge
    TIM_CaptureConfigStruct.FallingEdge = ENABLE; // Disable capture on CAPn.0 falling edge
    TIM_CaptureConfigStruct.IntOnCaption = ENABLE; // Generate capture interrupt
    TIM_ConfigCapture(LPC_TIM1, &TIM_CaptureConfigStruct);

    TIM_ResetCounter(LPC_TIM1);
//TODO check priority for Timer1
    NVIC_SetPriority(TIMER1_IRQn, ((0x01 << 3) | 0x01)); // preemption = 1, sub-priority = 1
    NVIC_EnableIRQ(TIMER1_IRQn); // Enable interrupt for timer 1
    TIM_Cmd(LPC_TIM1,ENABLE);
}