Example #1
0
/**
  * @brief  Configure the TIMER peripheral.
  * @param  None
  * @retval None
  */
void TIMER_Configuration(void)
{
    /* ---------------------------------------------------------------------------
    TIMER2 Configuration: Output Compare Toggle Mode:
    TIMER2CLK = SystemCoreClock / 36000=2K,
    CH2 update rate = TIMER2 counter clock / CHCC2 = 2000/4000 = 0.5 Hz
    ----------------------------------------------------------------------------*/
    TIMER_BaseInitPara TIMER_TimeBaseStructure;
    TIMER_OCInitPara  TIMER_OCInitStructure;

    /* TIMERS clock enable */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1|RCC_APB2PERIPH_TIMER15|RCC_APB2PERIPH_TIMER16|RCC_APB2PERIPH_TIMER17,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2|RCC_APB1PERIPH_TIMER3|RCC_APB1PERIPH_TIMER6|RCC_APB1PERIPH_TIMER14,ENABLE);

    /* TIMER2  configuration */
    TIMER_DeInit(TIMER2);
    TIMER_TimeBaseStructure.TIMER_Prescaler     = 35999;
    TIMER_TimeBaseStructure.TIMER_CounterMode   = TIMER_COUNTER_UP;
    TIMER_TimeBaseStructure.TIMER_Period        = 3999;
    TIMER_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
    TIMER_BaseInit(TIMER2,&TIMER_TimeBaseStructure);

    /* CH2 Configuration in OC_TOGGLE mode */
    TIMER_OCInitStructure.TIMER_OCMode      = TIMER_OC_MODE_TOGGLE;
    TIMER_OCInitStructure.TIMER_OCPolarity  = TIMER_OC_POLARITY_HIGH;
    TIMER_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;
    TIMER_OCInitStructure.TIMER_Pulse       = 3999;
    TIMER_OC2_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC2_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    /* Auto-reload preload enable */
    TIMER_CARLPreloadConfig(TIMER2,ENABLE);
    /* TIMER enable counter*/
    TIMER_Enable( TIMER2, ENABLE );
}
Example #2
0
/**
  * @brief  Configure the TIMER peripheral.
  * @param  None
  * @retval None
  */
void TIM_Configuration(void)
{
    /* -----------------------------------------------------------------------
    TIMER2 Configuration: Single Pulse Mode
    The external signal is connected to TIMER2 CH1 pin (PA0) and the Rising 
    edge is used as active edge.
    The Single Pulse signal is output on TIMER2 CH2 pin (PA1).

    The TIMER2CLK frequency is set to SystemCoreClock (Hz),the Prescaler is 
    4,so the TIMER2 counter clock is 27MHz.

    Single Pulse value = (TIMER2_Period - TIMER2_Pulse) / TIMER2 counter clock
                       = (65535 - 11535) / 27M = 2.0 ms.

    ----------------------------------------------------------------------- */

    TIMER_BaseInitPara TIMER_TimeBaseStructure;
    TIMER_OCInitPara   TIMER_OCInitStructure;
    TIMER_ICInitPara   TIM_ICInitStructure;

    /* TIMER2 clock enable */
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2,ENABLE);

    /* TIMER2 configuration */
    TIMER_DeInit(TIMER2);
    TIMER_TimeBaseStructure.TIMER_Prescaler     = 3;
    TIMER_TimeBaseStructure.TIMER_CounterMode   = TIMER_COUNTER_UP;
    TIMER_TimeBaseStructure.TIMER_Period        = 65535;
    TIMER_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
    TIMER_BaseInit(TIMER2,&TIMER_TimeBaseStructure);

    /* TIMER2 CH2 Configuration in PWM2 mode */
    TIMER_OCInitStructure.TIMER_OCMode      = TIMER_OC_MODE_PWM2;
    TIMER_OCInitStructure.TIMER_OCPolarity  = TIMER_OC_POLARITY_HIGH;
    TIMER_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;
    TIMER_OCInitStructure.TIMER_OCIdleState = TIMER_OC_IDLE_STATE_RESET;

    TIMER_OCInitStructure.TIMER_Pulse = 11535;
    TIMER_OC2_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC2_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    /* TIMER2 CH1 Input Capture Configuration */
    TIM_ICInitStructure.TIMER_CH          = TIMER_CH_1;
    TIM_ICInitStructure.TIMER_ICPolarity  = TIMER_IC_POLARITY_FALLING;
    TIM_ICInitStructure.TIMER_ICSelection = TIMER_IC_SELECTION_DIRECTTI;
    TIM_ICInitStructure.TIMER_ICPrescaler = TIMER_IC_PSC_DIV1;
    TIM_ICInitStructure.TIMER_ICFilter    = 0x00;
    TIMER_ICInit( TIMER2, &TIM_ICInitStructure);

    /* Single Pulse Mode selection */
    TIMER_SinglePulseMode(TIMER2,TIMER_SP_MODE_SINGLE);

    /* Slave Mode selection : TIMER4 */
    /* TIMER2 Input trigger : External Trigger connected to TI1 */
    TIMER_SelectInputTrigger( TIMER2, TIMER_TS_TI1FP1);
    TIMER_SelectSlaveMode( TIMER2, TIMER_SLAVE_MODE_TRIGGER);
}
Example #3
0
/**
  * @brief  Configure the TIMER peripheral.
  * @param  None
  * @retval None
  */
