Пример #1
0
void USART1_IRQHandler(void)
{ 
	u8 res;                                                //存储接收到的数据
  u8 err;                                                //串口硬件错误出发的中断
  if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)     //接收中断
  {
		if(USART_GetFlagStatus(USART1,USART_FLAG_NE|USART_FLAG_FE|USART_FLAG_PE)) 
			err=1;//检查到噪音、帧错误或校验错误
    else 
			err=0;
    
		res=USART_ReceiveData(USART1);            //读接收到的字节,同时相关标志自动清除
		if((RS485_RX_CNT<2047)&&(err==0))         //接收到的字节数量,在合理的范围内,同时无其他错误
    {
			RS485_RX_BUFF[RS485_RX_CNT]=res;        //获取数据
      RS485_RX_CNT++;                         //计数

      TIM_ClearITPendingBit(TIM1,TIM_IT_Update);           //清除定时器溢出中断
      TIM_SetCounter(TIM1,0);                   //当接收到一个新的字节时,将定时器1复位为0,重新计时(相当于watchdog)
      TIM_Cmd(TIM1,ENABLE);                    //使能定时器1,开始计时
    }
  }
}
Пример #2
0
void TIMER_irq() {
  if (TIM_GetITStatus(STM32_SYSTEM_TIMER, TIM_IT_Update) != RESET) {
    TIM_ClearITPendingBit(STM32_SYSTEM_TIMER, TIM_IT_Update);

#ifdef CONFIG_CNC
    CNC_timer();
#endif
    bool ms_update = SYS_timer();
    if (ms_update) {
      TRACE_MS_TICK(SYS_get_time_ms() & 0xff);
    }

    TASK_timer();
#ifdef CONFIG_LED
    LED_SHIFT_tick();
    LED_tick();
#endif
    if (ms_update) {
      __os_time_tick(SYS_get_time_ms());
    }
    CLI_timer();
  }
}
Пример #3
0
// Used by interrupt system
static void tim_oc_irq_handler(void) {
    uint16_t cval = TIM_MST->CNT;
  
    // Clear interrupt flag
    if (TIM_GetITStatus(TIM_MST, TIM_IT_CC1) == SET) {
        TIM_ClearITPendingBit(TIM_MST, TIM_IT_CC1);
    }

    if (oc_rem_part > 0) {
        set_compare(oc_rem_part); // Finish the remaining time left
        oc_rem_part = 0;
    }
    else {
        if (oc_int_part > 0) {
            set_compare(0xFFFF);
            oc_rem_part = cval; // To finish the counter loop the next time
            oc_int_part--;
        }
        else {
            us_ticker_irq_handler();
        }
    }
}
void TIM3_IRQHandler(void)                                         //¶¨Ê±ÖжÏ3       ¶¨Ê±·¢ËÍÊý¾Ý¸øÉÏλ»ú
{  
	if (TIM_GetITStatus(TIM3 , TIM_IT_Update) == SET)                //¶¨Ê±¸üÐÂ
	{  
		
		TIM_ClearITPendingBit(TIM3 , TIM_IT_Update);                   //Çå¿Õ¶¨Ê±ÖжÏ
		
		if((Inspection_Mode!=0)||(Key_En == 1))                        //??
		{
			
			if(Transfer_DataDisable_CommandEnable_Sign==0)                  //?¡
			{
				
				if(Pressure_mmHg1<1.5)
					Pressure_mmHg1=0;
				else 
					Pressure_mmHg1=Pressure_mmHg1;
				
				if(Pressure_mmHg2<1.5)
					Pressure_mmHg2=0;
				else 
					Pressure_mmHg2=Pressure_mmHg2;
				if(Pressure_mmHg3<1.5)
					Pressure_mmHg3=0;
				else
					Pressure_mmHg3=Pressure_mmHg3;
				if(Pressure_mmHg4<1.5)
					Pressure_mmHg4=0;
				else 
					Pressure_mmHg4=Pressure_mmHg4;
				
				Transfer_Agreement15x8b_Data(0x01,(u16)(Pressure_mmHg1*10),(u16)(Pressure_mmHg2*10),(u16)(Pressure_mmHg3*10),(u16)(Pressure_mmHg4*10));	
				                            //0x01  ±íʾ·½ÏòΪÏÂλ»úÏòÉÏλ»ú
			}
		}		
	}	
} 
Пример #5
0
void TIM2_IRQHandler(void)
{
	if ( TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET ) 
	{	
		TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);

		/////////////////////////////////////////////////////////////////
		// Power OFF GPS and GSM before go into standby mode
		/////////////////////////////////////////////////////////////////
		GSM_TurnOnOff_delay();
#ifdef USE_STM32_GPS_BOARD_VB
		GPSPowerOff();
		GSM_PowerOff();
#endif
		/* Wait till RTC Second event occurs */
		RTC_ClearFlag(RTC_FLAG_SEC);
		while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);

		// normal working state
		if(BKP_TRUE == BKP_ReadBackupRegister(BKP_DR1))
		{
			/* Set the RTC Alarm after xx s */
			DEBUG("in timer2 bkptrue %d\n", (BKP_ReadBackupRegister(BKP_DR4) + BKP_ReadBackupRegister(BKP_DR4) <<16));
			RTC_SetAlarm(RTC_GetCounter()+ ((BKP_ReadBackupRegister(BKP_DR4) + BKP_ReadBackupRegister(BKP_DR4) <<16)/SLEEP_TIM2_RATIO));
		}
		else
		{
			DEBUG("in timer2 bkpfalse\n");
			RTC_SetAlarm(RTC_GetCounter()+ (SLEEP_NORMAL_SEC/SLEEP_TIM2_RATIO));
		}
	
		/* Wait until last write operation on RTC registers has finished */
		RTC_WaitForLastTask();		
		/* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
		PWR_EnterSTANDBYMode();
	}		 	
}
//***************************************************************************
//Обработчик прерывания TIM14 для определения окончания приёма данных по ModBus
//***************************************************************************
void TIM14_IRQHandler(void)
{
	TIM_ClearITPendingBit(TIM14, TIM_IT_Update);

	//blinking with PC9
//	if(GPIO_ReadOutputDataBit  ( GPIOA,GPIO_Pin_5))
//	     GPIO_WriteBit(GPIOA,GPIO_Pin_5,Bit_RESET);
//	else
//		GPIO_WriteBit(GPIOA,GPIO_Pin_5,Bit_SET);
		
	//проверяем окончание приёма uart1
	if((modbus1.rxtimer++ > modbus1.delay) & (modbus1.rxcnt > 1)){
		modbus_slave1(&modbus1);							//подготовка данных на отправку

/* Старт отправки данных по UART1 если данные готовы */
		if((modbus1.txlen>0)&(modbus1.txcnt==0))
		{
			/* Configure USART1 TX (PA9) as alternate function push-pull*/	
//			GPIO_InitTypeDef  GPIO_InitStructure;
//			GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;
//			GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
//			GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
//			GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
//			GPIO_Init(GPIOA, &GPIO_InitStructure);
//			GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
			
			//countReqUSART1 = 0;
			USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
			USART_ITConfig(USART1, USART_IT_TC, ENABLE);

			//rs485 DE enable
//			GPIOA->BSRR = GPIO_Pin_12;
			//GPIO_WriteBit(PIN_USART_DE, Bit_SET);
			USART_SendData(USART1, modbus1.buffer[modbus1.txcnt++]);
		}
	}
}
Пример #7
0
//konfiguracja przerwania i timera dla ZLICZANIA PREDKOSCI
void IniTimerPrzerwanie1()
{
	//ustawienie trybu pracy priorytetow przerwan
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
	NVIC_InitTypeDef p;
	//numer przerwania
	p.NVIC_IRQChannel = TIM2_IRQn;
	// priorytet główny
	p.NVIC_IRQChannelPreemptionPriority = 0x00;
	// subpriorytet
	p.NVIC_IRQChannelSubPriority = 0x00;
	// uruchom dany kanał
	p.NVIC_IRQChannelCmd = ENABLE;
	// zapisz wypełnioną strukturę do rejestrów
	NVIC_Init(&p);

	//doprowadzenie sygnalu zerowego
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

	//TIM2 przy prescaler=1 ma 42Mhz a przy wiekszym 84Mhz)
	TIM_TimeBaseInitTypeDef a;
	a.TIM_Prescaler=8400;
	int obliczona = 2000 - 1;
	a.TIM_CounterMode=TIM_CounterMode_Up;
	a.TIM_Period=obliczona;
	a.TIM_ClockDivision=0;
	a.TIM_RepetitionCounter=0;
	TIM_TimeBaseInit(TIM2, &a);

	// wyczyszczenie przerwania od timera 2 (przy konfiguracji timera)
	TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
	// zezwolenie na przerwania od przepelnienia dla timera 2
	TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
	//wlaczenie timera
	TIM_Cmd(TIM2, ENABLE);

}
Пример #8
0
/**
  * @brief  This function handles TIM7 global interrupt request.
  * @param  None
  * @retval None
  */
