Пример #1
0
Файл: buz.c Проект: wantf/C
void BuzzerStart(void)
{
/*
		TIM2_DeInit();
		TIM2_TimeBaseInit(TIM2_PRESCALER_16,u8BzrFrqBuf);
		TIM2_ARRPreloadConfig(ENABLE);
		TIM2_Cmd(ENABLE);
		TIM2_ITConfig(TIM2_IT_UPDATE,ENABLE);
*/
		TIM2_DeInit(); 
		TIM2_TimeBaseInit(TIM2_PRESCALER_16,u8BzrFrqBuf ); 
#ifdef	NEW_260		
		TIM2_CCxCmd(TIM2_CHANNEL_3, ENABLE); 
		TIM2_OC3Init(TIM2_OCMODE_TOGGLE, TIM2_OUTPUTSTATE_ENABLE, 64, TIM2_OCPOLARITY_LOW); 
		TIM2_OC3PreloadConfig(ENABLE); 
#else
		TIM2_CCxCmd(TIM2_CHANNEL_2, ENABLE); 
		TIM2_OC2Init(TIM2_OCMODE_TOGGLE, TIM2_OUTPUTSTATE_ENABLE, 64, TIM2_OCPOLARITY_LOW); 
		TIM2_OC2PreloadConfig(ENABLE);
#endif
		TIM2_ARRPreloadConfig(ENABLE); 
		TIM2_ITConfig(TIM2_IT_CC1, DISABLE); 
		TIM2_ITConfig(TIM2_IT_CC2, DISABLE); 
		TIM2_ITConfig(TIM2_IT_CC3, DISABLE); 
		TIM2_ITConfig(TIM2_IT_UPDATE, DISABLE); 
		TIM2_GenerateEvent(TIM2_EVENTSOURCE_UPDATE); 
		TIM2_Cmd(ENABLE);

		SetBuzzerEnOn();
}
Пример #2
0
 void tim2_on(void)
{
   TIM2_TimeBaseInit(TIM2_Prescaler_2,TIM2_CounterMode_Up,0x0800);
   TIM2_OC1Init(TIM2_OCMode_PWM2,TIM2_OutputState_Enable,0x0400,TIM2_OCPolarity_High,TIM2_OCIdleState_Set);
   TIM2_OC2Init(TIM2_OCMode_PWM2,TIM2_OutputState_Enable,0x0400,TIM2_OCPolarity_Low ,TIM2_OCIdleState_Set); 
   TIM2_CCxCmd(TIM2_Channel_1,ENABLE);
   TIM2_CCxCmd(TIM2_Channel_2,ENABLE);
   TIM2_BKRConfig(TIM2_OSSIState_Enable,TIM2_LockLevel_Off,TIM2_BreakState_Disable,TIM2_BreakPolarity_High,TIM2_AutomaticOutput_Enable);
   TIM2_ITConfig(TIM2_IT_CC1,ENABLE);
   TIM2_ITConfig(TIM2_IT_CC2,DISABLE);
   TIM2_Cmd(ENABLE);
};
Пример #3
0
void MOD_TIM_Config(Mod_Master_Frame_TypeDef* aFrame)
{


	TIM2_DeInit();
	
	TIM2_TimeBaseInit(0x0F, 1500); //2ms comm response time
	TIM2_UpdateRequestConfig(TIM2_UPDATESOURCE_REGULAR);
	TIM2_GenerateEvent(TIM2_EVENTSOURCE_UPDATE);
	TIM2_Cmd(DISABLE);
	TIM2_ClearITPendingBit(TIM2_IT_UPDATE);
	TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
	TIM2_ClearFlag(TIM2_FLAG_UPDATE);
	
	TIM4_DeInit();
	
	TIM4_TimeBaseInit(0x07, 126);	//128 * 126 = 16128 = 2ms (8MHz), frame check
	TIM4_UpdateRequestConfig(TIM4_UPDATESOURCE_REGULAR);
	TIM4_GenerateEvent(TIM4_EVENTSOURCE_UPDATE);
	TIM4_Cmd(DISABLE);
	TIM4_ClearITPendingBit(TIM4_IT_UPDATE);
	TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
	TIM4_ClearFlag(TIM4_FLAG_UPDATE);
	
}
Пример #4
0
/**
  * @brief Example firmware main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{

  /* Time base configuration */
  TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 65535);

  /* Prescaler configuration */
  TIM2_PrescalerConfig(TIM2_PRESCALER_2048, TIM2_PSCRELOADMODE_IMMEDIATE);

  /* Output Compare Active Mode configuration: Channel1 */
  /*
	  TIM2_OCMode = TIM2_OCMODE_INACTIVE
       TIM2_OCPolarity = TIM2_OCPOLARITY_HIGH
       TIM2_Pulse = CCR1_Val
	*/
  TIM2_OC1Init(TIM2_OCMODE_INACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH); 
  TIM2_OC1PreloadConfig(DISABLE);

  /* Output Compare Active Mode configuration: Channel2 */
  
  /*TIM2_Pulse = CCR2_Val;  */
  TIM2_OC2Init(TIM2_OCMODE_INACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_HIGH); 
  TIM2_OC2PreloadConfig(DISABLE);

  /* Output Compare Active Mode configuration: Channel3 */
  /*TIM2_Pulse = CCR3_Val  */
  TIM2_OC3Init(TIM2_OCMODE_INACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val, TIM2_OCPOLARITY_HIGH); 
  TIM2_OC3PreloadConfig(DISABLE);

  TIM2_ARRPreloadConfig(ENABLE);
  
  /* TIM IT enable */
  TIM2_ITConfig(TIM2_IT_CC1, ENABLE);
  TIM2_ITConfig(TIM2_IT_CC2, ENABLE);
  TIM2_ITConfig(TIM2_IT_CC3, ENABLE);

  /* Set pin PG.5 & PG.6 & PG.7 to high state */
  GPIO_Init(GPIOG, (GPIO_PIN_5|GPIO_PIN_6| GPIO_PIN_7), GPIO_MODE_OUT_PP_LOW_FAST);
  GPIO_WriteHigh(GPIOG, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
  
  /* TIM2 enable counter */
  TIM2_Cmd(ENABLE);
	
  enableInterrupts();

  while (1);
}
Пример #5
0
inline void
vMBPortTimersDisable(  )
{
    /* Disable any pending timers. */
  
    TIM2_ITConfig(TIM2_IT_UPDATE, DISABLE);
    TIM2_Cmd(DISABLE);
}
Пример #6
0
/*
    Configure TIM2 to interrupt every 10ms
  */