void TIMER_Configuration(void)
{
    /* ---------------------------------------------------------------
    TIMER2 Configuration: 
    TIMER2CLK = SystemCoreClock / 36000 = 2K,
    And generate 3 signals with 3 different delays:
    TIMER2_CH1 delay = 4000/2000  = 2s
    TIMER2_CH2 delay = 8000/2000  = 4s
    TIMER2_CH3 delay = 12000/2000 = 6s
    --------------------------------------------------------------- */
    TIMER_BaseInitPara TIMER_TimeBaseStructure;
    TIMER_OCInitPara  TIMER_OCInitStructure;

    /* TIMERS clock enable */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1|RCC_APB2PERIPH_TIMER15|RCC_APB2PERIPH_TIMER16|RCC_APB2PERIPH_TIMER17,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2|RCC_APB1PERIPH_TIMER3|RCC_APB1PERIPH_TIMER6|RCC_APB1PERIPH_TIMER14,ENABLE);

    /* TIMER2  configuration */
    TIMER_DeInit(TIMER2);
    TIMER_TimeBaseStructure.TIMER_Prescaler     = 35999;
    TIMER_TimeBaseStructure.TIMER_CounterMode   = TIMER_COUNTER_UP;
    TIMER_TimeBaseStructure.TIMER_Period        = 19999;
    TIMER_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
    TIMER_BaseInit(TIMER2,&TIMER_TimeBaseStructure);

    /* CH1,CH2 and CH3 Configuration in OC_ACTIVE mode */
    TIMER_OCInitStructure.TIMER_OCMode      = TIMER_OC_MODE_ACTIVE;
    TIMER_OCInitStructure.TIMER_OCPolarity  = TIMER_OC_POLARITY_HIGH;
    TIMER_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;

      
    TIMER_OCInitStructure.TIMER_Pulse = 3999;
    TIMER_OC1_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC1_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    TIMER_OCInitStructure.TIMER_Pulse = 7999;
    TIMER_OC2_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC2_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    TIMER_OCInitStructure.TIMER_Pulse = 11999;
    TIMER_OC3_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC3_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    /* Auto-reload preload enable */
    TIMER_CARLPreloadConfig(TIMER2,ENABLE);
    /* TIMER enable counter*/
    TIMER_Enable( TIMER2, ENABLE );
}
Example #4
0
/**
  * @brief  Configure the TIMER peripheral.
  * @param  None
  * @retval None
  */
