Пример #1
3
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc) 
{
	/*ADC1 regular group
	conversion is finished*/
	/*count the amount of samples collected*/
	sampleCounter[0]--;
	for (int i = 0;i < 3;i++)
	{
		/*collect all ADC samples*/
		adcAccumulator[i] += adcConvertedValues[i];
	}
	if(sampleCounter[0] == 0)
	{
		/*if required number of samples is collected
		calculate average data
		and turn off ADC and DMA*/
		HAL_ADC_Stop_DMA(&hadc1);
		xPosSignal = adcAccumulator[0]/ADC1_SAMPL_NUMBER;
		yPosSignal = adcAccumulator[1]/ADC1_SAMPL_NUMBER;
		zPosSignal = adcAccumulator[2]/ADC1_SAMPL_NUMBER;
		
	}
	else
	{
		/*perform next conversion cycle otherwise*/
		HAL_ADC_Start_IT(&hadc1);
	}
}
Пример #2
0
void adcSetResolution (uint8_t res){
	samplingDisable();
	HAL_ADC_Stop_DMA(&hadc1);
	HAL_ADC_Stop_DMA(&hadc2);
	HAL_ADC_Stop_DMA(&hadc3);
	if(res==8){
		ADCResolution	= ADC_RESOLUTION8b;
	}else if(res==12){
		ADCResolution	= ADC_RESOLUTION12b;
	}else{
		return;
	}
	
	HAL_ADC_DeInit(&hadc1);
	HAL_ADC_DeInit(&hadc2);
	HAL_ADC_DeInit(&hadc3);
	
	HAL_DMA_DeInit(&hdma_adc1);
	HAL_DMA_DeInit(&hdma_adc2);
	HAL_DMA_DeInit(&hdma_adc3);
	
	MX_ADC1_Init();
  MX_ADC2_Init();
  MX_ADC3_Init();
} 
Пример #3
0
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle)
{	
	HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_9);
	HAL_ADC_Stop_DMA(&g_AdcHandle);
	osSignalSet(tid_TH_GUI,DMA_ConvCpltSig);
	HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_9);
	//GPIOB->ODR ^= GPIO_PIN_9; // this is just for test of DMA speed
}
/**
  * @brief Update power module instance adc measurements.
  * @param  power_module: pointer to  power module instance for which to get adc measurements.
  * @retval None.
  */
