/**
  * @brief  Initializes the temperature sensor and its related ADC.
  * @param  None
  * @retval the float value of temperature measured in Celsius.
  */
float temperature_MeasureValue(void)
{	
	/* Raw value of temperature sensor voltage converted from ADC1_IN16 */
	uint16_t v_refint;
	/* Raw value of VREFINT converted from ADC1_INT17 */
	uint16_t v_sensor;
	
	/* select ADC1_IN16 to sample sensor voltage value*/
	ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_28Cycles);
	/* start one ADC conversion */
	ADC_SoftwareStartConv(ADC1);
	/*  wait unitl ECO bit is set, sample finished */
	while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
	ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
	/* Read the value from ADC_DR*/
	v_sensor = ADC_GetConversionValue(ADC1);

	/* select ADC1_IN16 to sample reference voltage value*/
	ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 1, ADC_SampleTime_28Cycles);
	/* start one ADC conversion */
	ADC_SoftwareStartConv(ADC1);
	/*  wait unitl ECO bit is set, sample finished */
	while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
	ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
	/* Read the value from ADC_DR*/
	v_refint = ADC_GetConversionValue(ADC1);

  /*
	 * measured_sensor_voltage = actual_reference_voltage * sampled_sensor_voltage / sampled_reference_voltage_value
	 * temperature = (measured_sensor_voltage - sensor_voltage_at_25) / AVG_SLOPE + 25
	 */
	return (VREFINT_VOLTAGE_V / v_refint * v_sensor - TEMPERATURE_V25) * 1000 / AVG_SLOPE + 25;
}
コード例 #2
0
ファイル: mclib_enter_API.c プロジェクト: tangb765/FredFoc
/*******************************************************************************
* Function Name  : ADC1_2_IRQHandler
* Description    : This function handles ADC1 and ADC2 global interrupts requests.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_IRQHandler(void)
{
  if((ADC1->SR & ADC_FLAG_JEOC) == ADC_FLAG_JEOC)
  {
    //It clear JEOC flag
    ADC1->SR &= ~(rt_uint32_t)(ADC_FLAG_JEOC | ADC_FLAG_JSTRT);
    MCLIB_Mesure_Structure.Mec_Angle = GET_MECHANICAL_ANGLE;
//    if (SVPWMEOCEvent())
		if (State != IDLE)
    {   
//      MCL_Calc_BusVolt();
			
      switch (State)
      {
          case RUN:          
            FOC_Model();       
          break;       
    
          case START: 
						ENC_Start_Up();	
          break; 
    
          default:
          break;
      }
			
      #ifdef BRAKE_RESISTOR
        if((wGlobal_Flags & BRAKE_ON) == BRAKE_ON)
        {
          rt_uint16_t aux;
					
          aux = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_2);
        
          if (aux < BRAKE_HYSTERESIS)
          {
           wGlobal_Flags &= ~BRAKE_ON;
           MCL_Set_Brake_Off();
          }
        }
      #endif      
    }
  }
  else 
  {  
    if(ADC_GetITStatus(ADC1, ADC_IT_AWD) == SET)
    {
#ifdef BRAKE_RESISTOR
      //Analog watchdog interrupt has been generated 
     MCL_Set_Brake_On(); 
     wGlobal_Flags |= BRAKE_ON;
#else
     if(MCL_Chk_BusVolt()==OVER_VOLT)  // ·ÀÖ¹¸ÉÈÅ
        MCL_SetFault(OVER_VOLTAGE);
#endif

     ADC_ClearFlag(ADC1, ADC_FLAG_AWD);
    }    
  }
	
}
コード例 #3
0
ファイル: temp_tool.c プロジェクト: claus147/MicroP17
void getVoltage () {

		ADC_SoftwareStartConv(ADC1); 								//Starting Conversion, waiting for it to finish, clearing the flag, reading the result
		while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); 		//Could be through interrupts (Later)
		ADC_ClearFlag (ADC1, ADC_FLAG_EOC); 						//EOC means End Of Conversion
		ADC_GetConversionValue(ADC1); 								// Result available in ADC1->DR
}
コード例 #4
0
ファイル: task_measure.c プロジェクト: pabe/pins-oscilloscope
/*
 * NOTE: No protection, should only be called from ISR
 */