void InitTimer()
{
  TIM2_DeInit();
  TIM2_TimeBaseInit(TIM2_PRESCALER_32768,      // Interrupt every 32768 clock pulses.
                    5);                        // 16Mhz / 32768 = 488 -> every 2ms -> ARR=5 -> every 10ms
  TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
  TIM2_Cmd(ENABLE);
}
Пример #7
0
inline void
vMBPortTimersEnable(  )
{
    /* Enable the timer with the timeout passed to xMBPortTimersInit( ) */
  
    TIM2_ClearFlag(TIM2_FLAG_UPDATE);
    TIM2_SetCounter(0x00);
    TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
    TIM2_Cmd(ENABLE);
}
Пример #8
0
/**
  * @brief Включить таймер № 2.
  * @par
  * Параметры отсутствуют
  * @retval
  * Возвращаемое значение отсутствует
*/
void CounterTimerStart(void)
{
  TIM2_DeInit();
  
  TIM2_TimeBaseInit(TIM2_PRESCALER_32768, 610);
  
  TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);  
  
  TIM2_Cmd(ENABLE); 
}
Пример #9
0
void timer_init()
{
  TIM2_DeInit();
  TIM2_TimeBaseInit(TIM2_PRESCALER_1, 1600);
  //TIM2_PrescalerConfig(TIM2_PRESCALER_32768, TIM2_PSCRELOADMODE_IMMEDIATE);
  TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
  
  ITC_SetSoftwarePriority(ITC_IRQ_TIM2_OVF, ITC_PRIORITYLEVEL_1);  
  TIM2_Cmd(ENABLE);
}
Пример #10
0
void timerInit(void)
{
  /* TIM2 initial */
  TIM2_TimeBaseInit(TIM2_PRESCALER_16,7812);
  TIM2_ITConfig( TIM2_IT_UPDATE , ENABLE);
  TIM2_SetCounter(0x0000);
  /*计时器打开*/
  TIM2_Cmd(ENABLE);
  TIM2_ClearFlag(TIM2_FLAG_UPDATE);
}
/* Private functions ---------------------------------------------------------*/
void TIM2_Config(void)
{
	/* Time base configuration */
	TIM2_TimeBaseInit(TIM2_Prescaler_1,TIM2_CounterMode_Up, 1);
	
	/* Clear TIM1 update flag */
	TIM2_ClearFlag(TIM2_FLAG_Update);
	/* Enable update interrupt */
	TIM2_ITConfig(TIM2_IT_Update, ENABLE);

	/* Enable TIM2 */
	TIM2_Cmd(ENABLE);
}
Пример #12
0
/**
  * @brief  Configure Output Compare Active Mode for TIM2 Channel1, Channel2 and 
  *         channel3  
  * @param  None
  * @retval None
  */