void TIM7_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM7, TIM_IT_Update) != RESET)
  {  
    /* if Display Timeout is working */    
    if(DisplayTimeout != TIMEOUT_DEFAULT)
    {
      DisplayTimeout--;
      
      if (!DisplayTimeout)
      {
        DisplayTimeout = TIMEOUT_DEFAULT;
        ExitMutex = 1;
      }
    }
    
    /* Toggle leds */
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);
    
    /* if 20 TIM7 interrupt reached */
    if (SaveReportCmd == 20)
    {     
        ReqOperation = SAVE_REPORT_OP;
        SaveReportCmd = 0;     
    }
    else
    {
      SaveReportCmd++;
    }
    
    /* Clear TIM7 interrupt pending bits */
    TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
  } 
}
Пример #9
0
/**
  * @brief  This function handles TIM4 global interrupt request.
  * @param  None
  * @retval None
  */
void TIM4_IRQHandler(void)
{ 
  if (TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET)
  {
    /* Clear TIM4 Capture compare interrupt pending bit */
    TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);

    if(CaptureNumber == 0)
    {
      /* Get the Input Capture value */
      IC4ReadValue1 = TIM_GetCapture2(TIM4);
      CaptureNumber = 1;
    }
    else if(CaptureNumber == 1)
    {
      /* Get the Input Capture value */
      IC4ReadValue2 = TIM_GetCapture2(TIM4); 
      
      /* Capture computation */
      if (IC4ReadValue2 > IC4ReadValue1)
      {
        Capture = (IC4ReadValue2 - IC4ReadValue1) - 1; 
      }
      else if (IC4ReadValue2 < IC4ReadValue1)
      {
        Capture = ((0xFFFF - IC4ReadValue1) + IC4ReadValue2) - 1; 
      }
      else
      {
        Capture = 0;
      }
      /* Frequency computation */ 
      TIM4Freq = (uint32_t) SystemCoreClock / Capture;
      CaptureNumber = 0;
    }
  }
}
Пример #10
0
//配置中断处理函数
void TIM5_IRQHandler(void)
{
    if((TIM5CH1_CAPTURE_STA&0x80)==0)//if capture not done
    {
        if(TIM_GetITStatus(TIM5,TIM_IT_Update)!=RESET)//if overflow occured
        {
            if(TIM5CH1_CAPTURE_STA&0x40)//rising has been captured
            {
                if((TIM5CH1_CAPTURE_STA&0x3f)==0x3f)//if overflow times FULL,end capture anyway
                {
                    TIM5CH1_CAPTURE_STA|=0x80;//end capture
                    TIM5CH1_CAPTURE_VAL=0xffff;//full
                }
                else TIM5CH1_CAPTURE_STA++;//if overflow times not full,overflow times++
            }
        }
        if(TIM_GetITStatus(TIM5,TIM_IT_CC1)!=RESET)//if captured rising/falling
        {
            if(TIM5CH1_CAPTURE_STA&0x40)//if rising has been captured,capture下降沿
            {
                TIM5CH1_CAPTURE_STA|=0x80;//done capture
                TIM5CH1_CAPTURE_VAL=TIM_GetCapture1(TIM5);//get value
                TIM_OC1PolarityConfig(TIM5,TIM_ICPolarity_Rising);//reset to original mode
            }
            else//if rising not captured,set all to init value,and set rising captured
            {
                TIM5CH1_CAPTURE_STA=0;
                TIM5CH1_CAPTURE_VAL=0;
                TIM_SetCounter(TIM5,0);
                TIM5CH1_CAPTURE_STA|=0x40;//set rising captured
                TIM_OC1PolarityConfig(TIM5,TIM_ICPolarity_Falling);//then capture falling
            }
        }
    }
    
    TIM_ClearITPendingBit(TIM5,TIM_IT_CC1|TIM_IT_Update);
}
Пример #11
0
void vTimer2IntHandler( void )
{
static unsigned short usLastCount = 0, usSettleCount = 0, usMaxDifference = 0;
unsigned short usThisCount, usDifference;

	/* Capture the free running timer 3 value as we enter the interrupt. */
	usThisCount = TIM3->CNT;
	
	if( usSettleCount >= timerSETTLE_TIME )
	{
		/* What is the difference between the timer value in this interrupt
		and the value from the last interrupt. */
		usDifference = usThisCount - usLastCount;

		/* Store the difference in the timer values if it is larger than the
		currently stored largest value.  The difference over and above the
		expected difference will give the 'jitter' in the processing of these
		interrupts. */
		if( usDifference > usMaxDifference )
		{
			usMaxDifference = usDifference;
			usMaxJitter = usMaxDifference - timerEXPECTED_DIFFERENCE_VALUE;
		}
	}
	else
	{
		/* Don't bother storing any values for the first couple of
		interrupts. */
		usSettleCount++;
	}

	/* Remember what the timer value was this time through, so we can calculate
	the difference the next time through. */
	usLastCount = usThisCount;

    TIM_ClearITPendingBit( TIM2, TIM_IT_Update );
}
Пример #12
0
/*-----------------------------------------------------------
* @brief Function Name  : vhADC_initTIM1
* @brief Description    : Initializes TIM1 to give interrupt with specified
* 							frequency.
*/
void vhADC_initTIM1(void){
	TIM_TimeBaseInitTypeDef TIM_InitStructure;
	TIM_OCInitTypeDef TIM_OCInitStructure;

	TIM_InitStructure.TIM_Prescaler = 4200-1;				//84MHz : 42000 = 20000 Hz
	TIM_InitStructure.TIM_Period = 100;						//20000 Hz : 100 = 200 Hz
	TIM_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_InitStructure.TIM_RepetitionCounter = 0;
	TIM_TimeBaseInit(TIM1, &TIM_InitStructure);

	// Channel 1 configuration
	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Active;
	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_Pulse = 10;
	TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
	TIM_OC1Init(TIM1, &TIM_OCInitStructure);
	TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Disable);

	// Clear pending interrupt bits
	TIM_ClearITPendingBit( TIM1, TIM_IT_Update | TIM_IT_CC1 );
	TIM_ITConfig( TIM1, TIM_IT_Update | TIM_IT_CC1, ENABLE );
	TIM_Cmd( TIM1, ENABLE );
}
Пример #13
0
/**-------------------------------------------------------
  * @函数名 TIM5_IRQHandler
  * @功能   TIM5中断处理函数,每0.1ms中断一次 
  * @参数   无
  * @返回值 无
***------------------------------------------------------*/
void TIM2_IRQHandler(void)
{
    /* www.armjishu.com ARM技术论坛 */

    if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
    {
        TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
        tick_1ms++;
				if(tick_1ms >= 10)
				{
					tick_1ms = 0;
					speed_count++;
					tick_5ms++;
					if(speed_count >= 50)
					{
						speed_count = 0;
					}
					CarMove();
				}
				
				//舵机PWM输出
					duoji_count++;
					if(duoji_count <= zhuanjiao)
					{
						Servo_SET;
					}
					else
					{
						Servo_RESET;
					}
					if(duoji_count >= 200)//20ms
					{
						duoji_count = 0;
					}
    }
}
Пример #14
0
void TIM3_IRQHandler()
{

  if(TIM_GetITStatus(TIM3, TIM_IT_CC1) == SET)
    {
      //  Clear TIM3 Capture compare interrupt pending bit
      TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
      if(CaptureNumber == 0)
        {
          //  Get the Input Capture value
          IC3ReadValue1 = TIM_GetCapture1(TIM3);
          CaptureNumber = 1;
          tim3ConfigFalling();
        }
      else if(CaptureNumber == 1)
        {
          //  Get the Input Capture value
          IC3ReadValue2 = TIM_GetCapture1(TIM3);
          dataCaptureReady = 1;
          CaptureNumber = 0;
          tim3ConfigRising();
        }
    }
}
Пример #15
0
void TIM3_IRQHandler (void)
{
    TIM_ClearITPendingBit (TIM3 , TIM_IT_Update );
    
    dataX = mySPI_GetData(OutX);
    dataY = mySPI_GetData(OutY);
    dataZ = mySPI_GetData(OutZ);
    
    out[0] = '\0';
    strcpy(out,"X=");
    tmp[0] = '\0';
    itoa(tmp, 'd', dataX);
    strcat(out, tmp);
    strcat(out, ",Y=");
    tmp[0] = '\0';
    itoa(tmp, 'd', dataY);
    strcat(out, tmp);
    strcat(out, ",Z=");
    tmp[0] = '\0';
    itoa(tmp, 'd', dataZ); 
    strcat(out, tmp);
    strcat(out, "\r\n");
    uart_write(myUSART, out, strlen(out));
}
Пример #16
0
void TIM2_IRQHandler(void)
{
	uint16_t cnt = TIM2->CNT;
	GPIOC->ODR^=GPIO_Pin_8;

	//send_to_uart('T');
	 /* if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
	  {
	    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
	  }*/
	TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

	if ( cnt < 0x7FFF ) {
		Enc1_TotalCount += (uint32_t)0x10000;
	} else {
		Enc1_TotalCount -= (uint32_t)0x10000;
	}
	Enc1_Interrupted = 0;
	//send_to_uart('S');
	//USART1->DR = (cnt & (uint16_t)0x01FF);
	//USART_SendData(USART1, 0x01);
	USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
	DMA_Cmd(DMA1_Channel4, ENABLE);
}
Пример #17
0
/**
  * @brief  This function handles TIM1 global interrupt request.
  * @param  None
  * @retval None
  */
