コード例 #1
0
ファイル: main.c プロジェクト: avr-master/Healty_Beck
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* CLK configuration -------------------------------------------*/
  CLK_Config(); 

  /* ADC configuration -------------------------------------------*/
  ADC_Config(); 

  /* DMA configuration -------------------------------------------*/
  DMA_Config(); 

  /* TIM1 configuration -------------------------------------------*/
  TIM1_Config(); 

  /* Enable ADC1 DMA requests*/
  ADC_DMACmd(ADC1, ENABLE);

  /* Enable TIM1 DMA requests*/
  TIM1_DMACmd(TIM1_DMASource_Update, ENABLE);

  /* Start ADC1 Conversion using Software trigger*/
  ADC_SoftwareStartConv(ADC1);

  while (1)
  {}
}
コード例 #2
0
ファイル: main.c プロジェクト: PaxInstruments/STM32CubeF3
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F3xx HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 72 MHz */
  SystemClock_Config();

  /******* Initialize LEDs available on STM32303E-EVAL RevC board ******************/
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /* configure COMPx : output redirected to TIM1 BKIN and blanking source is TIM1 OC5 */
  COMPx_Config();

  /* TIM1 Configuration in PWM mode */
  TIM1_Config();
  
  /* Infinite loop */
  while (1)
  {
  }
}
コード例 #3
0
ファイル: main.c プロジェクト: edosedgar/stm8s
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    /* TIM1 configuration -----------------------------------------*/
    TIM1_Config();

    while (1)
    {}
}
コード例 #4
0
ファイル: main.c プロジェクト: HorseMa/contiki
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /* CLK configuration -------------------------------------------*/
  CLK_Config(); 

   /* GPIO configuration -------------------------------------------*/
  GPIO_Config(); 
  
   /* TIM1 configuration -------------------------------------------*/
  TIM1_Config();
  
  /* Infinite loop */
  while (1)
  {}
}
コード例 #5
0
ファイル: main.c プロジェクト: MbedTinkerer/STM8teach
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* TIM1 configuration -----------------------------------------*/
    TIM1_Config();
    
  /* TIM4 configuration -----------------------------------------*/
    TIM4_Config();
   
  /* Main Output Enable */
  TIM1_CtrlPWMOutputs(ENABLE);
  
  enableInterrupts();
  
  while (1)
  {} 
}
コード例 #6
0
ファイル: main.c プロジェクト: BackupTheBerlios/ledcube-svn
int main(void)
{
	// Init all needed hardware
	IO_Init();
	VPRG_Off();
	DCPRG_Off();
	Layer_On(-1);
	TIM1_Config();
	TIM8_Config();
	HardwareSPI_init();
	Interrupts_Init();
	SysTick_Init();

	while (1)
	{
		;
	}
}
コード例 #7
0
ファイル: main.c プロジェクト: Rijad12/EL-401
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{

  /* Connect LSI to COO pin*/
  GPIO_Init(GPIOE, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
  CLK_CCOConfig(CLK_OUTPUT_LSI);
  CLK_CCOCmd(ENABLE);

  /* TIM1 configuration -----------------------------------------*/
  TIM1_Config();
    
  /* Compute LSI clock frequency */
  LSIClockFreq = (8 * TIM1ClockFreq) / (ICValue2 - ICValue1);
  
  /* Insert a break point here */
  while (1)
  {}
}
コード例 #8
0
ファイル: main.c プロジェクト: edosedgar/stm8s
void main(void)
{ 
  /* select Clock = 4 MHz */
  CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV4);
  CLK_HSICmd(ENABLE);
  
  
  /* The counter value is initialized to 0.*/
  counter = 0;
  LoadValueIntoSinStruct();           
  
  /* TIM1 configuration -----------------------------------------*/
  TIM1_Config();

  /* Enable interrupts*/
  enableInterrupts();        
  
  while(1)
  {}
}  
コード例 #9
0
ファイル: main.c プロジェクト: avr-master/Healty_Beck
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    /* CLK configuration -------------------------------------------*/
    CLK_Config();

    /* GPIO configuration -------------------------------------------*/
    GPIO_Config();

    /* TIM1 configuration -------------------------------------------*/
    TIM1_Config();

    /* DAC configuration -------------------------------------------*/
    DAC_Config();

    /* COMP configuration -------------------------------------------*/
    COMP_Config();

    /* TIM1 counter enable */
    TIM1_Cmd(ENABLE);

    /* Infinite loop */
    while (1)
    {}
}
コード例 #10
0
ファイル: bsp_adc.c プロジェクト: hyq19921011/MyScop_GUI3.98
/*
*********************************************************************************************************
*	函 数 名: DMA_Open
*	功能说明: 使能ADC1,ADC2,ADC3的DMA
*	形    参: 无
*	返 回 值: 无
*********************************************************************************************************
*/
void ADC_DMA_Open(void)
{
    DMA_InitTypeDef       DMA_InitStructure;

	/* DMA2 Stream1 channel1 配置用于ADC3 **************************************/
    DMA_DeInit(DMA2_Stream1);
	DMA_InitStructure.DMA_Channel = DMA_Channel_2;  
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC3_DR_ADDRESS;
	DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC3ConvertedValue;
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
	DMA_InitStructure.DMA_BufferSize = 1024*10;
	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_PeripheralDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
	DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
	DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_Init(DMA2_Stream1, &DMA_InitStructure);
    DMA_Cmd(DMA2_Stream1, ENABLE);
	
	/* DMA2 Stream2 channel1 配置用于ADC2 **************************************/
    DMA_DeInit(DMA2_Stream2);  /* 在DMA的DMA_Mode_Normal模式,一定要使用这个函数,循环模式可以不用 */
	DMA_InitStructure.DMA_Channel = DMA_Channel_1;  
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC2_DR_ADDRESS;
	DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC2ConvertedValue;
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
	DMA_InitStructure.DMA_BufferSize = 1024*10;
	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_PeripheralDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
	DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
	DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_Init(DMA2_Stream2, &DMA_InitStructure);
    DMA_Cmd(DMA2_Stream2, ENABLE);
	
	/* DMA2 Stream0 channel0 配置用于ADC1 **************************************/
    DMA_DeInit(DMA2_Stream0);
	DMA_InitStructure.DMA_Channel = DMA_Channel_0;  
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS;
	DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC1ConvertedValue;
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
	DMA_InitStructure.DMA_BufferSize = 1024*10;
	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_PeripheralDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
	DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
	DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_Init(DMA2_Stream0, &DMA_InitStructure);
    DMA_Cmd(DMA2_Stream0, ENABLE);

	ADC_RegularChannelConfig(ADC3, ADC_Channel_10, 1, ADC_SampleTime_3Cycles);

	/* 使能 ADC3 --------------------------------------------------------------*/
	ADC_Cmd(ADC3, ENABLE);
	
	ADC_RegularChannelConfig(ADC2, ADC_Channel_10, 1, ADC_SampleTime_3Cycles);

	/* 使能 ADC2 --------------------------------------------------------------*/
	ADC_Cmd(ADC2, ENABLE);
	
	ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_3Cycles);

	/* 使能 ADC1 --------------------------------------------------------------*/
	ADC_Cmd(ADC1, ENABLE);

	/**定时器配置,一定要重新的初始化从而保证同时触发 **/
	TIM1_Config();

	/* 只有在普通触发模式在启动TIM8的计时功能 */
	if(TriggerFlag != 0)
	{
		Time8Recorder();
	}
}
コード例 #11
0
ファイル: bsp_adc.c プロジェクト: hyq19921011/MyScop_GUI3.98
/*
*********************************************************************************************************
*	函 数 名: bsp_InitADC
*	功能说明: ADC初始化
*	形    参: 无
*	返 回 值: 无
*********************************************************************************************************
*/
void bsp_InitADC(void)
{  
	ADC_InitTypeDef       ADC_InitStructure;
    ADC_CommonInitTypeDef ADC_CommonInitStructure;
    DMA_InitTypeDef       DMA_InitStructure;
    GPIO_InitTypeDef      GPIO_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
    /* 配置模拟看门狗中断NVIC */
    NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
	
    /* 使能 ADC1, ADC2, DMA2 和 GPIO 时钟 ****************************************/
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOC, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | 
						   RCC_APB2Periph_ADC3, ENABLE);
	
	/* DMA2 Stream1 channel1 配置用于ADC3 **************************************/
    DMA_InitStructure.DMA_Channel = DMA_Channel_2;  
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC3_DR_ADDRESS;
	DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC3ConvertedValue;
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
	DMA_InitStructure.DMA_BufferSize = Sample_Num;
	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_PeripheralDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
	DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
	DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_Init(DMA2_Stream1, &DMA_InitStructure);
    DMA_Cmd(DMA2_Stream1, ENABLE);
	
    /* DMA2 Stream2 channel1 配置用于ADC2 **************************************/
    DMA_InitStructure.DMA_Channel = DMA_Channel_1;  
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC2_DR_ADDRESS;
	DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC2ConvertedValue;
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
	DMA_InitStructure.DMA_BufferSize = Sample_Num;
	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_PeripheralDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
	DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
	DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_Init(DMA2_Stream2, &DMA_InitStructure);
    DMA_Cmd(DMA2_Stream2, ENABLE);
	
	/* DMA2 Stream0 channel0 配置用于ADC1 **************************************/
    DMA_InitStructure.DMA_Channel = DMA_Channel_0;  
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS;
	DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC1ConvertedValue;
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
	DMA_InitStructure.DMA_BufferSize = Sample_Num;
	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_PeripheralDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
	DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
	DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_Init(DMA2_Stream0, &DMA_InitStructure);
    DMA_Cmd(DMA2_Stream0, ENABLE);

    /* 配置ADC引脚为模拟输入模式******************************/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

    /*
	***************************************************************************   
	  PCLK2 = HCLK / 2 
	  下面选择的是2分频
	  ADCCLK = PCLK2 /2 = HCLK / 4 = 168 / 4 = 42M
      ADC采样频率: Sampling Time + Conversion Time = 3 + 12 cycles = 15cyc
                    Conversion Time = 42MHz / 15cyc = 2.8Mbps.
	****************************************************************************
	*/
    
    /* ADC公共部分初始化**********************************************************/
    ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
    ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
    ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
    ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
    ADC_CommonInit(&ADC_CommonInitStructure); 
	
	/////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////

	 /*ADC3的配置*****************************************************************/
    ADC_InitStructure.ADC_Resolution = ADC_Resolution_10b;
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
	ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC3;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_InitStructure.ADC_NbrOfConversion = 1;
    
    /* ADC3 规则通道配置 */
	ADC_Init(ADC3, &ADC_InitStructure);
	ADC_RegularChannelConfig(ADC3, ADC_Channel_10, 1, ADC_SampleTime_3Cycles);

    /* 使能 ADC3 DMA */
	ADC_DMACmd(ADC3, ENABLE);
	
	/* 配置模拟看门狗的阀值 注意别配置反了,要不一直进入中断 */
    ADC_AnalogWatchdogThresholdsConfig(ADC3, 4095, 0);
    
    /* 配置模拟看门狗监测ADC3的通道10 */
    ADC_AnalogWatchdogSingleChannelConfig(ADC3, ADC_Channel_10);
    
    /* 使能一个规则通道的看门狗 */
    ADC_AnalogWatchdogCmd(ADC3, ADC_AnalogWatchdog_SingleRegEnable);

    /* 使能模拟看门狗中断 */
    ADC_ITConfig(ADC3, ADC_IT_AWD, ENABLE);
    
	/* 使能DMA请求 (多ADC模式) --------------------------------------------------*/
	ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE);

	/* Enable ADC1 --------------------------------------------------------------*/
	ADC_Cmd(ADC3, ENABLE);

	/////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////
	
    /*ADC2的配置*****************************************************************/
    ADC_InitStructure.ADC_Resolution = ADC_Resolution_10b;
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
	ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC2;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_InitStructure.ADC_NbrOfConversion = 1;
    
    /* ADC2 规则通道配置 */
	ADC_Init(ADC2, &ADC_InitStructure);
	ADC_RegularChannelConfig(ADC2, ADC_Channel_10, 1, ADC_SampleTime_3Cycles);

    /* 使能 ADC2 DMA */
	ADC_DMACmd(ADC2, ENABLE);
    
	/* 使能DMA请求 (多ADC模式) */
	ADC_DMARequestAfterLastTransferCmd(ADC2, ENABLE);

	/* 使能 ADC2 */
	ADC_Cmd(ADC2, ENABLE);
	
	/////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////
	
	/*ADC1的配置******************************************************************/
    ADC_InitStructure.ADC_Resolution = ADC_Resolution_10b;
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
	ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_InitStructure.ADC_NbrOfConversion = 1;
    
    /* ADC1 规则通道配置 -------------------------------------------------------*/
	ADC_Init(ADC1, &ADC_InitStructure);
	ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_3Cycles);

    /* 使能 ADC1 DMA */
	ADC_DMACmd(ADC1, ENABLE);
	
	/* 使能DMA请求 (多ADC模式) --------------------------------------------------*/
	ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);

	/* Enable ADC1 --------------------------------------------------------------*/
	ADC_Cmd(ADC1, ENABLE);

	/**定时器配置********************************************************************/
	TIM1_Config();
}
コード例 #12
0
ファイル: main.c プロジェクト: MbedTinkerer/uart_dma
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to 
       application main. 
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */

  /* USART configuration -----------------------------------------------------*/
  USART_Config();
    
  /* SysTick configuration ---------------------------------------------------*/
  SysTickConfig();
  
  /* LEDs configuration ------------------------------------------------------*/
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED5);
  STM_EVAL_LEDInit(LED6);
  
  STM_EVAL_LEDOn(LED3);//orange
  STM_EVAL_LEDOn(LED4);//verte
  STM_EVAL_LEDOn(LED5);//rouge
  STM_EVAL_LEDOn(LED6);//bleue
  
  //PWM config (motor control)
  TIM1_Config();
  PWM1_Config(10000);
  
  /* Tamper Button Configuration ---------------------------------------------*/
  STM_EVAL_PBInit(BUTTON_USER,BUTTON_MODE_GPIO);
    
  //Set motor speed
  PWM_SetDC(1, SPEED_100); //PE9 | PC6//ON 2ms
  PWM_SetDC(2, SPEED_100); //PE11 | PC 7
  PWM_SetDC(3, SPEED_100); //PE13
  PWM_SetDC(4, SPEED_100); //PE14

  //  /* Wait until Tamper Button is released */
  while (STM_EVAL_PBGetState(BUTTON_USER));  
  
  PWM_SetDC(1, SPEED_0); //PE9 | PC6//ON 2ms
  PWM_SetDC(2, SPEED_0); //PE11 | PC 7
  PWM_SetDC(3, SPEED_0); //PE13
  PWM_SetDC(4, SPEED_0); //PE14

  /* Initialization of the accelerometer -------------------------------------*/
  MPU6050_I2C_Init();
  MPU6050_Initialize();

  if (MPU6050_TestConnection()) {
		// connection success
		STM_EVAL_LEDOff(LED3);
  }else{
                STM_EVAL_LEDOff(LED4);
  }

  //Calibration process
  //  Use the following global variables and access functions
  //  to calibrate the acceleration sensor
  calibrate_sensors();

  zeroError();
  
  //Ready to receive message
  /* Enable DMA USART RX Stream */
  DMA_Cmd(USARTx_RX_DMA_STREAM,ENABLE);
  /* Enable USART DMA RX Requsts */
  USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE);
  
  while(1){
    //--------------------------------------------------------
    //------ Used to configure the speed controller ----------
    //--------------------------------------------------------
    
    // press blue button to force motor at SPEED_100
    if (STM_EVAL_PBGetState(BUTTON_USER)){
      PWM_SetDC(1, SPEED_100); //PE9 | PC6//ON 2ms
      PWM_SetDC(2, SPEED_100); //PE11 | PC 7
      PWM_SetDC(3, SPEED_100); //PE13
      PWM_SetDC(4, SPEED_100); //PE14
      
      //  /* Wait until Tamper Button is released */
      while (STM_EVAL_PBGetState(BUTTON_USER));  
      
      PWM_SetDC(1, SPEED_0); //PE9 | PC6//ON 2ms
      PWM_SetDC(2, SPEED_0); //PE11 | PC 7
      PWM_SetDC(3, SPEED_0); //PE13
      PWM_SetDC(4, SPEED_0); //PE14
      
      Delay(100);
    }
    
    //--------------------------------------------------------
    //------ Get gyro information                   ----------
    //--------------------------------------------------------
    
    // Read the raw values.
    MPU6050_GetRawAccelGyro(AccelGyro);

    // Get the time of reading for rotation computations
    unsigned long t_now = millis();
    STM_EVAL_LEDToggle(LED5);
    // The temperature sensor is -40 to +85 degrees Celsius.
    // It is a signed integer.
    // According to the datasheet:
    //   340 per degrees Celsius, -512 at 35 degrees.
    // At 0 degrees: -512 – (340 * 35) = -12412
    //dT = ( (double) AccelGyro[TEMP] + 12412.0) / 340.0;

    // Convert gyro values to degrees/sec
    gyro_x = (AccelGyro[GYRO_X] - base_x_gyro) / FSSEL;
    gyro_y = (AccelGyro[GYRO_Y] - base_y_gyro) / FSSEL;
    gyro_z = (AccelGyro[GYRO_Z] - base_z_gyro) / FSSEL;

    // Get raw acceleration values
    accel_x = AccelGyro[ACC_X];
    accel_y = AccelGyro[ACC_Y];
    accel_z = AccelGyro[ACC_Z];

    // Get angle values from accelerometer
    //float accel_vector_length = sqrt(pow(accel_x,2) + pow(accel_y,2) + pow(accel_z,2));
    float accel_angle_y = atan(-1*accel_x/sqrt(pow(accel_y,2) + pow(accel_z,2)))*RADIANS2DEGREES;
    float accel_angle_x = atan(accel_y/sqrt(pow(accel_x,2) + pow(accel_z,2)))*RADIANS2DEGREES;

    //float accel_angle_z = 0;

    //// Compute the (filtered) gyro angles
    //Get the value in second, a tick is every 10ms
    dt = (t_now - last_read_time)/100.0;
    float gyro_angle_x = gyro_x*dt + lastAngle[X];//get_last_x_angle();
    float gyro_angle_y = gyro_y*dt + lastAngle[Y];//(get_last_y_angle();
    float gyro_angle_z = gyro_z*dt + lastAngle[Z];//get_last_z_angle();

    // Compute the drifting gyro angles
    float unfiltered_gyro_angle_x = gyro_x*dt + lastGyroAngle[X];//get_last_gyro_x_angle();
    float unfiltered_gyro_angle_y = gyro_y*dt + lastGyroAngle[Y];//get_last_gyro_y_angle();
    float unfiltered_gyro_angle_z = gyro_z*dt + lastGyroAngle[Z];//get_last_gyro_z_angle();

    // Apply the complementary filter to figure out the change in angle – choice of alpha is
    // estimated now.  Alpha depends on the sampling rate…
    float alpha = 0.96;
    angle_x = alpha * gyro_angle_x + (1.0 - alpha) * accel_angle_x;
    angle_y = alpha * gyro_angle_y + (1.0 - alpha) * accel_angle_y;
    angle_z = gyro_angle_z;  //Accelerometer doesn’t give z-angle

    //printf("%4.2f %4.2f %4.2f\r\n",angle_x,angle_y,angle_z);

    //// Update the saved data with the latest values
    set_last_read_angle_data(t_now, angle_x, angle_y, angle_z, unfiltered_gyro_angle_x, unfiltered_gyro_angle_y, unfiltered_gyro_angle_z);

   //Stabilisation
   // Stable Mode
    angl = getAngleFromRC(rcBluetooth[ROLL]);
    levelRoll = (getAngleFromRC(rcBluetooth[ROLL]) - angle_x) * PID[LEVELROLL].P;
    levelPitch = (getAngleFromRC(rcBluetooth[PITCH]) - angle_y) * PID[LEVELPITCH].P;
    // Check if pilot commands are not in hover, don't auto trim
//    if ((abs(receiver.getTrimData(ROLL)) > levelOff) || (abs(receiver.getTrimData(PITCH)) > levelOff)) {
//      zeroIntegralError();
//    }
//    else {
      PID[LEVELROLL].integratedError = constrain(PID[LEVELROLL].integratedError + (((getAngleFromRC(rcBluetooth[ROLL]) - angle_x) * dt) * PID[LEVELROLL].I), -LEVEL_LIMIT, LEVEL_LIMIT);
      PID[LEVELPITCH].integratedError = constrain(PID[LEVELPITCH].integratedError + (((getAngleFromRC(rcBluetooth[PITCH]) + angle_y) * dt) * PID[LEVELROLL].I), -LEVEL_LIMIT, LEVEL_LIMIT);
//    }
    //motors.setMotorAxisCommand(ROLL,
    motor[ROLL] = updatePID(rcBluetooth[ROLL] + levelRoll, gyro_x + 1500, &PID[LEVELGYROROLL],dt) + PID[LEVELROLL].integratedError;//);
    //motors.setMotorAxisCommand(PITCH,
    motor[PITCH] = updatePID(rcBluetooth[PITCH] + levelPitch, gyro_y + 1500, &PID[LEVELGYROPITCH],dt) + PID[LEVELPITCH].integratedError;//);
   
    getLastSpeedFromMsg(); 
    
    PWM_SetDC(1, SPEED_0 + SPEED_RANGE*rcSpeed[1] + motor[ROLL] *0.10f); //PE9 | PC6//ON 2ms
  
        //Send data on UART
    *(float*)(aTxBuffer) = angle_x;
    *(float*)(aTxBuffer+4) = angle_y;
    *(float*)(aTxBuffer+8) = angle_z;
    *(float*)(aTxBuffer+12) = motor[ROLL];
    *(float*)(aTxBuffer+16) =  motor[PITCH];
   sendTxDMA((uint32_t)aTxBuffer,20);
   
   //Wait a little bit
   Delay(3); //30 ms
   
  }
}
コード例 #13
0
/********************************************************************//**
* @brief		Initializes the TIMx peripheral according to the specified
*               parameters.
* @param[in]	TIMx	Timer peripheral selected, should be:
*   			- LPC_TIM0: TIMER0 peripheral
* 				- LPC_TIM1: TIMER1 peripheral
* 				- LPC_TIM2: TIMER2 peripheral
* 				- LPC_TIM3: TIMER3 peripheral
* @param[in]	IntFlag: interrupt type, should be:
* 				- None   : No Pin Configuration
* 				- TIM_MR0: Configure for Ext Match channel 0
* 				- TIM_MR1: Configure for Ext Match channel 1
* 				- TIM_MR2: Configure for Ext Match channel 2 for only Timer2
* 				- TIM_MR3: Configure for Ext Match channel 3 for only Timer2
* 				- TIM_CR0: Configure for Capture channel 0
* 				- TIM_CR1: Configure for Capture channel 1
* @return 		None
*********************************************************************/
void TIM_Config(LPC_TIM_TypeDef *TIMx, TIM_PCFG_TYPE PCfg)
{
	// Pin configuration for TIM
	PINSEL_CFG_Type PinCfg;

	if (TIMx == LPC_TIM0)
	{
		switch (PCfg)
		{
		 case TIM_MR1:
			 // Configure P3.26 as MAT0.1
			 PinCfg.Funcnum = 2;
			 PinCfg.OpenDrain = 0;
			 PinCfg.Pinmode = 0;
			 PinCfg.Portnum = 3;
			 PinCfg.Pinnum = 26;
			 PINSEL_ConfigPin(&PinCfg);
			 break;

		 case None:
			 break;

		 default:
		 		//Error match value
		 		//Error loop
		 		while(1);
		}

		// Pin Configuration
		TIM0_Config();    // Timer0 Configuration
	}
	else if (TIMx == LPC_TIM1)
	{
		switch (PCfg)
		{
		 case TIM_MR0:
			 // Configure P1.22 as MAT1.0
			 PinCfg.Funcnum = 3;
			 PinCfg.OpenDrain = 0;
			 PinCfg.Pinmode = 0;
			 PinCfg.Portnum = 1;
			 PinCfg.Pinnum = 22;
			 PINSEL_ConfigPin(&PinCfg);
			 break;

		 case TIM_MR1:
			 // Configure P1.25 as MAT1.1
			 PinCfg.Funcnum = 3;
			 PinCfg.OpenDrain = 0;
			 PinCfg.Pinmode = 0;
			 PinCfg.Portnum = 1;
			 PinCfg.Pinnum = 25;
			 PINSEL_ConfigPin(&PinCfg);
			 break;

		 case TIM_CR0:
			 // Configure P1.18 as CAP1.0
			 PinCfg.Funcnum = 3;
			 PinCfg.OpenDrain = 0;
			 PinCfg.Pinmode = 0;
			 PinCfg.Portnum = 1;
			 PinCfg.Pinnum = 18;
			 PINSEL_ConfigPin(&PinCfg);
			 break;

		 case TIM_CR1:
			 // Configure P1.19 as CAP1.1
			 PinCfg.Funcnum = 3;
			 PinCfg.OpenDrain = 0;
			 PinCfg.Pinmode = 0;
			 PinCfg.Portnum = 1;
			 PinCfg.Pinnum = 19;
			 PINSEL_ConfigPin(&PinCfg);
			 break;

		 case None:
			 break;

		 default:
		 		//Error match value
		 		//Error loop
		 		while(1);
		}

		TIM1_Config();   // Timer1 Configuration
	}
	else if (TIMx == LPC_TIM2)
	{
		switch (PCfg)
		{
		 case TIM_MR0:
			 // Configure P4.28 as MAT2.0
			 PinCfg.Funcnum = 2;
			 PinCfg.OpenDrain = 0;
			 PinCfg.Pinmode = 0;
			 PinCfg.Portnum = 4;
			 PinCfg.Pinnum = 28;
			 PINSEL_ConfigPin(&PinCfg);
			 break;

		 case None:
			 break;

		 default:
		 		//Error match value
		 		//Error loop
		 		while(1);
		}

		// Pin Configuration
		TIM2_Config();    // Timer2 Configuration
	}
	else if (TIMx == LPC_TIM3)
	{
		switch (PCfg)
		{
		 case TIM_MR0:
			 // Configure P0.10 as MAT3.0
			 PinCfg.Funcnum = 3;
			 PinCfg.OpenDrain = 0;
			 PinCfg.Pinmode = 0;
			 PinCfg.Portnum = 0;
			 PinCfg.Pinnum = 10;
			 PINSEL_ConfigPin(&PinCfg);
			 break;

		 case TIM_MR1:
			 // Configure P0.11 as MAT3.1
			 PinCfg.Funcnum = 3;
			 PinCfg.OpenDrain = 0;
			 PinCfg.Pinmode = 0;
			 PinCfg.Portnum = 0;
			 PinCfg.Pinnum = 11;
			 PINSEL_ConfigPin(&PinCfg);
			 break;

		 case None:
			 break;

		 default:
		 		//Error match value
		 		//Error loop
		 		while(1);
		}

		// Pin Configuration
		TIM3_Config();    // Timer3 Configuration
	}
}