Esempio n. 1
0
void timer_start(uint8_t num) {
	switch(num) {
		case 0:
			TIM_ResetCounter(LPC_TIM0);
			TIM_Cmd(LPC_TIM0, ENABLE);
			break;
		case 1:
			TIM_ResetCounter(LPC_TIM1);
			TIM_Cmd(LPC_TIM1, ENABLE);
			break;
		default:
			break;
	}
}
Esempio n. 2
0
void hal_tick_init(void){
	//initialize timer struct
	TTC0.PrescaleOption = TIM_PRESCALE_TICKVAL;
	TTC0.PrescaleValue = 1;

	//intialize match channel struct
	MATC0.MatchChannel = 0;
	MATC0.IntOnMatch = ENABLE;
	MATC0.StopOnMatch = DISABLE;
	MATC0.ResetOnMatch = ENABLE;
	MATC0.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
	MATC0.MatchValue = TIMER_COUNTDOWN; // this should give approximately 1/4 of a sec

	//initialize TIMER0
	TIM_Init((LPC_TIM_TypeDef *) LPC_TIM0, TIM_TIMER_MODE, &TTC0);

	//initialize MAT0
	 TIM_ConfigMatch((LPC_TIM_TypeDef *) LPC_TIM0, &MATC0);

	//reset Timer0
	TIM_ResetCounter((LPC_TIM_TypeDef *) LPC_TIM0);

	//enable Timer0
	TIM_Cmd((LPC_TIM_TypeDef *) LPC_TIM0, ENABLE);

	NVIC_EnableIRQ(TIMER0_IRQn);

}
Esempio n. 3
0
void Set_LED_Pattern(uint8_t no, uint16_t delay, uint8_t bri){
	xprintf(INFO "no=%d,delay=%d,bri=%d",no,delay,bri);FFL_();
	if(no==9 || no==10){
		PREV_LED_PATTERN = LED_PATTERN;
		LED_PATTERN = no;
	}else{
		LED_PATTERN = no;
	}
	if(delay!=0){
		MILLI_DELAY = delay;
		TIM_UpdateMatchValue(LPC_TIM2, 0, MILLI_DELAY);
		TIM_ResetCounter(LPC_TIM2);
	}
	else{
		xprintf(INFO "LED delay not changed");FFL_();
	}
	if(bri!=0)
		SetBrightness(bri);
	else{
		xprintf(INFO "Brightness not changed");FFL_();
	}
//	TIM_Cmd(LPC_TIM2,DISABLE);
//	xprintf(INFO "pattern=%d DELAY=%d Bri=%d",no,MILLI_DELAY,bri);FFL_();
	resetLeds();
	LED_Loop=0;
	LED_Loop_v1=0;
	LED_Loop_v2=0;
	LED_Loop_v3=0;
	TIM_Cmd(LPC_TIM0,ENABLE);
	TIM_Cmd(LPC_TIM2,ENABLE);
}
Esempio n. 4
0
int platform_adc_start_sequence()
{ 
  elua_adc_dev_state *d = adc_get_dev_state( 0 );
  
  if( d->running != 1 )
  {
    adc_update_dev_sequence( 0 );
    
    // Start sampling on first channel
    d->seq_ctr = 0;
    ADC_ChannelCmd( LPC_ADC, d->ch_state[ d->seq_ctr ]->id, ENABLE );
    ADC_IntConfig( LPC_ADC, d->ch_state[ d->seq_ctr ]->id, ENABLE );

    d->running = 1;
    NVIC_EnableIRQ( ADC_IRQn );
    
    if( d->clocked == 1 )
    {
      ADC_StartCmd( LPC_ADC, adc_trig[ d->timer_id ] );
      TIM_ResetCounter( tmr[ d->timer_id ] );
      TIM_Cmd( tmr[ d->timer_id ], ENABLE );
    }
    else
      ADC_StartCmd( LPC_ADC, ADC_START_NOW );
  }
  
  return PLATFORM_OK;
}
Esempio n. 5
0
timer_data_type platform_s_timer_op( unsigned id, int op, timer_data_type data )
{
  u32 res = 0;

  switch( op )
  {
    case PLATFORM_TIMER_OP_START:
      TIM_Cmd( tmr[ id ], ENABLE );
      TIM_ResetCounter( tmr[ id ] );
      break;
      
    case PLATFORM_TIMER_OP_READ:
      res = tmr[ id ]->TC;
      break;

    case PLATFORM_TIMER_OP_SET_CLOCK:
      res = platform_timer_set_clock( id, data );
      break;
      
    case PLATFORM_TIMER_OP_GET_CLOCK:
      res = platform_timer_get_clock( id );
      break;

    case PLATFORM_TIMER_OP_GET_MAX_CNT:
      res = 0xFFFFFFFF;
      break;
  }
  return res;
}
Esempio n. 6
0
void Timer1_Start(uint32_t Delay) // Задержка в сек * 10
{
  TIM1_Match.MatchValue   = Delay;
  TIM_ConfigMatch(TIMER1,&TIM1_Match);
  TIM_ResetCounter(TIMER1);
  TIM_Cmd(TIMER1,ENABLE);
}
Esempio n. 7
0
void Timer0_Start(uint32_t Delay)
{
  TIM0_Match.MatchValue   = Delay;
  TIM_ConfigMatch(TIMER0,&TIM0_Match);
  TIM_ResetCounter(TIMER0);
  TIM_Cmd(TIMER0,ENABLE);
}
Esempio n. 8
0
void Timer::initialize()
{
	callbackFunction = new FunctionPointer<void, void>;
	callbackActive = false;
	
	if(!timerInitialized)
	{
		timerInitialized = true;
		
		//configure timer for 25MHz, overflow at 2^32 / 25000000 = ~171.798 seconds
		TIM_TIMERCFG_Type TIM_ConfigStruct;
		TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_TICKVAL;
		TIM_ConfigStruct.PrescaleValue	= 1;
		TIM_Init(TIMER_PERIPHERAL, TIM_TIMER_MODE, &TIM_ConfigStruct);
		
		TIM_MATCHCFG_Type TIM_MatchConfigStruct;
		TIM_MatchConfigStruct.MatchChannel = 0;
		TIM_MatchConfigStruct.IntOnMatch   = TRUE;
		TIM_MatchConfigStruct.ResetOnMatch = TRUE;
		TIM_MatchConfigStruct.StopOnMatch  = FALSE;
		TIM_MatchConfigStruct.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
		TIM_MatchConfigStruct.MatchValue   = 0xffffffff;
		TIM_ConfigMatch(TIMER_PERIPHERAL,&TIM_MatchConfigStruct);
		
		TIM_ResetCounter(TIMER_PERIPHERAL);
		TIM_Cmd(TIMER_PERIPHERAL,ENABLE);
	}
}
Esempio n. 9
0
/*********************************************************************//**
 * @brief 		TIMER3 interrupt handler
 * @param		None
 * @return 		None
 ***********************************************************************/