static uint16_t read_channel(oscilloscope_input_t ch)
{
  uint8_t real_ch;
  switch(ch)
  {
    case input_channel0:
      real_ch = ADC_Channel_7;
      break;

    case input_channel1:
      real_ch = ADC_Channel_8;
      break;

    default:
      ipc_watchdog_signal_error(0);
      return UINT16_MAX;
  }
  
  ADC_RegularChannelConfig(ADC1, real_ch, 1, ADC_SampleTime_239Cycles5);
  ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

  /* spin until we have data */
  while (!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));			

  return ADC_GetConversionValue(ADC1);
}	
コード例 #5
0
ファイル: ADC.c プロジェクト: cmtm/microP
// fill this in
float getTemp_celcius() {
	ADC_SoftwareStartConv(ADC1);
	while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
	ADC_ClearFlag(ADC1, ADC_FLAG_EOC);

	return ((ADC1->DR * 3000.0/4096.0) - 760)/2.5 + 25;
}
コード例 #6
0
ファイル: IOSTM.cpp プロジェクト: g4klx/MMDVM
void CIO::interrupt()
{
  uint8_t control  = MARK_NONE;
  uint16_t sample  = DC_OFFSET;
  uint16_t rawRSSI = 0U;

  m_txBuffer.get(sample, control);

  // Send the value to the DAC
  DAC_SetChannel1Data(DAC_Align_12b_R, sample);

  // Read value from ADC1 and ADC2
  if ((ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET)) {
    // shouldn't be still in reset at this point so null the sample value?
    sample  = 0U;
  } else {
    sample  = ADC_GetConversionValue(ADC1);
#if defined(SEND_RSSI_DATA)
    rawRSSI = ADC_GetConversionValue(ADC2);
#endif
  }

  // trigger next ADC1
  ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
  ADC_SoftwareStartConv(ADC1);

  m_rxBuffer.put(sample, control);
  m_rssiBuffer.put(rawRSSI);

  m_watchdog++;
}
コード例 #7
0
ファイル: ADC_metoder.c プロジェクト: sivertism/usb_can_v02
/**
 * @brief  	A interrupt request is generated when ADC4 is done converting a sample.
 * 			The ADC is triggered by TIM2. Saves the voltage in mV in ADC4_conv_val.
 * @param  	None
 * @retval 	None
 */
void ADC4_IRQHandler(void){
	ADC_buffer[6] = (30000*ADC_GetConversionValue(ADC4))/4096;
	/* Indicate to the main-loop that there is a new measurement available.*/
	new_values |= (1u << 4);
	GPIOE->ODR ^= (STATUS_LED7 << 8);
	/* Reset ADC_FLAG_EOC to clear the interrupt request.*/
	ADC_ClearFlag(ADC4, ADC_FLAG_EOC);
} // end ADC3_IRQHandler()
コード例 #8
0
ファイル: adc.c プロジェクト: Apo11oH/micromouse_2014
int getSensorValue()
{
	int temp;
	while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)){}
	temp = ADC_GetConversionValue(ADC1);
	ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
	return temp;
}
コード例 #9
0
/*******************************************************************************
* Function Name  : SVPWMUpdateEvent
* Description    :  Routine to be performed inside the update event ISR  it reenable 
           the ext adc.trigger in 。It must be assigned to pSVPWM_UpdateEvent pointer.	
* Input           : None
* Output         : None
* Return         : None
*******************************************************************************/
void SVPWMUpdateEvent(void)
{
	// ReEnable EXT. ADC Triggering
	ADC1->CR2 |= 0x00008000;

	// Clear unwanted current sampling
	ADC_ClearFlag(ADC1, ADC_FLAG_JEOC);
}
コード例 #10
0
ファイル: 91x_it.c プロジェクト: LupusDei/8LU-DSP
/*******************************************************************************
* Function Name  : ADC_IRQHandler
* Description    : This function handles the ADC interrupt request
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_IRQHandler(void)
{
  /* Clear the end of conversion flag */
  ADC_ClearFlag(ADC_FLAG_ECV);

  /* Set the new pulse of the TIM0 with the converted value */
  TIM_SetPulse(TIM0, TIM_PWM_OC1_Channel, ADC_GetConversionValue(ADC_Channel_5));
}
コード例 #11
0
ファイル: Battery.cpp プロジェクト: taniho0707/nucleo_mouse
void Battery::rescanVoltage(){
	int tmp = 0;
	ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
	ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_112Cycles);
	ADC_SoftwareStartConv(ADC1);
	while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
	tmp = ADC_GetConversionValue(ADC1);
	voltage = (15.1 * tmp / 5.1) * (3.3 / 4095);
}
コード例 #12
0
/**
 * @brief Change thresholds for light sensor readings
 *
 * This function reconfigures the analog watchdog thresholds.
 */