void TIMER_Configuration(void)
{
    /* -----------------------------------------------------------------------
    TIMER2 Configuration: generate 3 PWM signals with 3 different duty cycles:
    TIMER2CLK = SystemCoreClock / 72 = 1MHz

    TIMER2 Channel2 duty cycle = (4000/ 16000)* 100  = 25%
    TIMER2 Channel3 duty cycle = (8000/ 16000)* 100  = 50%
    TIMER2 Channel4 duty cycle = (12000/ 16000)* 100 = 75%
    ----------------------------------------------------------------------- */
    TIMER_BaseInitPara TIMER_TimeBaseStructure;
    TIMER_OCInitPara  TIMER_OCInitStructure;

    /* TIMERS clock enable */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1|RCC_APB2PERIPH_TIMER15|RCC_APB2PERIPH_TIMER16|RCC_APB2PERIPH_TIMER17,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2|RCC_APB1PERIPH_TIMER3|RCC_APB1PERIPH_TIMER6|RCC_APB1PERIPH_TIMER14,ENABLE);

    /* TIMER2  configuration */
    TIMER_DeInit(TIMER2);
    TIMER_TimeBaseStructure.TIMER_Prescaler     = 71;
    TIMER_TimeBaseStructure.TIMER_CounterMode   = TIMER_COUNTER_UP;
    TIMER_TimeBaseStructure.TIMER_Period        = 15999;
    TIMER_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
    TIMER_BaseInit(TIMER2,&TIMER_TimeBaseStructure);

    /* CH2,CH3 and CH4 Configuration in PWM mode */
    TIMER_OCInitStructure.TIMER_OCMode      = TIMER_OC_MODE_PWM1;
    TIMER_OCInitStructure.TIMER_OCPolarity  = TIMER_OC_POLARITY_HIGH;
    TIMER_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;

    TIMER_OCInitStructure.TIMER_Pulse = 3999;
    TIMER_OC2_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC2_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    TIMER_OCInitStructure.TIMER_Pulse = 7999;
    TIMER_OC3_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC3_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    TIMER_OCInitStructure.TIMER_Pulse = 11999;
    TIMER_OC4_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC4_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    /* Auto-reload preload enable */
    TIMER_CARLPreloadConfig(TIMER2,ENABLE);
    /* TIMER enable counter*/
    TIMER_Enable( TIMER2, ENABLE );
}
Example #5
0
void pwm_set_reverse(uint8_t number, float pwm)
{
	pwm = pwm * PWMTOP;

	if (pwm < 0)
		pwm = 0;
	if (pwm > PWMTOP)
		pwm = PWMTOP;

	TIM_OCInitStructure.TIMER_Pulse = (uint32_t) pwm;
	switch (number)
	  {
	  case 2:		// FR ok
		  TIMER_OC2_Init(TIMER1, &TIM_OCInitStructure);
		  break;

	  case 3:		// BR ok
		  TIMER_OC4_Init(TIMER3, &TIM_OCInitStructure);
		  break;

	  case 0:		// FL ok
		  TIMER_OC1_Init(TIMER2, &TIM_OCInitStructure);
		  break;

	  case 1:		// BL ok        
		  TIMER_OC3_Init(TIMER2, &TIM_OCInitStructure);
		  break;

	  default:
		  // handle error;
		  //
		  break;

	  }

}
Example #6
0
void pwm_init(void)
{
	
    GPIO_InitPara GPIO_InitStructure;

	// timer 3 pin PB1 config ( ch4 )
    GPIO_InitStructure.GPIO_Pin = GPIO_PIN_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
    GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_PULLDOWN;
    GPIO_Init(GPIOB,&GPIO_InitStructure);
		
    GPIO_PinAFConfig(GPIOB,GPIO_PINSOURCE1,GPIO_AF_1);
	
	// GPIO pins PA8 , 9 ,10 setup ( Timer1 ch 1 , 2 , 3)
	  GPIO_InitStructure.GPIO_Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;

    GPIO_Init(GPIOA,&GPIO_InitStructure);
		
    GPIO_PinAFConfig(GPIOA,GPIO_PINSOURCE8,GPIO_AF_2);
	  GPIO_PinAFConfig(GPIOA,GPIO_PINSOURCE9,GPIO_AF_2);
		GPIO_PinAFConfig(GPIOA,GPIO_PINSOURCE10,GPIO_AF_2);
	
    TIMER_BaseInitPara TIM_TimeBaseStructure;

    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER3,ENABLE);

// TIMER3 for pins A8 A9 A10

    TIM_TimeBaseStructure.TIMER_Prescaler = TIMER_PRESCALER - 1;  //
    TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;
    TIM_TimeBaseStructure.TIMER_Period = PWMTOP;
    TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
    TIMER_BaseInit(TIMER3,&TIM_TimeBaseStructure);
		

 //Ch1 , 2 , 3 
    TIM_OCInitStructure.TIMER_OCMode = TIMER_OC_MODE_PWM1;
    TIM_OCInitStructure.TIMER_OCPolarity = OUT_POLARITY;
    TIM_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;
    TIM_OCInitStructure.TIMER_OCIdleState = TIMER_OC_IDLE_STATE_RESET;
		
    TIM_OCInitStructure.TIMER_Pulse = 0;
    TIMER_OC4_Init(TIMER3, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER3,ENABLE);

    TIMER_CARLPreloadConfig(TIMER3,ENABLE);

    TIMER_Enable( TIMER3, ENABLE );
		
    TIMER_BaseInit(TIMER1,&TIM_TimeBaseStructure);

    TIMER_OC1_Init(TIMER1, &TIM_OCInitStructure);

    TIMER_OC2_Init(TIMER1, &TIM_OCInitStructure);

    TIMER_OC3_Init(TIMER1, &TIM_OCInitStructure);
		
	TIMER_CtrlPWMOutputs(TIMER1,ENABLE);	
		
    TIMER_CARLPreloadConfig(TIMER1,ENABLE);

	TIMER_OC1_Preload(TIMER1,ESC_PRELOAD);
	TIMER_OC2_Preload(TIMER1,ESC_PRELOAD);
	TIMER_OC3_Preload(TIMER1,ESC_PRELOAD);
	TIMER_OC4_Preload(TIMER3,ESC_PRELOAD);
	
  TIMER_Enable( TIMER1, ENABLE );
}
Example #7
0
void pwm_init(void)
{
	GPIO_InitPara GPIO_InitStructure;


//pin A0 TM2_ch1
	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_1;
	GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF;
	GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
	GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_PULLDOWN;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE1, GPIO_AF_2);


	TIMER_BaseInitPara TIM_TimeBaseStructure;

	RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2 | 
															RCC_APB1PERIPH_TIMER14 |
																RCC_APB1PERIPH_TIMER3, ENABLE);
	
	RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1, ENABLE);