void TIMER3_IRQHandler(void)
{
	//duty cycle = 50%
	TIM_Cmd(LPC_TIM3,DISABLE);
	TIM_ClearIntPending(LPC_TIM3, TIM_MR0_INT);
	TIM_ResetCounter(LPC_TIM3);
	TIM_Cmd(LPC_TIM3,ENABLE);
}
Esempio n. 10
0
/**
 * Measure time between two lightbariers. Afterwards computes weight and duty cycle for shooting action
 * @param shoot - 0 if we meassure just reference weight
 * 				  1 if we want also shoot and compute weight
 */
float measure_time_weight(int8_t shoot)
{
	float weight;
	uint32_t shoot_duty = 0;

	if (check_temperatur(MAX_TEMP)) // check if temperatur is not too high
		return 0;

	TIM_Cmd(LPC_TIM0, DISABLE);
	TIM_ResetCounter(LPC_TIM0 );

	PWM_MatchUpdate(LPC_PWM1, pwm_channel, 0, PWM_MATCH_UPDATE_NOW);
	delay_ms(500);
	if (shoot)
	{
		printf("Waiting for up wall time and shooting, ");
	}
	else
	{
		printf("Waiting for up wall time ");
	}
	uint32_t duty_measure = (uint32_t) roundNo((float) period * 0.61);

	up_wall_passed = 0;
	down_wall_passed = 0;

	PWM_MatchUpdate(LPC_PWM1, pwm_channel, duty_measure, PWM_MATCH_UPDATE_NOW);
	while (up_wall_passed == 0)
		;
	unsigned long measured_tick = time_wall_up - time_wall_down;

	//shooting procedure
	if (shoot == 1)
	{
		weight = (measured_tick - reference_time) / time_one_gram; //compute weight
		shoot_duty = get_duty_shoot(weight);
		PWM_MatchUpdate(LPC_PWM1, pwm_channel, shoot_duty, PWM_MATCH_UPDATE_NOW);
		delay_ms(100);
	}

	PWM_MatchUpdate(LPC_PWM1, pwm_channel, 0, PWM_MATCH_UPDATE_NOW);

	up_wall_passed = 0;
	down_wall_passed = 0;
	LPC_SC ->EXTINT = EINT0; /* clear interrupt */
	LPC_SC ->EXTINT = EINT1; /* clear interrupt */

	printf(", tick %lu , shoot_duty: %ld ,hard c. table:%d, temp:%g \n", measured_tick, shoot_duty, hard_coded_table, compute_temperatur());

	if (!shoot)
	{
		weight = measured_tick;
		calibration_temp = compute_temperatur();
	}

	return weight;
}
Esempio n. 11
0
void platform_s_timer_delay( unsigned id, timer_data_type delay_us )
{
  u32 last;

  last = ( ( u64 )delay_us * platform_timer_get_clock( id ) ) / 1000000;
  TIM_Cmd( tmr[ id ], ENABLE );
  TIM_ResetCounter( tmr[ id ] );
  while( tmr[ id ]->TC < last );
}
Esempio n. 12
0
void ResetTimer(uint32_t Timer){
#ifndef AVR
	TIM_Cmd(((    TIM_TypeDef *)     timers[Timer]), DISABLE);
#if !defined(STM32F10X_MD) && !defined(STM32F30X)
	TIM_ResetCounter(((    TIM_TypeDef *)     (timers[Timer])));
#endif
	ClearTimerINT(Timer);
#endif
}
Esempio n. 13
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. 14
0
void TIMER0_IRQHandler(void){
	char msg[BUFFLENGTH] = "";
	char* strPtr = &msg;
	if (TIM_GetIntStatus(LPC_TIM0, TIM_MR0_INT)== SET){
		TIM_Cmd(LPC_TIM0,DISABLE);
		TIM_ResetCounter(LPC_TIM0);
		tim0_flag = 1;
		TIM_Cmd(LPC_TIM0,ENABLE);
	}
  TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
}
Esempio n. 15
0
static void init_TIM()
{
    TIM_TIMERCFG_Type TIM_ConfigStruct;
    /* Initialize timer 0, prescale count time of 1uS */
    TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_TICKVAL;
    TIM_ConfigStruct.PrescaleValue  = 204;  /* 204MHz */
    /* Set configuration for Tim_config and Tim_MatchConfig */
    TIM_Init(LPC_TIMER2, TIM_TIMER_MODE,&TIM_ConfigStruct);
    TIM_ResetCounter(LPC_TIMER2);
    /* To start timer 2 */
    TIM_Cmd(LPC_TIMER2,ENABLE);
}
Esempio n. 16
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
Esempio n. 17
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);
}
Esempio n. 18
0
/********************************************************************//**
* @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. 19
0
// Helper function: set timer clock
static u32 platform_timer_set_clock( unsigned id, u32 clock )
{
  TIM_TIMERCFG_Type TIM_ConfigStruct;

  TIM_Cmd( tmr[ id ], DISABLE );

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

  TIM_Init( tmr[ id ], TIM_TIMER_MODE, &TIM_ConfigStruct );
  TIM_Cmd( tmr[ id ], ENABLE );
  TIM_ResetCounter( tmr[ id ] );
  
  return clock;
}
Esempio n. 20
0
/*********************************************************************//**
 * @brief 		TIMER1 interrupt handler
 * @param		None
 * @return 		None
 ***********************************************************************/