void setAdcThresholds(uint32_t high, uint32_t low){

        ADC_AnalogWatchdogThresholdsConfig(ADC1, high, low);
        ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_10);
        ADC_ClearFlag(ADC1, ADC_FLAG_AWD);
        ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);
	ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);

}
コード例 #13
0
ファイル: adc.c プロジェクト: Laurenceb/STM32-Logger
/**
* @brief This function gets a conversion from ADC2 (non blocking)
* @param None
* @retval Read value (-1 means adc not ready)
*/
uint16_t getADC2(void)
{
  // Make sure we have conversion completion
  if(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET)
    return -1;
  // Reset the flag
  ADC_ClearFlag(ADC2, ADC_FLAG_EOC);
  // Get the conversion value
  return ADC_GetConversionValue(ADC2);
}
コード例 #14
0
ファイル: ADC_metoder.c プロジェクト: sivertism/usb_can_v02
/**
 * @brief  	A interrupt request is generated when ADC1 is done converting a sample.
 * 			The ADC is triggered TIM2. Saves the voltage in mV in a buffer indexed by
 * 			the channels position in the sequencer.
 * @param  	None
 * @retval 	None
 */
void ADC1_2_IRQHandler(void){
	if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)){
		GPIOF->ODR = GPIO_Pin_2;
		ADC_buffer[channel_counter] = (30000*ADC_GetConversionValue(ADC1))/4096;
		/* Indicate to the main-loop that there is a new measurement available.*/
		new_values |= (1u << channel_counter);
		GPIOE->ODR ^= (STATUS_LED6 << 8);
		/* Increment the channel counter */
		channel_counter++;
		if (channel_counter>3) channel_counter = 0;
		ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
		GPIOF->ODR = 0;
	}
	if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOS)){
		GPIOE->ODR ^= (UART_TX_LED << 8);
		ADC_ClearFlag(ADC1, ADC_FLAG_EOS);
	}
	/* Reset ADC_FLAG_EOC to clear the interrupt request.*/
} // end ADC3_IRQHandler()
コード例 #15
0
void SVPWM_3ShuntCurrentReadingCalibration(void)
{
	static u16 bIndex;

	/* ADC1 Injected group of conversions end interrupt disabling */
	ADC_ITConfig(ADC1, ADC_IT_JEOC, DISABLE);

	hPhaseAOffset=0;
	hPhaseBOffset=0;
	hPhaseCOffset=0;

	/* ADC1 Injected conversions trigger is given by software and enabled */ 
	ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);  
	ADC_ExternalTrigInjectedConvCmd(ADC1,ENABLE); 

	/* ADC1 Injected conversions configuration */ 
	ADC_InjectedSequencerLengthConfig(ADC1,3);
	ADC_InjectedChannelConfig(ADC1, PHASE_A_ADC_CHANNEL,1,SAMPLING_TIME_CK);
	ADC_InjectedChannelConfig(ADC1, PHASE_B_ADC_CHANNEL,2,SAMPLING_TIME_CK);
	ADC_InjectedChannelConfig(ADC1, PHASE_C_ADC_CHANNEL,3,SAMPLING_TIME_CK);

	/* Clear the ADC1 JEOC pending flag */
	ADC_ClearFlag(ADC1, ADC_FLAG_JEOC);  
	ADC_SoftwareStartInjectedConvCmd(ADC1,ENABLE);

	/* ADC Channel used for current reading are read 
	 in order to get zero currents ADC values*/ 
	for(bIndex=0; bIndex <NB_CONVERSIONS; bIndex++)
	{
		while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_JEOC)) { }

		hPhaseAOffset += (ADC_GetInjectedConversionValue(ADC1,ADC_InjectedChannel_1)>>3);
		hPhaseBOffset += (ADC_GetInjectedConversionValue(ADC1,ADC_InjectedChannel_2)>>3);
		hPhaseCOffset += (ADC_GetInjectedConversionValue(ADC1,ADC_InjectedChannel_3)>>3);    
		/* Clear the ADC1 JEOC pending flag */
		ADC_ClearFlag(ADC1, ADC_FLAG_JEOC);    
		ADC_SoftwareStartInjectedConvCmd(ADC1,ENABLE);
	}
	
	SVPWM_InjectedConvConfig( );  
}
コード例 #16
0
ファイル: Touch_Driver.c プロジェクト: RTOS-Developers/TRTOS
/**************************************************************************************
 Func: ADC中断函数
 Time: 2014-6-18
 Ver.: V1.0
 Note;
**************************************************************************************/
void ADC1_2_IRQHandler(void) //模拟狗相关
{
	ADC_ITConfig(ADC1,ADC_IT_AWD,DISABLE);
	if(SET == ADC_GetFlagStatus(ADC1,ADC_FLAG_AWD))
	{
		ADC_ClearFlag(ADC1,ADC_FLAG_AWD);
		ADC_ClearITPendingBit(ADC1,ADC_IT_AWD);
		if(Tos_TaskGetState(TOUCH_Tos_TaskID)==_TTS_Stop)Tos_TaskRecover(TOUCH_Tos_TaskID);
	else Tos_TaskTimeout(TOUCH_Tos_TaskID,10);//防止在任务没有挂起就发生dma发送中断了
	}
	
}
コード例 #17
0
ファイル: adc.c プロジェクト: Laurenceb/STM32-Logger
/**
* @brief This function returns a conversion from ADC2 (blocking)
* @param Channel number to convert
* @retval unsigned 16 bit integer - adc is 12bit
*/
uint16_t readADC2(uint8_t channel)
{
  ADC_RegularChannelConfig(ADC2, channel, 1, ADC_SampleTime_239Cycles5);
  // Start the conversion
  ADC_SoftwareStartConvCmd(ADC2, ENABLE);
  // Wait until conversion completion
  while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET);
  // Reset the flag
  ADC_ClearFlag(ADC2, ADC_FLAG_EOC);
  // Get the conversion value
  return ADC_GetConversionValue(ADC2);
}
コード例 #18
0
ファイル: ana_inputs.c プロジェクト: cansonlee/rc_controller
void ana_inputs_adc_dma_irq_handler_callback(void)	
{
	uint16_t adc_buf[ADC_MODULE_NUMBER];

	if(DMA_GetITStatus(SKYBORNE_ADC_DMA_STREAM, SKYBORNE_ADC_DMA_TC_FLAG) != RESET)
	{
		DMA_Cmd(SKYBORNE_ADC_DMA_STREAM,DISABLE);
		DMA_ClearITPendingBit(SKYBORNE_ADC_DMA_STREAM, SKYBORNE_ADC_DMA_TC_FLAG);
		ADC_ClearFlag(SKYBORNE_ADC, ADC_FLAG_EOC | ADC_FLAG_STRT | ADC_FLAG_OVR);	
		
		ana_inputs_adc_dma_irq_handler_cb_hook(g_adcs_value, ADC_MODULE_NUMBER);					
	}
}
コード例 #19
0
ファイル: adc.cpp プロジェクト: NikeKhin/stm32vldiscovery
/**
    @brief Reads conversion value.
    @returns The value
*/
uint16_t Analog::read()
{
    uint16_t value;
    //start the ADC Software Conversion
    ADC_SoftwareStartConvCmd(_base, ENABLE);
    //wait for conversion complete
    while(!ADC_GetFlagStatus(_base, ADC_FLAG_EOC)){}
    //read ADC value
    value=ADC_GetConversionValue(_base);
    //clear EOC flag
    ADC_ClearFlag(_base, ADC_FLAG_EOC);
    //return the result
    return value;
}
コード例 #20
0
ファイル: ana_inputs.c プロジェクト: cansonlee/rc_controller
/***************************************************************************************************
* @fn 	 ana_inputs_sample_start
*
* @brief   Ò¡¸Ë¡¢²¦ÂÖ¼°µçѹ¼à²â²ÉÑù¿ªÊ¼
* @param   NULL
* @return  NULL
***************************************************************************************************/
void ana_inputs_sample_start(void)
{
	DMA_Cmd(SKYBORNE_ADC_DMA_STREAM,DISABLE);
	ADC_ClearFlag(SKYBORNE_ADC, ADC_FLAG_EOC | ADC_FLAG_STRT | ADC_FLAG_OVR);
	DMA_ClearITPendingBit(SKYBORNE_ADC_DMA_STREAM, SKYBORNE_ADC_DMA_TC_FLAG);

	DMA_SetCurrDataCounter(SKYBORNE_ADC_DMA_STREAM, ADC_MODULE_NUMBER);
	ADC_DMARequestAfterLastTransferCmd(SKYBORNE_ADC, ENABLE);
	ADC_DMACmd(SKYBORNE_ADC, ENABLE);
	DMA_ITConfig(SKYBORNE_ADC_DMA_STREAM, DMA_IT_TC, ENABLE);	
	
	DMA_Cmd(SKYBORNE_ADC_DMA_STREAM, ENABLE);
	ADC_SoftwareStartConv(SKYBORNE_ADC);
}
コード例 #21
0
ファイル: key.c プロジェクト: ajugurikang/cortex_class_ref
void ADC3_IRQHandler(void)
{
	uint32_t ADCValue;
	KEY_CODE Key;

	ADC_ClearFlag(ADC3, ADC_FLAG_JSTRT | ADC_FLAG_JEOC);	// Flag를 초기화 한다.
	ADCValue = ADC3->JDR1;								 	// ADC 값을 읽는다. 
	Key = Key_FindKeyCode((uint16_t)ADCValue);				// 키 값을 찾는다 
	/* 콜백 함수를 호출한다 */
	if(KeyHandle != (void *)0)
	{
		KeyHandle(Key);
	}
}
コード例 #22
0
void enable_ADC_watchdog(uint16_t low, uint16_t high)
{
    ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_0);
    ADC_AnalogWatchdogThresholdsConfig(ADC1, high, low);
    ADC_ClearFlag(ADC1, ADC_FLAG_AWD);
    ADC_ClearITPendingBit(ADC1, ADC_IT_AWD);
    ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);
    ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);

    NVIC_InitTypeDef NVIC_InitStructure = {0};
    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);
}
コード例 #23
0
ファイル: adc.c プロジェクト: Paolo-Maffei/webled-node
void ADC_GetValue(char *ret)
{
  /* Start ADC1 Software Conversion */ 
  unsigned char i = 0;
  for(i=0;i<4;i++)
  {
    uint16_t adc_tmp = 0;
    ADC_RegularChannelConfig(ADC1, ADC_Channel_10+i, 1, ADC_SampleTime_13Cycles5);
    ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
    ADC_SoftwareStartConvCmd(ADC1, ENABLE);    
    while(SET != ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
    adc_tmp = ADC_GetConversionValue(ADC1);
    *(ret+2*i) = (char)adc_tmp;
    *(ret+2*i+1) = (char)(adc_tmp>>8);
  }
}
コード例 #24
0
/**
 * @brief Set up analog input and ADC to read values from light sensor
 *
 * This function configures GPIO PC0 as an analog input connected to an 
 * ADC. It also enables an analog watchdog interrupt that fires each time the 
 * digital value is less then LIGHT_THRESHOLD_LOW or higher than LIGHT_THRESHOLD_HIGH.
 * 
 * (LIGHT_THRESHOLD_LOW and LIGHT_THRESHOLD_HIGH are defined in lightsensor.h)
 * 
 * You must define an interrupt handler (ADC_IRQHandler) to handle
 * these interrupts.
 */
void initAdc() {
	GPIO_InitTypeDef GPIO_initStructre; 
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);

	RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOCEN,ENABLE); 

	GPIO_initStructre.GPIO_Pin = GPIO_Pin_0;
	GPIO_initStructre.GPIO_Mode = GPIO_Mode_AN;
	GPIO_initStructre.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOC,&GPIO_initStructre);
	
	/* Common ADC Initialization           */
	ADC_CommonInitTypeDef adc_common;
	ADC_CommonStructInit(&adc_common);
	adc_common.ADC_Prescaler = ADC_Prescaler_Div8; 
	ADC_CommonInit(&adc_common);

	/* ADC Initialization           */
	ADC_InitTypeDef adc;
	ADC_StructInit(&adc);  
	adc.ADC_Resolution = ADC_Resolution_12b;
        adc.ADC_ContinuousConvMode = ENABLE; 

	ADC_Init(ADC1, &adc);

	ADC_Cmd(ADC1,ENABLE);
	ADC_RegularChannelConfig(ADC1,ADC_Channel_10,1,ADC_SampleTime_480Cycles);

	/* Use an analog watchdog to trigger interrupt on given thresholds      */
        ADC_AnalogWatchdogThresholdsConfig(ADC1, LIGHT_THRESHOLD_HIGH, LIGHT_THRESHOLD_LOW);
        ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_10);
        ADC_ClearFlag(ADC1, ADC_FLAG_AWD);
        ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);
	ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);

	NVIC_InitTypeDef NVIC_InitStructure;

	/* Configure and enable ADC interrupt */
	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);

	ADC_SoftwareStartConv(ADC1);
}
コード例 #25
0
float fdi_adc_convert(uint32_t channel) {
    const int conversions = 32;
    uint32_t value = 0;
    for (int i = 0; i < conversions; ++i) {
        ADC_ClearFlag(ADC1, ADC_FLAG_OVR | ADC_FLAG_EOC);
        ADC_RegularChannelConfig(ADC1, channel, 1, ADC_SampleTime_480Cycles);
        fdi_delay_us(10);
        do {
            ADC_SoftwareStartConv(ADC1);
            if (ADC_GetFlagStatus(ADC1, ADC_FLAG_OVR)) {
                ADC1->SR &= ~ADC_FLAG_OVR;
            }
        } while (!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));

        value += ADC_GetConversionValue(ADC1);
    }
    return value * 3.3f / 4096.0f / conversions;
}
コード例 #26
0
ファイル: adc.c プロジェクト: turboman1234/TankController
//Get ADCx Value
u16 GetADCValue(ADC_TypeDef* ADCx, int channel)
{
    u16 res;
    
    //set chanelXX from ADCx with wanted sample time
    //ADC sample time = (1 / APB2frequency ) * ADCcyclesCount;
    ADC_RegularChannelConfig(ADCx, channel, 1, ADC_SampleTime_56Cycles);
    
    ADC_Cmd(ADCx, ENABLE);
    ADC_SoftwareStartConv(ADCx);
    
    while (ADC_GetFlagStatus(ADCx, ADC_FLAG_EOC) != SET);
    
    ADC_ClearFlag(ADCx, ADC_FLAG_EOC);
    
    res = ADC_GetConversionValue(ADCx);
    
    ADC_Cmd(ADCx, DISABLE);
    
    return res;
}
コード例 #27
0
ファイル: adc.c プロジェクト: tarasii/BMP085
uint16_t adc_coretemp_simple(void)
{
	ADC_InitTypeDef ADC_InitStructure;
	
	uint16_t AD_value;
	uint16_t TemperatureC;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);		//enable ADC1 clock
	
	//ADC1 configuration
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;						//convert single channel only
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; 		//convert one time
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None; //select no external triggering
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; 	//right 12-bit data alignment in ADC data register
	ADC_InitStructure.ADC_NbrOfConversion = 1; 							//single channel conversion	
	ADC_Init(ADC1, &ADC_InitStructure); 							//load structure values to control and status registers
	
	ADC_TempSensorVrefintCmd(ENABLE); 								//wake up temperature sensor
	
	//ADC1 channel16 configuration
	ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_384Cycles);
	
	ADC_Cmd(ADC1, ENABLE); 														//Enable ADC1
	
	calibdata = *FACTORY_CALIB_DATA;
	
  ADC_SoftwareStartConv(ADC1);
	
	while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)){} 	//wait for conversion complete
	
	AD_value = ADC_GetConversionValue(ADC1);					//read ADC value
	ADC_ClearFlag(ADC1, ADC_FLAG_EOC);								//clear EOC flag

	TemperatureC = CalcTemperature(AD_value); 
	return TemperatureC;
}
コード例 #28
0
ファイル: main.c プロジェクト: LupusDei/8LU-DSP
int main(void)
{
  u16 Conversion_Value = 0;

  #ifdef DEBUG
    debug();
  #endif
  
  SCU_MCLKSourceConfig(SCU_MCLK_OSC);         /*Use OSC as the default clock source*/
  SCU_PCLKDivisorConfig(SCU_PCLK_Div1);      /* ARM Peripheral bus clokdivisor = 1*/
  
  SCU_APBPeriphClockConfig(__ADC, ENABLE);    /* Enable the clock for the ADC */
  ADC_DeInit();                               /* ADC Deinitialization */

  SCU_APBPeriphClockConfig(__TIM01, ENABLE);  /* Enable the clock for TIM0 and TIM1 */
  TIM_DeInit(TIM0);                           /* TIM0 Deinitialization */

  SCU_APBPeriphClockConfig(__GPIO4, ENABLE);  /* Enable the clock for the GPIO4 */
  GPIO_DeInit(GPIO4);                         /* GPIO4 Deinitialization */

  SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  /* Enable the clock for the GPIO3 */
  GPIO_DeInit(GPIO3);                         /* GPIO3 Deinitialization */

  /* Configure the GPIO4 pin 5 as analog input */
  GPIO_ANAPinConfig(GPIO_ANAChannel5, ENABLE);

  /* GPIO6 configuration (PWM on P3.0, pin 55) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3;
  GPIO_Init(GPIO3,&GPIO_InitStructure);

  /* TIM0 Structure Initialization */
  TIM_StructInit(&TIM_InitStructure);

  /* TIM0 Configuration in PWM Mode */
  TIM_InitStructure.TIM_Mode = TIM_PWM;
  TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
  TIM_InitStructure.TIM_Prescaler = 0x0;
  TIM_InitStructure.TIM_Pulse_Level_1 = TIM_HIGH;
  TIM_InitStructure.TIM_Period_Level = TIM_LOW;
  TIM_InitStructure.TIM_Pulse_Length_1 = 0x200;
  TIM_InitStructure.TIM_Full_Period = 0x404;
  TIM_Init (TIM0, &TIM_InitStructure);

  /* Start the counter of TIM0 */
  TIM_CounterCmd(TIM0, TIM_START);

  /* ADC Structure Initialization */
  ADC_StructInit(&ADC_InitStructure);

  /* Configure the ADC in continuous mode conversion */
  ADC_InitStructure.ADC_Channel_5_Mode = ADC_NoThreshold_Conversion;
  ADC_InitStructure.ADC_Select_Channel = ADC_Channel_5;
  ADC_InitStructure.ADC_Scan_Mode = DISABLE;
  ADC_InitStructure.ADC_Conversion_Mode = ADC_Continuous_Mode;

  /* Enable the ADC */
  ADC_Cmd(ENABLE);

  /* Prescaler config */
  ADC_PrescalerConfig(0x0);

  /* Configure the ADC */
  ADC_Init(&ADC_InitStructure);

  /* Start the conversion */
  ADC_ConversionCmd(ADC_Conversion_Start);

  while(1)
  {
        /* Wait until conversion completion */
    while(ADC_GetFlagStatus(ADC_FLAG_ECV) == RESET);

    /* Get the conversion value */
    Conversion_Value = ADC_GetConversionValue(ADC_Channel_5);

    /* Clear the end of conversion flag */
    ADC_ClearFlag(ADC_FLAG_ECV);

    /* Set the new pulse of the TIM0 */
    TIM_SetPulse(TIM0, TIM_PWM_OC1_Channel, Conversion_Value);
  }
}
コード例 #29
0
ファイル: adc_driver.c プロジェクト: konglingchun/charger
void ADC1Stop(void)
{
	ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
	ADC_SoftwareStartConvCmd(ADC1, DISABLE);
	ADC_Cmd(ADC1, DISABLE);
}
コード例 #30
0
ファイル: btm.c プロジェクト: MINH-TIEN-KHT/PIP-Watch
/* Described at the top of this file. */
void BluetoothModemTask( void *pvParameters )
{
    char cChar;

    /* Just to avoid compiler warnings. */
    ( void ) pvParameters;


    /* Initialise COM0, which is USART1 according to the STM32 libraries. */
    lCOMPortInit( comBTM, mainBAUD_RATE );

    /* Reset BTM */
    #if 0
    GPIO_ResetBits(BTM_Reset_Port, BTM_Reset_Pin);
    vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS );
    GPIO_SetBits(BTM_Reset_Port, BTM_Reset_Pin);
    #endif

    // do { } while (1);

    // const char *atEscape = "^^^";
    const char *atEscapeChar = "^";
    const char *atEOL = "\r";
    const char *atTest = "AT\r";
    
    // after-reset condition: give the BT module some time to init itself.
    vTaskDelay( ( TickType_t ) 1000 / portTICK_PERIOD_MS );

    do {
        #if 1
        // Before the escape sequence there must be silence for 1s
        vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS );
        
        lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) );
        vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS );
        lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) );
        vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS );
        lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) );
        
        // After the escape sequence there must be silence for 1s
        vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS );
        #endif

        LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_100, LED_INTENS_0);

        // Send end of line
        lSerialPutString( comBTM, atEOL, strlen(atEOL) );
        // wait a little bit
        vTaskDelay( ( TickType_t ) 100 / portTICK_PERIOD_MS );
        // empty input buffer
        usartDrainInput(comBTM);            /* this drains possible 'ERROR 05' status */
        
        // vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS );

        // Send plain AT
        lSerialPutString( comBTM, atTest, strlen(atTest) );
        // vTaskDelay( ( TickType_t ) 20 / portTICK_PERIOD_MS );
        
        // expect "OK\r\n"
    } while (btmExpectOK());

    LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_0, LED_INTENS_100);

    
    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 /*| GPIO_Pin_1*/;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init( GPIOA, &GPIO_InitStruct );
    do { } while (1);

    // disable local echo
    const char *atDisableEcho = "ATE0\r";
    lSerialPutString( comBTM, atDisableEcho, strlen(atDisableEcho) );
    if (btmExpectOK()) {
        // failed
        assert_failed(__FILE__, __LINE__);
    }

    const char *atSetDeviceName = "AT*agln=\"PIP-Watch\",0\r\n";
    lSerialPutString( comBTM, atSetDeviceName, strlen(atSetDeviceName) );
    if (btmExpectOK()) {
        // failed
        assert_failed(__FILE__, __LINE__);
    }

    const char *atSetPin = "AT*agfp=\"1234\",0\r";
    lSerialPutString( comBTM, atSetPin, strlen(atSetPin) );
    if (btmExpectOK()) {
        // failed
        assert_failed(__FILE__, __LINE__);
    }

    const char *atToDataMode = "AT*addm\r";
    lSerialPutString( comBTM, atToDataMode, strlen(atToDataMode) );
    if (btmExpectOK()) {
        // failed
        assert_failed(__FILE__, __LINE__);
    }


    /* Try sending out a string all in one go, as a very basic test of the
    lSerialPutString() function. */
    // lSerialPutString( comBTM, pcLongishString, strlen( pcLongishString ) );

    int k = 0;
    char *buf = NULL;

    for( ;; )
    {
        /* Block to wait for a character to be received on COM0. */
        xSerialGetChar( comBTM, &cChar, portMAX_DELAY );

        /* Write the received character back to COM0. */
        xSerialPutChar( comBTM, cChar, 0 );

        if (!buf) {
            buf = pvPortMalloc(sizeof(char) * 32);

        #if 0
            /* start ADC conversion by software */
            // ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
            ADC_ClearFlag(ADC1, ADC_FLAG_STRT);
            ADC_Cmd(ADC1, ENABLE);
        #if 0
            ADC_SoftwareStartConvCmd(ADC1, ENABLE);
            /* wait till the conversion starts */
            while (ADC_GetSoftwareStartConvStatus(ADC1) != RESET) { }
        #endif
            /* wait till the conversion ends */
            while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != SET) { }
        #endif
            
            k = 0;
            // k = itostr(buf, 32, RTC_GetCounter());
            // k = itostr(buf, 32, ADC_GetConversionValue(ADC1));
            // k = itostr(buf, 32, vbat_measured);
            // k = itostr(buf, 32, vbat_percent);

            // ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
        }

        buf[k++] = cChar;
        
        if (cChar == '\r' || k >= 30) {
            buf[k] = '\0';
            
            for (int i = 0; i < k-4; ++i) {
                if (buf[i] == '*') {
                    /* set time: *<hours><minutes> */
                    int hours = (buf[i+1]-'0')*10 + (buf[i+2]-'0');
                    int minutes = (buf[i+3]-'0')*10 + (buf[i+4]-'0');
                    hours %= 24;
                    minutes %= 60;
                    current_rtime.sec = 0;
                    current_rtime.hour = hours;
                    current_rtime.min = minutes;
                    break;
                }
            }

            if (xQueueSend(toDisplayStrQueue, &buf, 0) == pdTRUE) {
                // ok; will alloc new buffer
                buf = NULL;
            } else {
                // fail; ignore, keep buffer
            }

            // motor demo
            GPIO_SetBits(GPIOB, 1 << 13);
            vTaskDelay( ( TickType_t ) 300 / portTICK_PERIOD_MS );
            GPIO_ResetBits(GPIOB, 1 << 13);

            k = 0;
            xSerialPutChar( comBTM, '\n', 0 );
        }

    }
}