void TIM1_CC_IRQHandler(void)
{ 
  if(TIM_GetITStatus(TIM1, TIM_IT_CC2) == SET) 
  {
    /* Clear TIM1 Capture compare interrupt pending bit */
    TIM_ClearITPendingBit(TIM1, TIM_IT_CC2);
    if(uhCaptureNumber == 0)
    {
      /* Get the Input Capture value */
      uhIC3ReadValue1 = TIM_GetCapture2(TIM1);
      uhCaptureNumber = 1;
    }
    else if(uhCaptureNumber == 1)
    {
      /* Get the Input Capture value */
      uhIC3ReadValue2 = TIM_GetCapture2(TIM1); 
      
      /* Capture computation */
      if (uhIC3ReadValue2 > uhIC3ReadValue1)
      {
        uwCapture = (uhIC3ReadValue2 - uhIC3ReadValue1); 
      }
      else if (uhIC3ReadValue2 < uhIC3ReadValue1)
      {
        uwCapture = ((0xFFFF - uhIC3ReadValue1) + uhIC3ReadValue2); 
      }
      else
      {
        uwCapture = 0;
      }
      /* Frequency computation */ 
      uwTIM1Freq = (uint32_t) SystemCoreClock / uwCapture;
      uhCaptureNumber = 0;
    }
  }
}
Пример #18
0
void TIM4_IRQHandler(void)		//1ms中断一次,用于程序读取6050等
{
    if( TIM_GetITStatus(TIM4 , TIM_IT_Update) != RESET ) 
    {     
     Ledcounter++;
      
     if(Ledcounter==59)Led1=1;
     if(Ledcounter==60){Led1=0;Ledcounter=0;}
     

      TxBuf[0]=(Throttle*10)&0xff;
      TxBuf[1]=((Throttle*10)>>8);     //油门量装入待发送数组的前两个字节
      TxBuf[2]=Pitch;                  //俯仰角装入第3个字节
      TxBuf[3]=Roll;                   //横滚角转入第4个字节
      TxBuf[4]=Yaw;                    //偏航角装入第5个字节
      TxBuf[31]=(Throttle<=5) ? 0:0xA5;//紧急熄火标志字节控制     
      NRF24L01_TxPacket(TxBuf);	//数据包发送,最大重发次数15次
     
     
      TIM_ClearITPendingBit(TIM4 , TIM_FLAG_Update);   //清除中断标志  
      
        
        
    } 
Пример #19
0
int main(void) {
///-----Inicjalizacja funkcji----
	SystemInit();
	DELAY_Init();
	LCD_Init();
	DAC_Conf();
  EXTILine0_Config();
	EXTILine3_Config();
	Timer();
	
	LCD_Clear();
	LCD_GoTo(0,0);
	LCD_SendText("Probkowanie co:");
	LCD_GoTo(1,0);
	LCD_SendInt(z);
	


	DAC_Cmd(DAC_Channel_1, ENABLE);  //wlacz przetwornik

    while (1) {
			
			int timerValue = TIM_GetCounter(TIM2); //sprawdzanie wartosci timera
			if(timerValue >=z-1)
				{
        TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
				DAC_SetChannel1Data(DAC_Align_12b_R, k);
			  k++;
				if(k >= 4000) 
					{
					k=0;
					}	
		
	}
}
		}
Пример #20
0
// ========================================================
// генерация звука на динамик
void TIM2_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
  {
		TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
		if(!poweroff_state)
		{
			if(Alarm.Alarm_active && !Alarm.User_cancel)
			{
				Alarm.Alarm_beep_count++;
				if(Alarm.Alarm_beep_count==50)   TIM_SetAutoreload(TIM10, 32  );
				if(Alarm.Alarm_beep_count==100) {TIM_SetAutoreload(TIM10, 16  );Alarm.Alarm_beep_count=0;}
			}

			if((Alarm.Alarm_active && Alarm.User_cancel) || !Alarm.Alarm_active)
			{
				if(Power.Sound_active == ENABLE)
				{	
					if(Sound_key_pressed) // нажатие кнопки
					{
						if(Alarm.Tick_beep_count>40)
								{
									Alarm.Tick_beep_count=0;
									sound_deactivate();
								} else Alarm.Tick_beep_count++;
							
					} else if(Alarm.Tick_beep_count>3) // тик датчика
							{
								Alarm.Tick_beep_count=0;
								sound_deactivate();
							} else Alarm.Tick_beep_count++;
			} else sound_deactivate();
		}
	}
	}
}
Пример #21
0
/*
** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
**
**   Function    : void initTimer3(void)
**
**   Arguments   : n/a
**      
**   Return      : n/a 
** 
**   Description : timer 3 interrupt routine to calculate ADC average values.
**
**   Notes       : restrictions, odd modes
**
**   Author      : Nguyen Trong Tri
**
**   Date        : 2012/02/15 
**
** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/	
void initTimer3(void)
{
   /* System clock */
   unsigned int gTimerClock;

   unsigned long u32_timer_reload;

   TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
   NVIC_InitTypeDef NVIC_InitStructure;

   gTimerClock = SystemCoreClock / 2;
   u32_timer_reload =  (gTimerClock * INT_PERIOD_MS) / ONESEC;
   /* TIM3 clock enable */
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

   /* Time base configuration */
   TIM_TimeBaseStructure.TIM_Period = u32_timer_reload / 1000 - 1;
   TIM_TimeBaseStructure.TIM_Prescaler = 1999;
   TIM_TimeBaseStructure.TIM_ClockDivision = 0;
   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
   TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

   /* Enable the TIM3 global Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 10;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);

   /* Enable Timer 2 interrupt. */
   TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
   TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

   /* Start counting */
   TIM_Cmd(TIM3, ENABLE);
}
Пример #22
0
/******************************************************************
** 函数名: TIMy_IRQHandler
** 输  入: none
** 描  述: 该定时器用作检测和LED控制计时使用                                            
** 全局变量: 
** 调用模块: 
** 作  者:   zcs
** 日  期:   2015-04-21
** 修  改:
** 日  期:

** 版  本: 1.0
*******************************************************************/
void TIMx_IRQHandler(void)
{
	/******作为计时使用,为波形变换时间提供依据,0.1ms进入一次*****/
 	if (TIM_GetITStatus(TIMx,TIM_IT_Update) != RESET)
	{
		TIM_ClearITPendingBit(TIMx, TIM_FLAG_Update);
		TIMx_timecount++;
		if (TIMx_timecount > Time5sCount)		          //定时一个5s时间
		{
			TIMx_timecount = 0;                    
			for (ch_count = 0; ch_count < 6; ch_count++)//判定通道是否开启复杂波形,如果是,则对相应通道进行计数
			{
				if(CH[ch_count].complex_status)
				CH[ch_count].time5s_count++;     
			}   
		}
		for (ch_count = 0; ch_count < 6; ch_count++)//如果通道开启,则对通道的基本波形时间计数
		{
			if(CH[ch_count].channel_open)
				CH[ch_count].wave_count++;
		}
		WaveWork();//产生波形的函数
	}
}
Пример #23
0
void TIM2_IRQHandler(void)
{
	uint32_t current[4];
	TIM_ICInitTypeDef TIM_ICInitStructure;
	TIM_ICStructInit(&TIM_ICInitStructure);

	if (TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET) {
		/* Clear TIM1 Capture compare interrupt pending bit */
		TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);

		if ( inc[INC6].status == RISING ) {
			TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
			TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;

			/* Get the Input Capture value */
			inc[INC6].prev_value = TIM_GetCapture1(TIM2);
			inc[INC6].status = FALLING;
			

		} else {
			TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
			TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

			//Get the Input Capture value
			current[0] =  TIM_GetCapture1(TIM2);

			if (current[0] > inc[INC6].prev_value)
				inc[INC6].curr_value =  current[0] - inc[INC6].prev_value ;
			else if (current[0] < inc[INC6].prev_value)
				inc[INC6].curr_value = 0xFFFF - inc[INC6].prev_value  + current[0] ;

			inc[INC6].status = RISING;
		}

		TIM_ICInit(TIM2, &TIM_ICInitStructure);

	}

	if (TIM_GetITStatus(TIM2, TIM_IT_CC2) == SET) {
		/* Clear TIM1 Capture compare interrupt pending bit */
		TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);

		if (inc[INC5].status == RISING) {
			TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
			TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;

			/* Get the Input Capture value */
			inc[INC5].prev_value = TIM_GetCapture2(TIM2);
			inc[INC5].status = FALLING;

		} else {
			TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
			TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

			/* Get the Input Capture value */
			current[1] =  TIM_GetCapture2(TIM2);

			if (current[1] > inc[INC5].prev_value)
				inc[INC5].curr_value =  current[1] - inc[INC5].prev_value ;
			else if (current[1] < inc[INC5].prev_value)
				inc[INC5].curr_value = 0xFFFF - inc[INC5].prev_value + current[1] ;

			inc[INC5].status = RISING;


		}

		TIM_ICInit(TIM2, &TIM_ICInitStructure);
	}

	if (TIM_GetITStatus(TIM2, TIM_IT_CC3) == SET) {
		/* Clear TIM1 Capture compare interrupt pending bit */
		TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);

		if (inc[INC2].status == RISING) {
			TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
			TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;

			/* Get the Input Capture value */
			inc[INC2].prev_value = TIM_GetCapture3(TIM2);
			inc[INC2].status = FALLING;
			


		} else {
			TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
			TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

			/* Get the Input Capture value */
			current[2] =  TIM_GetCapture3(TIM2);

			if (current[2] > inc[INC2].prev_value)
				inc[INC2].curr_value=  current[2] - inc[INC2].prev_value;
			else if (current[2] < inc[INC2].prev_value)
				inc[INC2].curr_value =   0xFFFF - inc[INC2].prev_value + current[2] ;
			
			inc[INC2].status = RISING;


		}

		TIM_ICInit(TIM2, &TIM_ICInitStructure);
	}

	if (TIM_GetITStatus(TIM2, TIM_IT_CC4) == SET) {
		/* Clear TIM1 Capture compare interrupt pending bit */
		TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);

		if (inc[INC1].status == RISING) {
			TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
			TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;

			/* Get the Input Capture value */
			inc[INC1].prev_value = TIM_GetCapture4(TIM2);
			inc[INC1].status  = FALLING;
			

		} else {
			TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
			TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

			/* Get the Input Capture value */
			current[3] =  TIM_GetCapture4(TIM2);

			if (current[3] > inc[INC1].prev_value)
				inc[INC1].curr_value =  current[3] - inc[INC1].prev_value;
			else if (current[3] < inc[INC1].prev_value)
				inc[INC1].curr_value = 0xFFFF - inc[INC1].prev_value+ current[3] ;

			inc[INC1].status = RISING;


		}

		TIM_ICInit(TIM2, &TIM_ICInitStructure);
	}
}
Пример #24
0
/*矩阵键盘10ms扫描中断*/
void TIM3_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
  {
    TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
		/*下面是定时器中断到来该做的程序*/
		
		//每次按键扫描都先扫一次(真的一次Once)旋转开关,判断是否与之前的旋转开关值相同,
		//若不同,则等待5个TIM3定时时间,再次扫一次旋转开关,
		if(iii == 0)
			KeyValue = OnceRotaryKey()&0x0F;
		/*旋转开关处理程序*/
		if(KeyValue != RotaryKeyValue_before)//有扫到旋转开关按键值与之前不同,应是真有开关变化
		{
			iii++;
			if(iii > 5)
			{
				u8 temp=KEY_NULL;
				temp = OnceRotaryKey()&0x0F;
				if(temp == KeyValue)
				{
					if(KeyValue >= KEY_VALUE_6)//0x06->KEY_VALUE_6,KeyValue有0x46,0x47,0x48,0x49,0x4A
					{
						RotaryKeyChanged_flag = 1;
						RotaryKeyValue = (KeyValue&0x0F);//只保留KeyValue中的按键值6-10
						RotaryKeyValue_before = RotaryKeyValue;//RotaryKeyValue_before只在前面if(KeyValue != RotaryKeyValue_before)比较用到。
					}
				}
				iii=0;
				KEY_LINE_write_high_all();
				KeyValue = KEY_NULL;//按键值、状态清零
				TIM_Cmd(TIM3, DISABLE);//同时关闭定时器
				EXTI->IMR |= Keyboard_EXTI_Line;//同时开放来自线上的中断请求
			}
		}
		/*软按钮处理程序,及开关抖动处理程序*/
		else//若扫到旋转开关按键值与之前相同,可能是旋转开关抖动或有软按键,则扫软按键,若没有软按键,也将TIM3关闭,打开外部中断
		{
			jjj++;
			KeyValue = ScanKey();
			/*开关抖动处理程序*/
			if(((KeyValue&0x0F) == KEY_NULL) && jjj > 100+6)//表示无软按键,100表示长按检测次数  (长按键检测阀值为100 所以这里的超时应该大于100)
			{
				jjj=0;
				KEY_LINE_write_high_all();
				KeyValue = KEY_NULL;//按键值、状态清零
				TIM_Cmd(TIM3, DISABLE);//同时关闭定时器
				EXTI->IMR |= Keyboard_EXTI_Line;//同时开放来自线上的中断请求 6789
			}
			/*软按钮处理程序*/
			if((KeyValue&0xF0) != 0x00 && (KeyValue&0x0F) < KEY_VALUE_6)//有按键也有状态(短按、长按),其中0x0F->KEY_NULL
			{
				jjj=0;
				
				SoftKeyChanged_flag = 1;
				SoftKeyValue_before = SoftKeyValue;
				SoftKeyValue = (KeyValue&0x0F);//只保留KeyValue中的按键值0-5
				
				if((KeyValue&0xF0)==0x90)//0x90=0b10010000
					ShortKey_flag = 1;
				else if((KeyValue&0xF0)==KEY_LONG)
					LongKey_flag = 1;
				
				KEY_LINE_write_high_all();
				KeyValue = KEY_NULL;//按键值、状态清零
				TIM_Cmd(TIM3, DISABLE);//同时关闭定时器
				EXTI->IMR |= Keyboard_EXTI_Line;//同时开放来自线上的中断请求
			}
		}
  }
}
Пример #25
0
/**************************************************************** 
*	函数名称: 
*	功    能: 2015-4-28新编中断服务函数。
*						2016-06-08 lea比较其开始后捕获第二次中断为相位起始和结束标志
*						当A相电压大于100V,在开启了比较器、输入捕获之后,捕获到A相经过比较器之后的上升沿,则定时器开始计数。
						关闭比较器,使无比较输出,即无捕获输入。
*						这时,同时需要判断再次检测到的电压要大于100V,再开启捕获功能,记录下再次捕获到的另一相的上升沿时的计数值。
*						供相序判断。
*	参    数: 无 
*	返 回 值: 无  
*****************************************************************/
void TIM5_IRQHandler(void)
{
	if(phasestatus != state0)//相序测量状态下比较用于触发相序的时间间隔测量
	{
		if((TIM5CH4_CAPTURE_STA&0x8000)==0)//还未成功捕获A相与B相orC相之间的时间
		{
//			if (TIM_GetITStatus(TIM5, TIM_IT_Update) != RESET)
//			{
//				if(TIM5CH4_CAPTURE_STA&0x4000)//已经捕获到A相的上升沿了
//				{
//					if((TIM5CH4_CAPTURE_STA&0x3FFF)==0x3FFF)//两次捕获A相与B相或C相的时间太长了,0x3F=4.194304s(1MHz计数0xFFFF次,再累加0x3F次)
//					{
//						TIM5CH4_CAPTURE_STA|=0x8000;//标记成功捕获了一次
//						TIM5CH4_CAPTURE_VAL=0xFFFF;
//	//					COMP_Cmd(COMP_Selection_COMP1, DISABLE);//关闭比较器
//					}
//					else TIM5CH4_CAPTURE_STA++;
//				}
//			}
			if(TIM_GetITStatus(TIM5, TIM_IT_CC4) != RESET)//捕获4发生捕获事件
			{
				if(TIM5CH4_CAPTURE_STA&0x4000)		//已经捕获到一次,再次捕获到一个上升沿 		
				{				
					/**************测试两次读取判断第二相线频率脉冲计数个数*/
					//20160607lea 两相线上的起始脉冲均从第二个开始,因为刚打开比较器时若此时输入脉冲处于正半周则会立即触发输入捕捉中断
					//所以从第二个脉冲开始判定。相序测量功能 相位差的测量基本正确。
					if(capstats==0)
					{						
						capstats=1;
					}
					else if(capstats==1)
					{
						TIM2_cap1 = TIM2->CNT;
						TIM5_cap1 = TIM_GetCapture4(TIM5);
						capstats=2;
					}
					else
					{
						TIM5CH4_CAPTURE_VAL = TIM_GetCapture4(TIM5);
						TIM5_cap2 = TIM5CH4_CAPTURE_VAL;
						TIM_Cmd(TIM5, DISABLE);
						
						TIM2_cap2 = TIM2->CNT;//TIM_GetCapture4(TIM2);
						TIM_Cmd(TIM2, DISABLE);
						TIM5CH4_CAPTURE_STA|=0x8000;		//标记成功捕获到B或C相的上升沿
						COMP_Cmd(COMP_Selection_COMP1, DISABLE);//关闭比较器
		
						TIM_Cmd(TIM14, DISABLE);//0.5s定时关闭
						
						TIM5_cap3=TIM5_cap2-TIM5_cap1;
						//一个周期的计数个数 用于对总计数个数取余后求相位差,确定第二相相序
						CCR4_Val = TIM5_cap3;
						
						TIM2_cap3=TIM2_cap2-TIM2_cap1;
						capstats=0;
						//BUZZER_Open(0);//蜂鸣一声						
					}
					/****************/
				}
				else  								//已经检测到A相电压大于100V,开始比较器和定时器后,第一次捕获上升沿
				{
					if(capstats==0)
					{
						capstats=1;
					}
					else
					{
						TIM5CH4_CAPTURE_STA=0;			//清空,此标志除了用来0x4000,0x8000做A、B/C两次的标记外,还用来定时器溢出计时
						TIM5CH4_CAPTURE_VAL=0;
						TIM_SetCounter(TIM5,0);
						TIM_SetCounter(TIM2,0);
						TIM5CH4_CAPTURE_STA|=0x4000;		//标记捕获到了A相经过比较器之后的上升沿
						
						TIM_Cmd(TIM5, ENABLE);//开启定时器计数
						
						TIM_Cmd(TIM2, ENABLE);//测试 在捕捉到A相上升沿后打开,输出一个脉冲对比待测的相位差
	 
						COMP_Cmd(COMP_Selection_COMP1, DISABLE);//关闭比较器,使无比较输出,即无捕获输入。等待下次检测到100V以上电压,再开启
						BUZZER_Open(0);//蜂鸣一声
						capstats=0;
					}
					
				}
			}
		}
	}
	else//正常模式下,比较器用于过零点触发交流的采样
	{
		if(TIM_GetITStatus(TIM5, TIM_IT_CC4) != RESET) 
		{
			/* Clear TIM2 Capture compare interrupt pending bit */
			TIM_ClearITPendingBit(TIM5, TIM_IT_CC4);			
			
			if(VadENA!=1)
			{
				VadENA=1;
				TIM_Cmd(TIM19, ENABLE);
				//printf("*converting!*\r\n");
			}
				
		}

	}
		

	TIM_ClearITPendingBit(TIM5, TIM_IT_CC4|TIM_IT_Update); //清除中断标志位
}
Пример #26
0
void TIM2_IRQHandler ( void )
{
	TIM_ClearITPendingBit ( TIM2, TIM_IT_Update );
	irmp_ISR ( );             // call irmp ISR
};
Пример #27
0
void __attribute__((used)) TIM7_IRQHandler(void)
{
  TIM_ClearITPendingBit(TIM7, TIM_IT_Update);

  __sync_fetch_and_add(&usecTimerHighCount, 1);
}
Пример #28
0
/*********************************************************************************
  *Function      : void TIM4_Tone_Interrupt_Handler(void)
  *Description  : set duty cycle
  *Input          : none
  *Output        : none
  *Return        : none
  *author        : lz
  *date           : 6-December-2013
  *Others        :         
**********************************************************************************/
void TIM4_Tone_Interrupt_Handler(void)
{
    uint16_t capture;

    if (TIM_GetITStatus(TIM4, TIM_IT_CC1) != RESET)
    {
        TIM_ClearITPendingBit(TIM4, TIM_IT_CC1 );
        capture = TIM_GetCapture1(TIM4);
        TIM_SetCompare1(TIM4, capture + PIN_MAP[9].timer_ccr);
        if(PIN_MAP[9].user_property != -1)
        {
            if (PIN_MAP[9].user_property > 0)
            {
                PIN_MAP[9].user_property -= 1;
            }
            else
            {
                noTone(9);
            }
        }
    }

    if (TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET)
    {
        TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);
        capture = TIM_GetCapture2(TIM4);
        TIM_SetCompare2(TIM4, capture + PIN_MAP[8].timer_ccr);
        if(PIN_MAP[8].user_property != -1)
        {
            if (PIN_MAP[8].user_property > 0)
            {
                PIN_MAP[8].user_property -= 1;
            }
            else
            {
                noTone(8);
            }
        }
    }

    if (TIM_GetITStatus(TIM4, TIM_IT_CC3) != RESET)
    {
        TIM_ClearITPendingBit(TIM4, TIM_IT_CC3);
        capture = TIM_GetCapture2(TIM4);
        TIM_SetCompare2(TIM4, capture + PIN_MAP[6].timer_ccr);
        if(PIN_MAP[6].user_property != -1)
        {
            if (PIN_MAP[6].user_property > 0)
            {
                PIN_MAP[6].user_property -= 1;
            }
            else
            {
                noTone(6);
            }
        }
    }

    if (TIM_GetITStatus(TIM4, TIM_IT_CC4) != RESET)
    {
        TIM_ClearITPendingBit(TIM4, TIM_IT_CC4);
        capture = TIM_GetCapture2(TIM4);
        TIM_SetCompare2(TIM4, capture + PIN_MAP[7].timer_ccr);
        if(PIN_MAP[7].user_property != -1)
        {
            if (PIN_MAP[7].user_property > 0)
            {
                PIN_MAP[7].user_property -= 1;
            }
            else
            {
                noTone(7);
            }
        }
    }
}
Пример #29
0
/*********************************************************************************
  *Function      : void TIM2_Tone_Interrupt_Handler(void)
  *Description  : set duty cycle
  *Input          : none
  *Output        : none
  *Return        : none
  *author        : lz
  *date           : 6-December-2013
  *Others        :         
**********************************************************************************/
void TIM2_Tone_Interrupt_Handler(void)
{
    uint16_t capture;

    if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)
    {
        TIM_ClearITPendingBit(TIM2, TIM_IT_CC1 );
        capture = TIM_GetCapture1(TIM2);
        TIM_SetCompare1(TIM2, capture + PIN_MAP[30].timer_ccr);
        if(PIN_MAP[30].user_property != -1)
        {
            if (PIN_MAP[30].user_property > 0)
            {
                PIN_MAP[30].user_property -= 1;
            }
            else
            {
                noTone(30);
            }
        }
    }

    if (TIM_GetITStatus(TIM2, TIM_IT_CC2) != RESET)
    {
        TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
        capture = TIM_GetCapture2(TIM2);
        TIM_SetCompare2(TIM2, capture + PIN_MAP[31].timer_ccr);
        if(PIN_MAP[31].user_property != -1)
        {
            if (PIN_MAP[31].user_property > 0)
            {
                PIN_MAP[31].user_property -= 1;
            }
            else
            {
                noTone(31);
            }
        }
    }

    if (TIM_GetITStatus(TIM2, TIM_IT_CC3) != RESET)
    {
        TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);
        capture = TIM_GetCapture3(TIM2);
        TIM_SetCompare3(TIM2, capture + PIN_MAP[33].timer_ccr);
        if(PIN_MAP[33].user_property != -1)
        {
            if (PIN_MAP[33].user_property > 0)
            {
                PIN_MAP[33].user_property -= 1;
            }
            else
            {
                noTone(33);
            }
        }
    }

    if (TIM_GetITStatus(TIM2, TIM_IT_CC4) != RESET)
    {
        TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);
        capture = TIM_GetCapture4(TIM2);
        TIM_SetCompare4(TIM2, capture + PIN_MAP[32].timer_ccr);
        if(PIN_MAP[32].user_property != -1)
        {
            if (PIN_MAP[32].user_property > 0)
            {
                PIN_MAP[32].user_property -= 1;
            }
            else
            {
                noTone(32);
            }
        }
    }
}
Пример #30
0
extern "C" void TIM5_IRQHandler(void)
{
	//f4TIM5.call_callback();
	int left = dev_v2::AsyncWorker::interrupt();
	TIM_ClearITPendingBit(TIM5 , TIM_FLAG_Update);
}