// timer 2
	TIM_TimeBaseStructure.TIMER_Prescaler = TIMER_PRESCALER - 1;	//
	TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_CENTER_ALIGNED2;
	TIM_TimeBaseStructure.TIMER_Period = PWMTOP;
	TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
// init timer 2
	TIMER_BaseInit(TIMER2, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_OCMode = TIMER_OC_MODE_PWM1;
	TIM_OCInitStructure.TIMER_OCPolarity = TIMER_OC_POLARITY_HIGH;
	TIM_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;
	TIM_OCInitStructure.TIMER_OCIdleState = TIMER_OC_IDLE_STATE_RESET;

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC2_Init(TIMER2, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER2, ENABLE);

	TIMER_CARLPreloadConfig(TIMER2, ENABLE);


	TIMER_OC2_Preload(TIMER2, TIMER_OC_PRELOAD_DISABLE);


	// pin A3

	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_3;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE3, GPIO_AF_2);

	TIMER_OC4_Init(TIMER2, &TIM_OCInitStructure);


	TIMER_OC4_Preload(TIMER2, TIMER_OC_PRELOAD_DISABLE);

//   TIMER_Enable( TIMER2, ENABLE );

// timer 1 ch3 , ch1 
// pins A10 , A8         
	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_10 | GPIO_PIN_8;

	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE10, GPIO_AF_2);
	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE8, GPIO_AF_2);


// timer 1

// init timer 1
	TIMER_BaseInit(TIMER1, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC3_Init(TIMER1, &TIM_OCInitStructure);

	TIMER_OC1_Init(TIMER1, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER1, ENABLE);

	TIMER_CARLPreloadConfig(TIMER1, ENABLE);


	TIMER_OC3_Preload(TIMER1, TIMER_OC_PRELOAD_DISABLE);

	TIMER_OC1_Preload(TIMER1, TIMER_OC_PRELOAD_DISABLE);


// bridge dir 2
///////////////

	//pin A9 TM1_ch2
	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_9;

	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE9, GPIO_AF_2);

// timer 1