static void TIM2_Config(void)
{
  /* Time base configuration */
  TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 65535);

  /* Prescaler configuration */
  TIM2_PrescalerConfig(TIM2_PRESCALER_2048, TIM2_PSCRELOADMODE_IMMEDIATE);

  /* Output Compare Active Mode configuration: Channel1 */
  /*
	  TIM2_OCMode = TIM2_OCMODE_INACTIVE
       TIM2_OCPolarity = TIM2_OCPOLARITY_HIGH
       TIM2_Pulse = CCR1_Val
	*/
  TIM2_OC1Init(TIM2_OCMODE_INACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH); 
  TIM2_OC1PreloadConfig(DISABLE);

  /* Output Compare Active Mode configuration: Channel2 */
  
  /*TIM2_Pulse = CCR2_Val;  */
  TIM2_OC2Init(TIM2_OCMODE_INACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_HIGH); 
  TIM2_OC2PreloadConfig(DISABLE);

  /* Output Compare Active Mode configuration: Channel3 */
  /*TIM2_Pulse = CCR3_Val  */
  TIM2_OC3Init(TIM2_OCMODE_INACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val, TIM2_OCPOLARITY_HIGH); 
  TIM2_OC3PreloadConfig(DISABLE);

  TIM2_ARRPreloadConfig(ENABLE);
  
  /* TIM IT enable */
  TIM2_ITConfig(TIM2_IT_CC1, ENABLE);
  TIM2_ITConfig(TIM2_IT_CC2, ENABLE);
  TIM2_ITConfig(TIM2_IT_CC3, ENABLE);
  
  /* TIM2 enable counter */
  TIM2_Cmd(ENABLE);
}
Пример #13
0
/* ----------------------- Start implementation -----------------------------*/
BOOL
xMBPortTimersInit( USHORT usTim1Timerout50us )
{
    ENTER_CRITICAL_SECTION();
    
    // f_master = 16 MHz
    // TIM2 counter clock = f_master / Prescaler = 0.5 MHz
    // 1 step = 2 us
    // maximum timeout = 2us * 65535 = 130ms
    TIM2_DeInit();
    TIM2_TimeBaseInit(TIM2_PRESCALER_32, 25 * usTim1Timerout50us);
    TIM2_ClearFlag(TIM2_FLAG_UPDATE);
    TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);

    EXIT_CRITICAL_SECTION();

    return TRUE;
}
Пример #14
0
void TIM2_Config(void)
{
    /* TIM2 configuration:
    - TIM2CLK is set to 16 MHz, the TIM2 Prescaler is equal to 128 so the TIM2 counter
    clock used is 16 MHz / 512 = 31250 Hz

    - In this example we need to generate a time base equal to 500 ms
    so TIM2_PERIOD = (0.5 * 312500 - 1) = 15624 */

    /* Time base configuration */
    TIM2_TimeBaseInit(TIM2_PRESCALER_512, TIM2_PERIOD);

    TIM2_ARRPreloadConfig(ENABLE);
    
    TIM2_ClearFlag(TIM2_FLAG_UPDATE);
    /* Enable update interrupt */
    TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);

    /* Enable TIM2 */
    TIM2_Cmd(ENABLE);
}
Пример #15
0
//Modbus Initialization
void Modbus_Init(void)
{
//Clock divider equals 1.Clock 16MHz
	CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
//Clear bits 
	TIM2_DeInit();
	GPIO_DeInit(GPIOA);
	UART2_DeInit();
//Peripetial Initialization
	TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 78);
	GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);
	UART2_Init(BAUDRATE, UART2_WORDLENGTH_8D, UART2_STOPBITS_2,UART2_PARITY_NO,UART2_SYNCMODE_CLOCK_DISABLE,UART2_MODE_TXRX_ENABLE );  
//Enable Periphs
	TIM2_Cmd(ENABLE);
	UART2_Cmd(ENABLE);
//Interrupt configuration
	TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
	UART2_ITConfig(UART2_IT_RXNE_OR, ENABLE);
#ifndef __DELAY_EN
	#define __MODBUS_EN
	enableInterrupts();
#endif
}