コード例 #1
0
ファイル: main.c プロジェクト: maxk9/etro_new
//==================================================================================
void TIM3_init(void)
{
	// TIMER3
	RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER3,ENABLE);
	/* Reset all TIMER3 settings */
  TIMER_DeInit(MDR_TIMER3);

  TIMER_BRGInit(MDR_TIMER3,TIMER_HCLKdiv1);

  /* TIM3 configuration ------------------------------------------------*/
  /* Initializes the TIMERx Counter ------------------------------------*/
  sTIM_CntInit.TIMER_Prescaler                = 0x10;
  sTIM_CntInit.TIMER_Period                   = 0x200;
  sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_ClkFixedDir;
  sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
  sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_ETR;
  sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
  sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
  sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
  sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
  sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
  sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
  TIMER_CntInit (MDR_TIMER3,&sTIM_CntInit);
  
	NVIC_EnableIRQ(Timer3_IRQn);
	TIMER_ITConfig(MDR_TIMER3,TIMER_STATUS_CNT_ARR, ENABLE);
    /* Enable TIMER3 */
  TIMER_Cmd(MDR_TIMER3,ENABLE);
  
}
コード例 #2
0
void main(void)
#endif
{
uint32_t i;

  RST_CLK_DeInit();
  RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0);
  /* Enable peripheral clocks --------------------------------------------------*/
  RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_TIMER1 | RST_CLK_PCLK_DMA),ENABLE);
  RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTA), ENABLE);

  /* Init NVIC */
  SCB->AIRCR = 0x05FA0000 | ((uint32_t)0x500);
  SCB->VTOR = 0x08000000;
  /* Disable all interrupt */
  NVIC->ICPR[0] = 0xFFFFFFFF;
  NVIC->ICER[0] = 0xFFFFFFFF;

  /* Disable all DMA request */
  MDR_DMA->CHNL_REQ_MASK_CLR = 0xFFFFFFFF;
  MDR_DMA->CHNL_USEBURST_CLR = 0xFFFFFFFF;

  /* Reset PORTB settings */
  PORT_DeInit(MDR_PORTB);
  /* Reset PORTF settings */
  PORT_DeInit(MDR_PORTF);

  /* Configure TIMER1 pins: CH1, CH2 */

  /* Configure PORTA pins 1, 3 */
  PORT_InitStructure.PORT_Pin   = PORT_Pin_1;
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_ALTER;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST;
  PORT_Init(MDR_PORTA, &PORT_InitStructure);
  PORT_InitStructure.PORT_Pin   = PORT_Pin_3;
  PORT_InitStructure.PORT_OE    = PORT_OE_IN;
  PORT_Init(MDR_PORTA, &PORT_InitStructure);

  /* Init RAM */
  Init_RAM (DstBuf, BufferSize);

  /* Reset all TIMER1 settings */
  TIMER_DeInit(MDR_TIMER1);

  TIMER_BRGInit(MDR_TIMER1,TIMER_HCLKdiv1);

  /* TIM1 configuration ------------------------------------------------*/
  /* Initializes the TIMERx Counter ------------------------------------*/
  sTIM_CntInit.TIMER_Prescaler                = 0x10;
  sTIM_CntInit.TIMER_Period                   = 0x200;
  sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_ClkFixedDir;
  sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
  sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_None;
  sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
  sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
  sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
  sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
  sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
  sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
  TIMER_CntInit (MDR_TIMER1,&sTIM_CntInit);

  /* Initializes the TIMER1 Channel1 -------------------------------------*/
  TIMER_ChnStructInit(&sTIM_ChnInit);

  sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL1;
  sTIM_ChnInit.TIMER_CH_Mode                = TIMER_CH_MODE_PWM;
  sTIM_ChnInit.TIMER_CH_REF_Format          = TIMER_CH_REF_Format3;

  TIMER_ChnInit(MDR_TIMER1, &sTIM_ChnInit);

  TIMER_SetChnCompare(MDR_TIMER1, TIMER_CHANNEL1, 0x100);

  /* Initializes the TIMER1 Channel1 Output -------------------------------*/

  TIMER_ChnOutStructInit(&sTIM_ChnOutInit);

  sTIM_ChnOutInit.TIMER_CH_Number                   = TIMER_CHANNEL1;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Polarity          = TIMER_CHOPolarity_NonInverted;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Source            = TIMER_CH_OutSrc_REF;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Mode              = TIMER_CH_OutMode_Output;

  TIMER_ChnOutInit(MDR_TIMER1, &sTIM_ChnOutInit);

  /* Initializes the TIMER1 Channel2 -------------------------------------*/
  TIMER_ChnStructInit(&sTIM_ChnInit);

  sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL2;
  sTIM_ChnInit.TIMER_CH_Mode                = TIMER_CH_MODE_CAPTURE;

  TIMER_ChnInit(MDR_TIMER1, &sTIM_ChnInit);

  /* Initializes the TIMER1 Channel2 Output -------------------------------*/

  TIMER_ChnOutStructInit(&sTIM_ChnOutInit);

  sTIM_ChnOutInit.TIMER_CH_Number                   = TIMER_CHANNEL2;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Polarity          = TIMER_CHOPolarity_NonInverted;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Source            = TIMER_CH_OutSrc_Only_0;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Mode              = TIMER_CH_OutMode_Input;

  TIMER_ChnOutInit(MDR_TIMER1, &sTIM_ChnOutInit);

  /* Enable TIMER1 DMA request */
  TIMER_DMACmd(MDR_TIMER1,(TIMER_STATUS_CCR_CAP_CH2), ENABLE);

  /* Reset all DMA settings */
  DMA_DeInit();
  DMA_StructInit(&DMA_InitStr);

  /* DMA_Channel_TIM1 configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_TIMER1->CCR2));
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf;
  DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncNo;
  DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncHalfword;
  DMA_PriCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_PriCtrlStr.DMA_Mode = DMA_Mode_Basic;
  DMA_PriCtrlStr.DMA_CycleSize = BufferSize;
  DMA_PriCtrlStr.DMA_NumContinuous = DMA_Transfers_1;
  DMA_PriCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged;
  DMA_PriCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged;
  /* Set Channel Structure */
  DMA_InitStr.DMA_PriCtrlData = &DMA_PriCtrlStr;
  DMA_InitStr.DMA_Priority = DMA_Priority_High;
  DMA_InitStr.DMA_UseBurst = DMA_BurstClear;
  DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY;
  /* Init DMA channel */
  DMA_Init(DMA_Channel_TIM1, &DMA_InitStr);

  /* Enable TIMER1 */
  TIMER_Cmd(MDR_TIMER1,ENABLE);

  /* Transfer complete */
  while((DMA_GetFlagStatus(DMA_Channel_TIM1, DMA_FLAG_CHNL_ENA)))
  {
  }

  /* Check the corectness of written dada */
  for(i = 0; i < BufferSize; i++)
  {
    if (DstBuf[i] != MDR_TIMER1->CCR1)
    {
      TransferStatus &= FAILED;
      break;
    }
    else
    {
      TransferStatus = PASSED;
    }
  }
  /* TransferStatus = PASSED, if the data transmitted are correct */
  /* TransferStatus = FAILED, if the data transmitted are not correct */

  while(1)
  {
  }
}
コード例 #3
0
ファイル: main.c プロジェクト: maxk9/etro_new
void prvSetupHardware( void )
{
	PORT_InitTypeDef PORT_InitStructure;
	UART_InitTypeDef UART_InitStructure;
	//SSP_InitTypeDef SPI_InitStructure;
	TIMER_CntInitTypeDef sTIM_CntInit;
//	TIMER_ChnInitTypeDef sTIM_ChnInit;
	

//CLK
/* Enable HSE clock oscillator */
	RST_CLK_HSEconfig(RST_CLK_HSE_ON);
	
	while(RST_CLK_HSEstatus() == ERROR);

	RST_CLK_CPUclkSelection(RST_CLK_CPUclkCPU_C3);
	MDR_RST_CLK -> CPU_CLOCK |= 2;//CPU_C1 set HSE
	RST_CLK_HSIcmd(DISABLE);
			
/* Enable the RTCHSE clock on all ports */
	RST_CLK_PCLKcmd(ALL_PORTS_CLK, ENABLE);
	PORT_StructInit(&PORT_InitStructure);//reset struct	
/************************ LCD Initialization *************************/

  /* Configure PORTA pins for data transfer to/from LCD */
	PORT_InitStructure.PORT_Pin = LCD_DATA_BUS_8;
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_OE = PORT_OE_IN;

	PORT_Init(MDR_PORTA, &PORT_InitStructure);

	/* Configure PORTE pin4 and pin5 for LCD crystals control */
	PORT_InitStructure.PORT_Pin = KS0108_CS1 | KS0108_CS2 | KS0108_RS;
	PORT_InitStructure.PORT_OE = PORT_OE_OUT;
	PORT_Init(MDR_PORTE, &PORT_InitStructure);

	PORT_Init(MDR_PORTE, &PORT_InitStructure);

	PORT_InitStructure.PORT_Pin = KS0108_EN | KS0108_RW | KS0108_RES;

	PORT_Init(MDR_PORTC, &PORT_InitStructure);
	
	PORT_SetBits(MDR_PORTA, LCD_DATA_BUS_8);
	PORT_SetBits(MDR_PORTE, KS0108_CS1 | KS0108_CS2 | KS0108_RS);
	PORT_SetBits(MDR_PORTC, KS0108_EN | KS0108_RW | KS0108_RES);

//Timer1
	
	// TIMER1
	RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER1,ENABLE);
	/* Reset all TIMER1 settings */
	TIMER_DeInit(MDR_TIMER1);

	TIMER_BRGInit(MDR_TIMER1,TIMER_HCLKdiv1);

	/* TIM1 configuration ------------------------------------------------*/
	/* Initializes the TIMERx Counter ------------------------------------*/
	sTIM_CntInit.TIMER_IniCounter				= 0;
	sTIM_CntInit.TIMER_Prescaler                = 150;//
	sTIM_CntInit.TIMER_Period                   = 82;
	sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_ClkFixedDir;
	sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
	sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_None;
	sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
	sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
	sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
	sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
	sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
	sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
	TIMER_CntInit (MDR_TIMER1,&sTIM_CntInit);

	NVIC_EnableIRQ(Timer1_IRQn);
	TIMER_ITConfig(MDR_TIMER1,TIMER_STATUS_CNT_ARR, ENABLE);
	
	/* TMR1 enable */
	TIMER_Cmd (MDR_TIMER1,ENABLE);

	
	// TIMER2
	RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER2,ENABLE);
	/* Reset all TIMER1 settings */
	TIMER_DeInit(MDR_TIMER2);

	TIMER_BRGInit(MDR_TIMER2,TIMER_HCLKdiv1);

	/* TIM2 configuration ------------------------------------------------*/
	/* Initializes the TIMERx Counter ------------------------------------*/
	sTIM_CntInit.TIMER_IniCounter				= 0;
	sTIM_CntInit.TIMER_Prescaler                = 0xf;//
	sTIM_CntInit.TIMER_Period                   = 0xffff;
	sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_ClkFixedDir;
	sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
	sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_None;
	sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
	sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
	sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
	sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
	sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
	sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
	TIMER_CntInit (MDR_TIMER2,&sTIM_CntInit);

	NVIC_EnableIRQ(Timer2_IRQn);
	TIMER_ITConfig(MDR_TIMER2,TIMER_STATUS_CNT_ARR, ENABLE);
	
	/* TMR2 enable */
	TIMER_Cmd (MDR_TIMER2,ENABLE);
	
	
	// TIMER3
	RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER3,ENABLE);
	/* Reset all TIMER3 settings */
	TIMER_DeInit(MDR_TIMER3);

	TIMER_BRGInit(MDR_TIMER3,TIMER_HCLKdiv1);

  /* TIM3 configuration ------------------------------------------------*/
  /* Initializes the TIMERx Counter ------------------------------------*/
	sTIM_CntInit.TIMER_IniCounter				= 0;
	sTIM_CntInit.TIMER_Prescaler                = 0;
	sTIM_CntInit.TIMER_Period                   = 0xFFFF;
	sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_EvtFixedDir;
	sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
	sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_CH1;
	sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
	sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
	sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
	sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
	sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
	sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
	TIMER_CntInit (MDR_TIMER3,&sTIM_CntInit);

	// 	NVIC_EnableIRQ(Timer3_IRQn);
	// 	TIMER_ITConfig(MDR_TIMER3,TIMER_STATUS_CNT_ARR, ENABLE);
	/* Enable TIMER3 */
	TIMER_Cmd(MDR_TIMER3,ENABLE);	
	
	
	