void EPS_update_power_module_state(EPS_PowerModule *power_module){

	/*initialize adc handle*/
	power_module->hadc_power_module->Init.NbrOfConversion = 2;
	//power_module->hadc_power_module->NbrOfConversionRank = 2;
	HAL_ADC_Init(power_module->hadc_power_module);

	/*setup conversion sequence for */
	ADC_ChannelConfTypeDef sConfig;
	sConfig.SamplingTime = ADC_SAMPLETIME_192CYCLES;

	/*power module current*/
	sConfig.Channel = power_module->ADC_channel_current ;
	sConfig.Rank = 1;
	HAL_ADC_ConfigChannel(power_module->hadc_power_module, &sConfig);

	/*power module voltage*/
	sConfig.Channel = power_module->ADC_channel_voltage ;
	sConfig.Rank = 2;
	HAL_ADC_ConfigChannel(power_module->hadc_power_module, &sConfig);



	/*start dma transfer from adc to memory.*/

	uint32_t adc_measurement_dma_power_modules[67]= { 0 };//2*64 +1

	adc_reading_complete = ADC_TRANSFER_NOT_COMPLETED;//external global flag defined in main and shared with the adc complete transfer interrupt handler.
	HAL_ADC_Start_DMA(power_module->hadc_power_module, adc_measurement_dma_power_modules, 66);

	/*Process Measurements*/
	uint32_t voltage_avg =0;
	uint32_t current_avg =0;

	/*Wait till DMA ADC sequence transfer is ready*/
	while(adc_reading_complete==ADC_TRANSFER_NOT_COMPLETED){
		//wait for dma transfer complete.
	}
	/*ADC must be stopped in the adc dma transfer complete callback.*/

	HAL_ADC_Stop_DMA(power_module->hadc_power_module);

	/*de-interleave and sum voltage and current measurements.*/
	for (int sum_index = 2; sum_index < 66; sum_index+=2) {
		/*top*/
		current_avg = current_avg + adc_measurement_dma_power_modules[sum_index];
		voltage_avg = voltage_avg + adc_measurement_dma_power_modules[sum_index+1];
	}

	/*filter ting*/
	/*average of 16 concecutive adc measurements.skip the first to avoid adc power up distortion.*/
	power_module->voltage = voltage_avg>>5;
	power_module->current = current_avg>>5;


}
Пример #5
0
void HAL_ADC_Enable(int enable)
{
#ifdef ENABLE_ADC
	if ( (adc_enabled == 0) && (enable != 0) ) {
		memset(&adc_samples,0, sizeof(adc_samples));
		HAL_StatusTypeDef status = HAL_ADC_Start_DMA(&hadc1, (uint32_t *)&adc_samples, sizeof(adc_samples));
		adc_enabled = ( status == HAL_OK ) ? 1 : 0;
	} else {
		if (adc_enabled != 0) {
			HAL_ADC_Stop_DMA(&hadc1);
		}
	}
#endif
}
Пример #6
0
static int
stm32f4_adc_release_buffer(struct adc_dev *dev, void *buf, int buf_len)
{
    ADC_HandleTypeDef *hadc;
    struct stm32f4_adc_dev_cfg *cfg;

    assert(dev);
    cfg  = (struct stm32f4_adc_dev_cfg *)dev->ad_dev.od_init_arg;
    hadc = cfg->sac_adc_handle;

    HAL_ADC_Stop_DMA(hadc);

    return (0);
}
Пример #7
0
/* USER CODE BEGIN 1 */
void ADC_DMA_Reconfig(uint8_t chan, uint32_t *buff, uint32_t len){
	ADC_HandleTypeDef adcHandler;
	switch(chan){
		case 0:
			adcHandler=hadc1;
		break;
		case 1:
			adcHandler=hadc2;
		break;
		case 2:
			adcHandler=hadc3;
		break;
	}
	HAL_ADC_Stop_DMA(&adcHandler);
	HAL_ADC_Start_DMA(&adcHandler, buff, len);
}
Пример #8
0
/**
  * @brief  HAL_ADC_ConvCpltCallback
  *     Get U/I output values
  * @param  ADC Handle
  * @retval None
  */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
  /* Stop DMA */
  HAL_ADC_Stop_DMA(&hadc1);
  /**/
  Calc_ADC_UI(ADC_SAMPLES_CNT/4, ADC_SAMPLES_CNT/2);

  /* Convert U/I values */
  float U = ( (float)adc_sum.v * 32.2F * 13.48F ) / 4095.0F;  // Convert, value = [ (adcdata * vdda * k) / 2^12 ], were k = 12k/1k + 1 = 13
  float I = ( ((float)adc_sum.i * 322.0F * (1.0F/0.047F) ) / (4095.0F * 9.2F) );  // Convert, value to mA

  hw_channel_self.data.v = (uint16_t)( U / (float)(ADC_SAMPLES_CNT/2) );
  hw_channel_self.data.i = (uint16_t)( I / (float)(ADC_SAMPLES_CNT/2) ) - 1;

  /* Complite data collection for channel callback */
  HW_Channel_GetDataCallback(&hw_channel_self);
}
Пример #9
0
    result_t stop(Port p)
    {
        if(false == initialised(p))
        {
            return resNOK;
        } 
        
        if(true == s_adc_isrunning)
        {
            HAL_ADC_Stop_DMA(&hadc1);  
            s_adc_isrunning = false;  
        }

        s_adc_isrunning = false;        

        return resOK;           
    }    