void TIMER1_IRQHandler(void)
{
	//duty cycle = 25%
	TIM_Cmd(LPC_TIM1,DISABLE);
	TIM_ClearIntPending(LPC_TIM1, TIM_MR0_INT);
	TIM_ResetCounter(LPC_TIM1);
	if((PWM1_State == ENABLE))
	{
		TIM_UpdateMatchValue(LPC_TIM1,0, 200);
		PWM1_State = DISABLE;
	}
	else
	{
		TIM_UpdateMatchValue(LPC_TIM1,0, 600);
		PWM1_State = ENABLE;
	}
	TIM_Cmd(LPC_TIM1,ENABLE);
}
Esempio n. 21
0
/*********************************************************************//**
 * @brief 		TIMER0 interrupt handler
 * @param		None
 * @return 		None
 ***********************************************************************/
void TIMER0_IRQHandler(void)
{
	//duty cycle = 12.5%
	TIM_Cmd(LPC_TIM0,DISABLE);
	TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
	TIM_ResetCounter(LPC_TIM0);
	if((PWM0_State == ENABLE))
	{
		TIM_UpdateMatchValue(LPC_TIM0, 0, 100);
		PWM0_State = DISABLE;
	}
	else
	{
		TIM_UpdateMatchValue(LPC_TIM0, 0, 700);
		PWM0_State = ENABLE;
	}
	TIM_Cmd(LPC_TIM0,ENABLE);
}
Esempio n. 22
0
/*********************************************************************//**
 * @brief 		TIMER2 interrupt handler
 * @param		None
 * @return 		None
 ***********************************************************************/