/************************ UART1 Initialization *************************/
	PORT_StructInit(&PORT_InitStructure);//reset struct

	PORT_InitStructure.PORT_Pin = PORT_Pin_12|PORT_Pin_13;//RX TX
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_OVERRID;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;
	PORT_Init(MDR_PORTE, &PORT_InitStructure);

	PORT_InitStructure.PORT_Pin = PORT_Pin_14;//EN RS485
	PORT_InitStructure.PORT_OE =PORT_OE_OUT;
	PORT_InitStructure.PORT_PD = PORT_PD_OPEN;
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT;
	PORT_Init(MDR_PORTE, &PORT_InitStructure);

	RS485_TX_OFF;
//UART1
	
	RST_CLK_PCLKcmd(RST_CLK_PCLK_UART1,ENABLE);
	/* Set the HCLK division factor = 1 for UART1,UART2*/
	UART_BRGInit(MDR_UART1, UART_HCLKdiv1);
	UART_DeInit(MDR_UART1);
	
	/* Disable interrupt on UART1 */
    NVIC_DisableIRQ(UART1_IRQn);
	
	/* Initialize UART_InitStructure */
	UART_InitStructure.UART_BaudRate			= 38400;
	UART_InitStructure.UART_WordLength			= UART_WordLength8b;
	UART_InitStructure.UART_StopBits			= UART_StopBits1;//PKDU2 niobyi
	UART_InitStructure.UART_Parity				= UART_Parity_No;
	UART_InitStructure.UART_FIFOMode			= UART_FIFO_OFF;
	UART_InitStructure.UART_HardwareFlowControl	= UART_HardwareFlowControl_RXE | UART_HardwareFlowControl_TXE;

	/* Configure UART1 parameters*/
	UART_Init(MDR_UART1,&UART_InitStructure);

	NVIC_EnableIRQ(UART1_IRQn);
	UART_ITConfig(MDR_UART1,UART_IT_RX, ENABLE);
	/* Enables UART1 peripheral */
	UART_Cmd(MDR_UART1,ENABLE);
	
	