// init timer 1
	TIMER_BaseInit(TIMER1, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC2_Init(TIMER2, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER1, ENABLE);

	TIMER_CARLPreloadConfig(TIMER1, ENABLE);


	TIMER_OC2_Preload(TIMER1, TIMER_OC_PRELOAD_DISABLE);



// timer 3 PB1 af1 ch4

	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_1;

	GPIO_Init(GPIOB, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOB, GPIO_PINSOURCE1, GPIO_AF_1);


// timer 3

// init timer 3
	TIMER_BaseInit(TIMER3, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC4_Init(TIMER3, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER3, ENABLE);

	TIMER_CARLPreloadConfig(TIMER3, ENABLE);


	TIMER_OC4_Preload(TIMER3, TIMER_OC_PRELOAD_DISABLE);

// A0
// Timer2 ch1

	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0;

	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE0, GPIO_AF_2);


// timer 2

// init timer 2
	TIMER_BaseInit(TIMER2, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC1_Init(TIMER2, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER2, ENABLE);

	TIMER_CARLPreloadConfig(TIMER2, ENABLE);


	TIMER_OC1_Preload(TIMER2, TIMER_OC_PRELOAD_DISABLE);

// PA2 tm2 ch3

	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_2;

	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE2, GPIO_AF_2);


	TIMER_OC3_Init(TIMER2, &TIM_OCInitStructure);

	TIMER_OC3_Preload(TIMER2, TIMER_OC_PRELOAD_DISABLE);



	TIMER_Enable(TIMER3, ENABLE);

	TIMER_Enable(TIMER1, ENABLE);

	TIMER_Enable(TIMER2, ENABLE);


}
Example #8
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{       
    /* Configure System clocks -----------------------------------------------*/
    RCC_Configuration();
    
    /* Configure NVIC --------------------------------------------------------*/
    NVIC_Configuration();
  
    /* Configure GPIO ports --------------------------------------------------*/
    GPIO_Configuration();
    
    /* Configure TIM2 --------------------------------------------------------*/ 
    /* Configure Time Base */
    TIMER_BaseStructInit(&TIM_TimeBaseStructure); 
    TIM_TimeBaseStructure.TIMER_Period = 256;          
    TIM_TimeBaseStructure.TIMER_Prescaler = 6;       
    TIM_TimeBaseStructure.TIMER_ClockDivision = 0x0;    
    TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;  
    TIMER_BaseInit(TIMER2, &TIM_TimeBaseStructure);
    
    /* Configure TIM2 channel2 in PWM mode */
    TIM_OCInitStructure.TIMER_OCMode = TIMER_OC_MODE_PWM1; 
    TIM_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;                
    TIM_OCInitStructure.TIMER_Pulse = 128; 
    TIM_OCInitStructure.TIMER_OCPolarity = TIMER_OC_POLARITY_LOW;         
    TIMER_OC2_Init(TIMER2, &TIM_OCInitStructure);
    
    /* Configure DMA1 Channel1 -----------------------------------------------*/
    DMA_DeInit(DMA1_CHANNEL1);
    DMA_InitStructure.DMA_PeripheralBaseAddr = ADC_RDTR_Address;
    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_RegularConvertedValueTab;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PERIPHERALSRC;
    DMA_InitStructure.DMA_BufferSize = 64;
    DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE;
    DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_ENABLE;
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PERIPHERALDATASIZE_HALFWORD;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MEMORYDATASIZE_HALFWORD;
    DMA_InitStructure.DMA_Mode = DMA_MODE_NORMAL;
    DMA_InitStructure.DMA_Priority = DMA_PRIORITY_HIGH;
    DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE;
    DMA_Init(DMA1_CHANNEL1, &DMA_InitStructure);
    
    /* Enable DMA1 channel1 */
    DMA_Enable(DMA1_CHANNEL1, ENABLE);
    
    /* Configure ADC ---------------------------------------------------------*/
    ADC_InitStructure.ADC_Mode_Scan = ENABLE;
    ADC_InitStructure.ADC_Mode_Continuous = DISABLE;
    ADC_InitStructure.ADC_Trig_External  = ADC_EXTERNAL_TRIGGER_MODE_T2_CC2;
    ADC_InitStructure.ADC_Data_Align = ADC_DATAALIGN_RIGHT;
    ADC_InitStructure.ADC_Channel_Number = 1;
    ADC_Init(&ADC_InitStructure);
    
    /* Configure ADC regular channel14 */ 
    ADC_RegularChannel_Config(ADC_CHANNEL_14, 1, ADC_SAMPLETIME_55POINT5);
    
    /* Set inserted sequencer length */
    ADC_InsertedSequencerLength_Config(1);
    /* Configure ADC inserted channel */ 
    ADC_InsertedChannel_Config(ADC_CHANNEL_11, 1, ADC_SAMPLETIME_55POINT5);
    /* Configure ADC inserted external trigger */
    ADC_ExternalTrigInsertedConv_Config(ADC_EXTERNAL_TRIG_INSERTCONV_NONE);
    
    /* Enable automatic inserted conversion start after regular one */
    ADC_AutoInsertedConv_Enable(ENABLE);
    
    /* Enable ADC DMA */
    ADC_DMA_Enable(ENABLE);   
    
    /* Enable ADC external trigger */ 
    ADC_ExternalTrigConv_Enable( ENABLE);
    
    /* Enable EOIC interrupt */
    ADC_INTConfig(ADC_INT_EOIC, ENABLE);
    
    /* Enable ADC */
    ADC_Enable(ENABLE); 
    
    ADC_Calibration();
    
    /* TIM2 counter enable */
    TIMER_Enable(TIMER2, ENABLE);
    /* TIM2 main Output enable */
    TIMER_CtrlPWMOutputs(TIMER2, ENABLE);  
    
    /* Test on channel1 transfer complete flag */
    while(!DMA_GetBitState(DMA1_FLAG_TC1));
    /* Clear channel1 transfer complete flag */
    DMA_ClearBitState(DMA1_FLAG_TC1); 
    
    /* TIM2 counter disable */
    TIMER_Enable(TIMER2, DISABLE);
    /* Turn on the Led1 */
    GD_EVAL_LEDOn(LED1);
    while (1)
    {
    }
}