void TIMER2_IRQHandler(void)
{
	//duty cycle = 37,5%
	TIM_Cmd(LPC_TIM2,DISABLE);
	TIM_ClearIntPending(LPC_TIM2, TIM_MR0_INT);
	TIM_ResetCounter(LPC_TIM2);
	if((PWM2_State == ENABLE))
	{
		TIM_UpdateMatchValue(LPC_TIM2,0, 300);
		PWM2_State = DISABLE;
	}
	else
	{
		TIM_UpdateMatchValue(LPC_TIM2,0, 500);
		PWM2_State = ENABLE;
	}
	TIM_Cmd(LPC_TIM2,ENABLE);
}
/*********************************************************************//**
 * @brief       Timer wait (microseconds)
 * @param[in]   time    number of microseconds waiting
 * @return      None
 **********************************************************************/
void TIM_Waitus(uint32_t time)
{
    TIM_MATCHCFG_Type MatchConfigStruct;
    LPC_TIM0->IR = 0xFFFFFFFF;

    MatchConfigStruct.MatchChannel = 0;
    MatchConfigStruct.IntOnMatch = ENABLE;
    MatchConfigStruct.ResetOnMatch = ENABLE;
    MatchConfigStruct.StopOnMatch = ENABLE;
    MatchConfigStruct.ExtMatchOutputType = 0;
    MatchConfigStruct.MatchValue = time;

    TIM_ConfigMatch(LPC_TIM0, &MatchConfigStruct);
    TIM_Cmd(LPC_TIM0,ENABLE);
    //wait until interrupt flag occur
    while(!(LPC_TIM0->IR & 0x01));
    TIM_ResetCounter(LPC_TIM0);
}
Esempio n. 24
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. 25
0
/*********************************************************************//**
 * @brief	TIM3 interrupt handler sub-routine
 * @param	None
 * @return	None
 **********************************************************************/