//PORT
/************************ Joystick Initialization *************************/

  /* Configure PORTC pins 10..14 for input to handle joystick events */
	PORT_StructInit(&PORT_InitStructure);//reset struct
	
	PORT_InitStructure.PORT_Pin   = ( PORT_Pin_10 | PORT_Pin_11 | PORT_Pin_12 |
									PORT_Pin_13 | PORT_Pin_14 );
	PORT_InitStructure.PORT_OE    = PORT_OE_IN;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
	PORT_InitStructure.PORT_SPEED = PORT_OUTPUT_OFF;

	PORT_Init( MDR_PORTC, &PORT_InitStructure );

/************************ LEDs Initialization *************************/
	PORT_StructInit( &PORT_InitStructure );//reset struct
  /* Configure PORTD pins 10..14 for output to switch LEDs on/off */
	PORT_InitStructure.PORT_Pin   = LEDs_PINs;
	PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;

	PORT_Init( MDR_PORTD, &PORT_InitStructure );

  /* All LEDs switch off */
	PORT_ResetBits(MDR_PORTD, LEDs_PINs);
}
コード例 #4
0
//-----------------------------------------------------------------//
// Setup Timers
// HCLK = 32 MHz
// TIMER_CLK = HCLK / TIMER_HCLKdivx
// CLK = TIMER_CLK/(TIMER_Prescaler + 1)
//-----------------------------------------------------------------//
void HW_TimersInit(void)
{
    TIMER_CntInitTypeDef sTIM_CntInit;
    TIMER_ChnInitTypeDef sTIM_ChnInit;
    TIMER_ChnOutInitTypeDef sTIM_ChnOutInit;

    //======================= TIMER1 =======================//
    // Timer1		CH2		-> BUZ+
    //				CH2N	-> BUZ-
    // TIMER_CLK = HCLK
    // CLK = 1MHz
    // Default buzzer freq = 1 / 500us = 2kHz

    // Initialize timer 1 counter
    TIMER_CntStructInit(&sTIM_CntInit);
    sTIM_CntInit.TIMER_Prescaler                = 0x1F;		// 32MHz / (31 + 1) = 1MHz
    sTIM_CntInit.TIMER_Period                   = 499;
    TIMER_CntInit (MDR_TIMER1,&sTIM_CntInit);

    // Initialize timer 1 channel 2
    TIMER_ChnStructInit(&sTIM_ChnInit);
    sTIM_ChnInit.TIMER_CH_Mode                = TIMER_CH_MODE_PWM;
    sTIM_ChnInit.TIMER_CH_REF_Format          = TIMER_CH_REF_Format6;
    sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL2;
    sTIM_ChnInit.TIMER_CH_CCR_UpdateMode      = TIMER_CH_CCR_Update_On_CNT_eq_0;
    TIMER_ChnInit(MDR_TIMER1, &sTIM_ChnInit);

    // Initialize timer 1 channel 2 output
    TIMER_ChnOutStructInit(&sTIM_ChnOutInit);
    sTIM_ChnOutInit.TIMER_CH_DirOut_Polarity          = TIMER_CHOPolarity_NonInverted;
    sTIM_ChnOutInit.TIMER_CH_DirOut_Source            = TIMER_CH_OutSrc_Only_1;
    sTIM_ChnOutInit.TIMER_CH_DirOut_Mode              = TIMER_CH_OutMode_Output;
    sTIM_ChnOutInit.TIMER_CH_NegOut_Polarity          = TIMER_CHOPolarity_NonInverted;
    sTIM_ChnOutInit.TIMER_CH_NegOut_Source            = TIMER_CH_OutSrc_Only_1;
    sTIM_ChnOutInit.TIMER_CH_NegOut_Mode              = TIMER_CH_OutMode_Output;
    sTIM_ChnOutInit.TIMER_CH_Number                   = TIMER_CHANNEL2;
    TIMER_ChnOutInit(MDR_TIMER1, &sTIM_ChnOutInit);

    // Set default buzzer duty
    MDR_TIMER1->CCR2 = 249;

    // Enable TIMER1 counter clock
    TIMER_BRGInit(MDR_TIMER1,TIMER_HCLKdiv1);

    // Enable TIMER1
    TIMER_Cmd(MDR_TIMER1,ENABLE);



    //======================= TIMER2 =======================//
    // Timer2		CH1N	-> UPWM
    //				CH3N	-> IPWM
    // 				CH2		-> HW control interrupt generation
    // TIMER_CLK = HCLK
    // CLK = 16MHz
    // PWM frequency = 3906.25 Hz (T = 256us)
    // PWM resolution = 12 bit

    // Initialize timer 2 counter
    TIMER_CntStructInit(&sTIM_CntInit);
    sTIM_CntInit.TIMER_Prescaler                = 0x1;		// CLK = 16MHz
    sTIM_CntInit.TIMER_Period                   = 0xFFF;	// 16MHz / 4096 = 3906.25 Hz
    TIMER_CntInit (MDR_TIMER2,&sTIM_CntInit);

    // Initialize timer 2 channels 1,3
    TIMER_ChnStructInit(&sTIM_ChnInit);
    sTIM_ChnInit.TIMER_CH_Mode                = TIMER_CH_MODE_PWM;
    sTIM_ChnInit.TIMER_CH_REF_Format          = TIMER_CH_REF_Format6;
    sTIM_ChnInit.TIMER_CH_CCR_UpdateMode      = TIMER_CH_CCR_Update_On_CNT_eq_0;
    sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL1;			// voltage
    TIMER_ChnInit(MDR_TIMER2, &sTIM_ChnInit);
    sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL3;			// curret
    TIMER_ChnInit(MDR_TIMER2, &sTIM_ChnInit);

    // Initialize timer 2 channel 2 - used for HW control interrupt generation
    TIMER_ChnStructInit(&sTIM_ChnInit);
    sTIM_ChnInit.TIMER_CH_Mode                = TIMER_CH_MODE_PWM;
    sTIM_ChnInit.TIMER_CH_REF_Format          = TIMER_CH_REF_Format1;	// REF output = 1 when CNT == CCR
    sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL2;
    sTIM_ChnInit.TIMER_CH_CCR_UpdateMode      = TIMER_CH_CCR_Update_Immediately;
    TIMER_ChnInit(MDR_TIMER2, &sTIM_ChnInit);

    // Initialize timer 2 channels 1,3 output
    TIMER_ChnOutStructInit(&sTIM_ChnOutInit);
    sTIM_ChnOutInit.TIMER_CH_NegOut_Polarity          = TIMER_CHOPolarity_Inverted;
    sTIM_ChnOutInit.TIMER_CH_NegOut_Source            = TIMER_CH_OutSrc_REF;
    sTIM_ChnOutInit.TIMER_CH_NegOut_Mode              = TIMER_CH_OutMode_Output;
    sTIM_ChnOutInit.TIMER_CH_Number                   = TIMER_CHANNEL1;
    TIMER_ChnOutInit(MDR_TIMER2, &sTIM_ChnOutInit);
    sTIM_ChnOutInit.TIMER_CH_Number                   = TIMER_CHANNEL3;
    TIMER_ChnOutInit(MDR_TIMER2, &sTIM_ChnOutInit);

    // Set default voltage PWM duty cycle
    MDR_TIMER2->CCR1 = 0;
    // Set default current PWM duty cycle
    MDR_TIMER2->CCR3 = 0;
    // Set default CCR for interrupt generation
    MDR_TIMER2->CCR2 = 0;

    // Enable interrupts
    TIMER_ITConfig(MDR_TIMER2, TIMER_STATUS_CCR_REF_CH2, ENABLE);
    //TIMER_ITConfig(MDR_TIMER2, TIMER_STATUS_CNT_ZERO, ENABLE);

    // Enable TIMER2 counter clock
    TIMER_BRGInit(MDR_TIMER2,TIMER_HCLKdiv1);

    // Enable TIMER2
    TIMER_Cmd(MDR_TIMER2,ENABLE);



    //======================= TIMER3 =======================//
    // Timer3		CH1 	-> LPWM (LCD backlight PWM)
    //				CH3N	-> CPWM (System cooler PWM)
    // TIMER_CLK = HCLK
    // CLK = 2MHz
    // PWM frequency = 20kHz
    // PWM resolution = 100

    // Initialize timer 3 counter
    TIMER_CntStructInit(&sTIM_CntInit);
    sTIM_CntInit.TIMER_Prescaler                = 0xF;		// 2MHz at 32MHz core clk
    sTIM_CntInit.TIMER_Period                   = 99;			// 20kHz at 2MHz
    TIMER_CntInit (MDR_TIMER3,&sTIM_CntInit);

    // Initialize timer 3 channel 1
    TIMER_ChnStructInit(&sTIM_ChnInit);
    sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL1;
    sTIM_ChnInit.TIMER_CH_Mode                = TIMER_CH_MODE_PWM;
    sTIM_ChnInit.TIMER_CH_REF_Format          = TIMER_CH_REF_Format6;
    sTIM_ChnInit.TIMER_CH_CCR_UpdateMode      = TIMER_CH_CCR_Update_On_CNT_eq_0;
    TIMER_ChnInit(MDR_TIMER3, &sTIM_ChnInit);

    // Initialize timer 3 channel 1 output
    TIMER_ChnOutStructInit(&sTIM_ChnOutInit);
    sTIM_ChnOutInit.TIMER_CH_Number                   = TIMER_CHANNEL1;
    sTIM_ChnOutInit.TIMER_CH_DirOut_Source            = TIMER_CH_OutSrc_REF;
    sTIM_ChnOutInit.TIMER_CH_DirOut_Polarity          = TIMER_CHOPolarity_NonInverted;
    sTIM_ChnOutInit.TIMER_CH_DirOut_Mode              = TIMER_CH_OutMode_Output;
    TIMER_ChnOutInit(MDR_TIMER3, &sTIM_ChnOutInit);

    // Initialize timer 3 channel 3
    sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL3;
    TIMER_ChnInit(MDR_TIMER3, &sTIM_ChnInit);

    // Initialize timer 3 channel 3 output
    sTIM_ChnOutInit.TIMER_CH_Number           	= TIMER_CHANNEL3;
    sTIM_ChnOutInit.TIMER_CH_DirOut_Source      = TIMER_CH_OutSrc_Only_0;
    sTIM_ChnOutInit.TIMER_CH_DirOut_Mode        = TIMER_CH_OutMode_Input;
    sTIM_ChnOutInit.TIMER_CH_NegOut_Source     	= TIMER_CH_OutSrc_REF;
    sTIM_ChnOutInit.TIMER_CH_NegOut_Polarity   	= TIMER_CHOPolarity_Inverted;
    sTIM_ChnOutInit.TIMER_CH_NegOut_Mode       	= TIMER_CH_OutMode_Output;
    TIMER_ChnOutInit(MDR_TIMER3, &sTIM_ChnOutInit);


    // Set default PWM duty cycle for LCD backlight PWM
    MDR_TIMER3->CCR1 = 0;

    // Set default PWM duty cycle for system cooler PWM
    MDR_TIMER3->CCR3 = 0;

    // Enable TIMER3 counter clock
    TIMER_BRGInit(MDR_TIMER3,TIMER_HCLKdiv1);

    // Enable TIMER3
    TIMER_Cmd(MDR_TIMER3,ENABLE);



}
コード例 #5
0
void main(void)
#endif
{
  RST_CLK_DeInit();
  RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0);
  /* Enable peripheral clocks --------------------------------------------------*/
  RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_DMA | RST_CLK_PCLK_PORTE),ENABLE);
  RST_CLK_PCLKcmd((RST_CLK_PCLK_TIMER1 | RST_CLK_PCLK_DAC),ENABLE);
  RST_CLK_PCLKcmd((RST_CLK_PCLK_SSP1 | RST_CLK_PCLK_SSP2),ENABLE);

  /* Disable all interrupt */
  NVIC->ICPR[0] = 0xFFFFFFFF;
  NVIC->ICER[0] = 0xFFFFFFFF;

  /* Reset PORTE settings */
  PORT_DeInit(MDR_PORTE);

  /* Configure DAC pin: DAC1_OUT */
  /* Configure PORTE pin 9 */
  PORT_InitStructure.PORT_Pin   = PORT_Pin_2;
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_ANALOG;
  PORT_Init(MDR_PORTE, &PORT_InitStructure);

  /* DMA Configuration */
  /* Reset all DMA settings */
  DMA_DeInit();
  DMA_StructInit(&DMA_InitStr);
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)Sine12bit;
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_DAC->DAC1_DATA));
  DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncHalfword;
  DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncNo;
  DMA_PriCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_PriCtrlStr.DMA_Mode = DMA_Mode_PingPong;
  DMA_PriCtrlStr.DMA_CycleSize = 32;
  DMA_PriCtrlStr.DMA_NumContinuous = DMA_Transfers_1;
  DMA_PriCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged;
  DMA_PriCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged;
  /* Set Alternate Control Data */
  DMA_AltCtrlStr.DMA_SourceBaseAddr = (uint32_t)Sine12bit;
  DMA_AltCtrlStr.DMA_DestBaseAddr   = (uint32_t)(&(MDR_DAC->DAC1_DATA));
  DMA_AltCtrlStr.DMA_SourceIncSize = DMA_SourceIncHalfword;
  DMA_AltCtrlStr.DMA_DestIncSize = DMA_DestIncNo;
  DMA_AltCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_AltCtrlStr.DMA_Mode = DMA_Mode_PingPong;
  DMA_AltCtrlStr.DMA_CycleSize = 32;
  DMA_AltCtrlStr.DMA_NumContinuous = DMA_Transfers_1;
  DMA_AltCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged;
  DMA_AltCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged;
  /* Set Channel Structure */
  DMA_InitStr.DMA_PriCtrlData = &DMA_PriCtrlStr;
  DMA_InitStr.DMA_AltCtrlData = &DMA_AltCtrlStr;
  DMA_InitStr.DMA_Priority = DMA_Priority_Default;
  DMA_InitStr.DMA_UseBurst = DMA_BurstClear;
  DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY;

  /* Init DMA channel TIM1*/
  DMA_Init(DMA_Channel_REQ_TIM1, &DMA_InitStr);

  /* Enable dma_req or dma_sreq to generate DMA request */
  MDR_DMA->CHNL_REQ_MASK_CLR = DMA_SELECT(DMA_Channel_REQ_TIM1);
  MDR_DMA->CHNL_USEBURST_CLR = DMA_SELECT(DMA_Channel_REQ_TIM1);

  /* Enable DMA_Channel_TIM1 */
  DMA_Cmd(DMA_Channel_REQ_TIM1, ENABLE);

  /* ADC Configuration */
  /* Reset all ADC settings */
  DAC_DeInit();
  /* DAC channel1 Configuration */
  DAC1_Init(DAC1_AVCC);
  /* DAC channel1 enable */
  DAC1_Cmd(ENABLE);

  /* TIMER1 Configuration */
  /* Time base configuration */
  TIMER_DeInit(MDR_TIMER1);
  TIMER_BRGInit(MDR_TIMER1,TIMER_HCLKdiv1);
  sTIM_CntInit.TIMER_Prescaler                = 0;
  sTIM_CntInit.TIMER_Period                   = 0xFF;
  sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_ClkFixedDir;
  sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
  sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_None;
  sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
  sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
  sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
  sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
  sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
  sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
  TIMER_CntInit (MDR_TIMER1,&sTIM_CntInit);

  /* Enable DMA for TIMER1 */
  TIMER_DMACmd(MDR_TIMER1, TIMER_STATUS_CNT_ARR, TIMER_DMA_Channel0, ENABLE);

  /* TIMER1 enable counter */
  TIMER_Cmd(MDR_TIMER1,ENABLE);

  /* Enable DMA IRQ */
  NVIC_EnableIRQ(DMA_IRQn);

  /* Infinite loop */
  while(1)
  {
  }
}