Пример #10
0
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{

	//SCOPE_1_TOGGLE();	

	
	adcDma_fullcnt = uni_adcDMA_bytesCaptured(hadc1.Init.NbrOfConversion);
		
	
	#ifdef CIRCULAR_DMA
	
	//is.dma2_complete_flag = true;
	power_from_ADC(adc_dma_buf_2); // ****** use is.adc_samples_per_cycle here?
	
	
	// continues automatically
	#else
	HAL_ADC_Stop_DMA(&hadc1);  
	// call uni_adc_start(); to restart
	#endif			
}
Пример #11
0
void test_Vbat(void)
{
	  ADC_ChannelConfTypeDef sConfig;
	  int vbat;
	  int vref = 3300;  //mV
	  int coeff = 33;  //%

	  ExpanderSetbit(7,0);
	  HAL_Delay(100);
	  ExpanderSetbit(7,1);
	  HAL_Delay(100);

	  ssd1306Init(0);
	  ssd1306ClearScreen();
	  ssd1306Refresh();

	  while(1)
	  {
	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, SET);
	  ssd1306ClearScreen();
	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_15;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_8, 1);

	  vbat = (((vref * uhADCxConvertedValue_8) / 40950) * coeff);

	  ssd1306PrintInt(10,  5, "Vbat =  ", vbat, &Font_5x8);
	  ssd1306Refresh();
	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, RESET);
	  HAL_Delay(100);
	  }

}
Пример #12
0
/**
  * @brief  Stop audio recording
  * @retval None
  */
uint8_t BSP_AUDIO_IN_Stop(void)
{
  uint32_t ret = AUDIO_OK;
  
  /* Stop the time base triggering the ADC */
  if (HAL_TIM_Base_Stop(&hAudioInTim3) != HAL_OK)
  {
    ret = AUDIO_ERROR;
  } 
  
  if (HAL_ADC_Stop_DMA(&hAudioInAdc) != HAL_OK)
  {
    /* Return 0 if all operations are OK */
    ret = AUDIO_ERROR;
  }
  
  /* Disable OPAMPx */
  if (HAL_OPAMP_Stop(&hAudioInOpamp) != HAL_OK)
  {
    ret = AUDIO_ERROR;
  }  
  
  return ret;
}
Пример #13
0
static EPS_soft_error_status EPS_update_state_adc_measurements(volatile EPS_State *state, ADC_HandleTypeDef *hadc_eps){

	EPS_soft_error_status adc_update_state = EPS_SOFT_ERROR_UPDATE_STATE_ADC;

	/*initialize adc handle*/
	hadc_eps->Init.NbrOfConversion = 6;
	HAL_ADC_Init(hadc_eps);

	/*setup conversion sequence for */
	ADC_ChannelConfTypeDef sConfig;
	sConfig.SamplingTime = ADC_SAMPLETIME_384CYCLES;

	/*Vbat*/
	sConfig.Channel = ADC_VBAT;
	sConfig.Rank = 1;
	HAL_ADC_ConfigChannel(hadc_eps, &sConfig);

	/*Ibat+*/
	sConfig.Channel = ADC_IBAT_PLUS;
	sConfig.Rank = 2;
	HAL_ADC_ConfigChannel(hadc_eps, &sConfig);

	/*Ibat-*/
	sConfig.Channel = ADC_IBAT_MINUS;
	sConfig.Rank = 3;
	HAL_ADC_ConfigChannel(hadc_eps, &sConfig);

	/*I3v3*/
	sConfig.Channel = ADC_I3V3;
	sConfig.Rank = 4;
	HAL_ADC_ConfigChannel(hadc_eps, &sConfig);

	/*I5v*/
	sConfig.Channel = ADC_I5V;
	sConfig.Rank = 5;
	HAL_ADC_ConfigChannel(hadc_eps, &sConfig);

	/*cpu internal temp sensor*/
	sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
	sConfig.Rank = 6;
	HAL_ADC_ConfigChannel(hadc_eps, &sConfig);

	adc_update_state = EPS_SOFT_ERROR_UPDATE_STATE_ADC_DMA;

	/*Start conversion and dma transfer*/
	uint32_t adc_measurement_dma_eps_state[55]= { 0 };//2*6 +1

	adc_reading_complete = ADC_TRANSFER_NOT_COMPLETED;
	HAL_ADC_Start_DMA(hadc_eps, adc_measurement_dma_eps_state, 54);

	/*Process Measurements*/
	uint32_t battery_voltage_avg =0;
	uint32_t battery_current_plus_avg =0;
	uint32_t battery_current_minus_avg =0;
	uint32_t v3_3_current_avg =0;
	uint32_t v5_current_avg =0;
	uint32_t cpu_temp_avg =0;

	/*Wait till DMA ADC sequence transfer is ready*/
	while(adc_reading_complete==ADC_TRANSFER_NOT_COMPLETED){
 	}
	HAL_ADC_Stop_DMA(hadc_eps);


	adc_update_state = EPS_SOFT_ERROR_UPDATE_STATE_ADC_FILTER;

	//de-interleave and sum adc state measurements.overflow strategy??? : 2^12(max adc value) * 32 = 2^17 < 2^32 so you do not need one!
	for (int sum_index = 6; sum_index < 54; sum_index+=6) {
		/*top*/
		battery_voltage_avg = battery_voltage_avg + adc_measurement_dma_eps_state[sum_index];
		battery_current_plus_avg = battery_current_plus_avg + adc_measurement_dma_eps_state[sum_index+1];
		battery_current_minus_avg = battery_current_minus_avg + adc_measurement_dma_eps_state[sum_index+2];
		v3_3_current_avg = v3_3_current_avg + adc_measurement_dma_eps_state[sum_index+3];
		v5_current_avg = v5_current_avg + adc_measurement_dma_eps_state[sum_index+4];
		cpu_temp_avg = cpu_temp_avg + adc_measurement_dma_eps_state[sum_index+5];
	}

	/*filter ting*/
	//average of 8 concecutive adc measurements.skip the first to avoid adc power up distortion.
	state->battery_voltage = battery_voltage_avg>>3;
	state->battery_current_plus = battery_current_plus_avg>>3;
	state->battery_current_minus = battery_current_minus_avg>>3;
	state->v3_3_current_avg = v3_3_current_avg>>3;
	state->v5_current_avg = v5_current_avg>>3;

	adc_update_state = EPS_SOFT_ERROR_UPDATE_STATE_ADC_CPU_TEMP;

	state->cpu_temperature = COMPUTATION_TEMPERATURE_TEMP30_TEMP110((cpu_temp_avg>>3));

	adc_update_state = EPS_SOFT_ERROR_OK;
	return adc_update_state;
}
Пример #14
0
/** \brief  停止进行温度AD转换
 *
 * \return void
 */