void TIMER3_IRQHandler(void)
{
	if (TIM_GetIntStatus(LPC_TIM3, TIM_MR0_INT)== SET)
	{
		TIM_Cmd(LPC_TIM3,DISABLE);                 // Disable Timer
		TIM_ResetCounter(LPC_TIM3);
		if(toggle_tim3 == TRUE)
		{
			TIM_UpdateMatchValue(LPC_TIM3,0,T1*10);//MAT3.0
			toggle_tim3=FALSE;
		}
		else
		{
			TIM_UpdateMatchValue(LPC_TIM3,0,T2*10);
			toggle_tim3=TRUE;
		}
		TIM_Cmd(LPC_TIM3,ENABLE);                // Start Timer
	}
	TIM_ClearIntPending(LPC_TIM3, TIM_MR0_INT);  // clear Interrupt
}
Esempio n. 26
0
/*********************************************************************//**
 * @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. 27
0
void startTimerInt(uint8_t matchRegister, uint32_t us)
{
	TIM_MATCHCFG_Type timerMatchCfg;
	TIM_TIMERCFG_Type timerCfg;
	uint32_t ticks = us;

	//Initialize timer for delays and interrupts
	TIM_ConfigStructInit(TIM_TIMER_MODE, &timerCfg);		/* initialize timer config struct */
	TIM_Init(LPC_TIM1, TIM_TIMER_MODE, &timerCfg);		/* initialize timer0 */

	timerMatchCfg.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
	timerMatchCfg.IntOnMatch = ENABLE;
	timerMatchCfg.MatchChannel = matchRegister;
	timerMatchCfg.MatchValue = ticks;
	timerMatchCfg.ResetOnMatch = DISABLE;
	timerMatchCfg.StopOnMatch = DISABLE;
	TIM_ConfigMatch(LPC_TIM1, &timerMatchCfg);
	TIM_ResetCounter(LPC_TIM1);
	NVIC_EnableIRQ(TIMER1_IRQn);
	TIM_Cmd(LPC_TIM1, ENABLE);

}
Esempio n. 28
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);
}
Esempio n. 29
0
// NOTE: On this platform, there is only one ADC, clock settings apply to the whole device
u32 platform_adc_set_clock( unsigned id, u32 frequency )
{
  TIM_TIMERCFG_Type TIM_ConfigStruct;
  TIM_MATCHCFG_Type TIM_MatchConfigStruct ;
  elua_adc_dev_state *d = adc_get_dev_state( 0 );

  if ( frequency > 0 )
  {
    d->clocked = 1;
    
    // Max Sampling Rate on LPC1768 is 200 kS/s
    if ( frequency > 200000 )
      frequency = 200000;
        
    // Run timer at 1MHz
    TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
    TIM_ConfigStruct.PrescaleValue     = 1;
    
    TIM_MatchConfigStruct.MatchChannel = 1;
    TIM_MatchConfigStruct.IntOnMatch   = FALSE;
    TIM_MatchConfigStruct.ResetOnMatch = TRUE;
    TIM_MatchConfigStruct.StopOnMatch  = FALSE;
    TIM_MatchConfigStruct.ExtMatchOutputType = TIM_EXTMATCH_TOGGLE;
    // Set match value to period (in uS) associated with frequency
    TIM_MatchConfigStruct.MatchValue   = ( 1000000ULL / ( frequency * 2 ) ) - 1;
        
    frequency = 1000000ULL / (TIM_MatchConfigStruct.MatchValue + 1);
  
    // Set configuration for Tim_config and Tim_MatchConfig
    TIM_Init( tmr[ d->timer_id ], TIM_TIMER_MODE, &TIM_ConfigStruct );
    TIM_ConfigMatch( tmr[ d->timer_id ], &TIM_MatchConfigStruct );
    TIM_ResetCounter( tmr[ d->timer_id ] );
  }
  else
    d->clocked = 0;
    
  return frequency;
}
Esempio n. 30
0
void TIMER0_IRQHandler ()
{
	if (TIM_GetIntStatus(LPC_TIM0, TIM_MR0_INT) == SET) {
		NVIC_DisableIRQ(TIMER0_IRQn); //disable interrupt, to prevent it from overlapping if it takes too long to process
    	TIM_ClearIntPending(LPC_TIM0,TIM_MR0_INT);
        TIM_ResetCounter(LPC_TIM0);

        #if DEBUG==1 && TRACE==1
		tty_writeln("Timer trigger");
		#endif

		if (scramble_mode) {
			scramble_timer_handler();
		} else {
	        filter_loop();
	    }

        cycle++; //used for sine wave generation
		if(cycle > frequency)
			cycle = 0;

        NVIC_EnableIRQ(TIMER0_IRQn);
	}
}