static void drv_StopMeasureTemperatureRaw()
{
    HAL_ADC_Stop_DMA(&ADC_HandleStruct);
}
Пример #15
0
void test_LineSensors(void)
{
	  ADC_ChannelConfTypeDef sConfig;

	  ExpanderSetbit(7,0);
	  HAL_Delay(100);
	  ExpanderSetbit(7,1);
	  HAL_Delay(100);

	  ssd1306Init(0);
	  ssd1306ClearScreen();
	  ssd1306Refresh();

	  while(1)
	  {
	  ssd1306ClearScreen();

	  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, SET);
	  HAL_Delay(25);


	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_3;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_1, 1);
	  ssd1306PrintInt(10,  5, "ADC3  = ", uhADCxConvertedValue_1, &Font_5x8);

	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_4;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_2, 1);
	  ssd1306PrintInt(10, 15, "ADC4  = ", uhADCxConvertedValue_2, &Font_5x8);

	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_1;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_3, 1);
	  ssd1306PrintInt(10, 25, "ADC1  = ", uhADCxConvertedValue_3, &Font_5x8);

	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_13;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_4, 1);
	  ssd1306PrintInt(10, 35, "ADC13 = ", uhADCxConvertedValue_4, &Font_5x8);

	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_12;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_5, 1);
	  ssd1306PrintInt(10, 45, "ADC12 = ", uhADCxConvertedValue_5, &Font_5x8);

	  ssd1306Refresh();

	  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, RESET);
	  }
}
Пример #16
0
void ADC_Stop(){

  HAL_ADC_Stop_DMA(&AdcHandle);

}
Пример #17
0
bool uni_adc_stop(void)
{
	//if(HAL_ADC_Stop(&hadc1) != HAL_OK) return 0; 
	if(HAL_ADC_Stop_DMA(&hadc1) != HAL_OK) return 0;
	return 1;
}
Пример #18
0
void Syringe_Size_stop(void)
{
HAL_ADC_Stop_DMA(&AdcHandle);
	
}