Beispiel #1
1
int main(void) {
  char msg[20];
  uint16_t rawValues[3];
  float temp;

  HAL_Init();
  Nucleo_BSP_Init();

  /* Initialize all configured peripherals */
  MX_TIM1_Init();
  MX_ADC1_Init();

  HAL_ADCEx_Calibration_Start(&hadc1);

  HAL_TIM_Base_Start(&htim1);
  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)rawValues, 1);

  while(1) {
    while(!convCompleted);

     for(uint8_t i = 0; i < 1; i++) {
      temp = ((float)rawValues[i]) / 4095 * 3300;
      temp = ((temp - 1430.0) / 4.3) + 25;

      sprintf(msg, "rawValue %d: %hu\r\n", i, rawValues[i]);
      HAL_UART_Transmit(&huart2, (uint8_t*) msg, strlen(msg), HAL_MAX_DELAY);

      sprintf(msg, "Temperature %d: %f\r\n",i,  temp);
      HAL_UART_Transmit(&huart2, (uint8_t*) msg, strlen(msg), HAL_MAX_DELAY);
    }
    convCompleted = 0;
  }
}
Beispiel #2
0
//
// uni_adc_start(); 
// do not restart DMA when using circular buffer
//
bool uni_adc_start(void)
{
	
	
	//SCOPE_1_HIGH();
	
	
	//log_int("adc channels: ", hadc1.Init.NbrOfConversion);
	//if(HAL_ADC_Start(&hadc1) != HAL_OK) return 0; 
	//if(HAL_ADC_Start_DMA(&hadc1, (uint32*)adc_dma_buf, ADC_DMA_SAMPLES) != HAL_OK) return 0;
	
	
	//
	// *** set DMA length - by cycle length ???
	//
	
	
	// if the number of samples is fixed
	if(HAL_ADC_Start_DMA(&hadc1, (uint32*)adc_dma_buf, ADC_DMA_SAMPLES * 2) != HAL_OK) return 0; // x2 for circular
	
	
	// no does not work for circular with half buffers
	// if the number of samples is set by measuring a cycle using zero-crossing etc.
	//if(HAL_ADC_Start_DMA(&hadc1, (uint32*)adc_dma_buf, is.adc_samples_per_cycle * 2) != HAL_OK) return 0; // x2 for circular

	
	
	// disable half-full interrupt
	//__HAL_DMA_DISABLE_IT(hadc1.DMA_Handle, DMA_IT_HT); 
	
	
	return 1;
}
Beispiel #3
0
/* USER CODE BEGIN 4 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) 
{
	/*250 Hz service interrupt
	was caused by TIM2*/
	if(htim->Instance == TIM2)
	{
		if (sampleCounter[0] == 0){
			/*clear accumulated data buffer*/
			for (int i = 0;i < 3;i++)
			{
				adcAccumulator[i] = 0;
			}
			/*Start ADC_1 to measure position sensors data*/
			HAL_ADC_Start_DMA(&hadc1, (unsigned int*)adcConvertedValues, 3);
			sampleCounter[0] = ADC1_SAMPL_NUMBER;
		}
		if (sampleCounter[1] == 0){
			/*clear accumulated data buffer*/
			for (int i = 3;i < 6;i++)
			{
				adcAccumulator[i] = 0;
			}
			/*Start ADC_2 to measure motor currents*/
			sampleCounter[1] = ADC2_SAMPL_NUMBER;
			HAL_ADCEx_InjectedStart_IT(&hadc2);
		}
	}
	/*PWM-driving TIM1
	caused interrupt on update event*/
	if(htim->Instance == TIM1) 
	{
	}
}
/**
  * @brief  Start audio recording
  * @param  pbuf Main buffer pointer for the recorded data storing  
  * @param  size Current size of the recorded buffer
  * @retval AUDIO_OK if correct communication, else wrong communication
  */
uint8_t BSP_AUDIO_IN_Record(uint16_t* pbuf, uint32_t size)
{
  uint32_t                ret = AUDIO_OK;
  TIM_MasterConfigTypeDef master_config = {0};

  if (HAL_ADC_Start_DMA(&hAudioInAdc, (uint32_t*)pbuf, size) == HAL_OK)
  {
    master_config.MasterOutputTrigger = TIM_TRGO_UPDATE;
    master_config.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
    
    HAL_TIMEx_MasterConfigSynchronization(&hAudioInTim3, &master_config);
    
    /* Start the time base triggering the ADC */
    if (HAL_TIM_Base_Start(&hAudioInTim3) != HAL_OK)
    {
      ret = AUDIO_ERROR;
    }
  }
  else
  {
    ret = AUDIO_ERROR;
  }
  
  return ret;
}
Beispiel #5
0
void ADC_Start(){

  if(HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&uhADCxConvertedValue, 1) != HAL_OK)
    {
      // Start Conversation Error
      Error_Handler();
    }
}
Beispiel #6
0
static void acquisition_start(void)
{
	HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t*)&wave_buff, WAVE_BUFF_LEN, DAC_ALIGN_12B_R);
	HAL_ADC_Start_IT(&hadc2);
	HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&mic_buff, WAVE_BUFF_LEN);
	HAL_TIM_Base_Start(&htim2);
	HAL_TIM_Base_Start_IT(&htim3);
}
//Zonder DMA
//void ADC_IRQHandler(void)
//{
//	uint16_t value = 0;
//		value = HAL_ADC_GetValue(&hadc1);
//		if(counter % 2 == 0) {
//				a1 = value;
//				HAL_GPIO_WritePin(GPIOD,LD5_Pin,GPIO_PIN_SET); //RED
//		} else {
//				a2 = value;
//				HAL_GPIO_WritePin(GPIOD,LD4_Pin,GPIO_PIN_SET); //YELLOW
//		}
//		counter++;
//}
void ADC_IRQHandler(void)
{
//	char tempbuffer[50] = {"Empty.."};
	if(counter%2 == 0)
		  {

			  HAL_ADC_Start_DMA(&hadc1, &ADCBuffer1[0], ADC_BUFFER_LENGTH*2);
		  }
		  else
		  {
			  HAL_ADC_Start_DMA(&hadc1, &ADCBuffer2[0], ADC_BUFFER_LENGTH*2);
		  }
//	  sprintf(tempbuffer,"counter: %05d   ",(int) counter);
//	  HAL_UART_Transmit(&huart6,(uint8_t*) tempbuffer,strlen(tempbuffer),HAL_MAX_DELAY);
		  counter++;
	//HAL_ADC_Start_DMA(&hadc1, &ADCBuffer1[0], ADC_BUFFER_LENGTH*2);
	//HAL_ADC_IRQHandler(&hadc1);
}
/**
  * @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;


}
Beispiel #9
0
/*====================================================================================================*/
void ADC_Config( void )
{
  ADC_ChannelConfTypeDef ADC_ChannelConfStruct;
  HAL_StatusTypeDef state;

  /* Config ADC *****************************************************************/
  ADC_HandleStruct.Instance = ADCx;
  ADC_HandleStruct.Init.ClockPrescaler        = ADC_CLOCK_ASYNC_DIV1;
  ADC_HandleStruct.Init.Resolution            = ADC_RESOLUTION_12B;
  ADC_HandleStruct.Init.DataAlign             = ADC_DATAALIGN_RIGHT;
  ADC_HandleStruct.Init.ScanConvMode          = ENABLE;
  ADC_HandleStruct.Init.EOCSelection          = ADC_EOC_SINGLE_CONV;
  ADC_HandleStruct.Init.LowPowerAutoWait      = DISABLE;
  ADC_HandleStruct.Init.ContinuousConvMode    = ENABLE;
  ADC_HandleStruct.Init.NbrOfConversion       = ADC_BUF_CHENNAL;
  ADC_HandleStruct.Init.DiscontinuousConvMode = ENABLE;
  ADC_HandleStruct.Init.NbrOfDiscConversion   = 1;
  ADC_HandleStruct.Init.ExternalTrigConv      = ADC_SOFTWARE_START;
  ADC_HandleStruct.Init.ExternalTrigConvEdge  = ADC_EXTERNALTRIGCONVEDGE_NONE;
  ADC_HandleStruct.Init.DMAContinuousRequests = ENABLE;
  ADC_HandleStruct.Init.Overrun               = ADC_OVR_DATA_OVERWRITTEN;
  HAL_ADC_DeInit(&ADC_HandleStruct);
  state = HAL_ADC_Init(&ADC_HandleStruct);
  if(state != HAL_OK)
    while(1) { ; }

  /* Config ADC Chennal **********************************************************/
  ADC_ChannelConfStruct.SamplingTime = ADC_SAMPLETIME_601CYCLES_5;
  ADC_ChannelConfStruct.SingleDiff   = ADC_SINGLE_ENDED;
  ADC_ChannelConfStruct.OffsetNumber = ADC_OFFSET_NONE;
  ADC_ChannelConfStruct.Offset       = 0;

  // ADC1_CH1 Channel
  ADC_ChannelConfStruct.Channel = ADCx_CHANNEL;
  ADC_ChannelConfStruct.Rank    = ADC_REGULAR_RANK_1;
  state = HAL_ADC_ConfigChannel(&ADC_HandleStruct, &ADC_ChannelConfStruct);
  if(state != HAL_OK)
    while(1) { ; }

  // ADC1_CH2 Channel
//  ADC_ChannelConfStruct.Channel = ADCx_2_CHANNEL;
//  ADC_ChannelConfStruct.Rank    = ADC_REGULAR_RANK_2;
//  state = HAL_ADC_ConfigChannel(&ADC_HandleStruct, &ADC_ChannelConfStruct);
//  if(state != HAL_OK)
//    while(1) { ; }

  /* Setup ADC *******************************************************************/
  state = HAL_ADCEx_Calibration_Start(&ADC_HandleStruct, ADC_SINGLE_ENDED);
  if(state != HAL_OK)
    while(1) { ; }
  state = HAL_ADC_Start_DMA(&ADC_HandleStruct, (uint32_t *)ADC_DMA_ConvBuf, ADC_BUF_SIZE * ADC_BUF_CHENNAL);
  if(state != HAL_OK)
    while(1) { ; }
}
/**
  * @brief  CustomHID_Init
  *         Initializes the CUSTOM HID media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CustomHID_Init(void)
{
  GPIO_InitTypeDef   GPIO_InitStructure;
  ADC_ChannelConfTypeDef sConfig;

  /* Configure the ADC peripheral */
  AdcHandle.Instance = ADCx;
  
  AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
  AdcHandle.Init.ScanConvMode = DISABLE;
  AdcHandle.Init.ContinuousConvMode = ENABLE;
  AdcHandle.Init.DiscontinuousConvMode = DISABLE;
  AdcHandle.Init.NbrOfDiscConversion = 0;
  AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
  AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  AdcHandle.Init.NbrOfConversion = 1;
  AdcHandle.Init.DMAContinuousRequests = ENABLE;
  AdcHandle.Init.EOCSelection = DISABLE;
  HAL_ADC_Init(&AdcHandle);
   
  /* Configure ADC regular channel */  
  sConfig.Channel = ADCx_CHANNEL;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
  sConfig.Offset = 0;
  HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);

  /* Start the conversion process and enable interrupt */  
  HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&ADCConvertedValue, 1);
    
  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /* Enable GPIOE clock */
  __HAL_RCC_GPIOE_CLK_ENABLE();
  
  /* Configure PE6 pin as input floating */
  GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStructure.Pull = GPIO_NOPULL;
  GPIO_InitStructure.Pin = GPIO_PIN_6;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);

  /* Enable and set EXTI15_10 Interrupt to the lowest priority */
  HAL_NVIC_SetPriority(EXTI9_5_IRQn, 3, 0);
  HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
  
  return (0);
}
Beispiel #11
0
/**
* @brief This function handles TIM2 global interrupt.
*/
void TIM2_IRQHandler(void)
{
  /* USER CODE BEGIN TIM2_IRQn 0 */

  irqflag_timer2 = 1;
  HAL_ADC_Start_DMA(&hadc4, adc4Samples, 2);
  /* USER CODE END TIM2_IRQn 0 */
  HAL_TIM_IRQHandler(&htim2);
  /* USER CODE BEGIN TIM2_IRQn 1 */

  /* USER CODE END TIM2_IRQn 1 */
}
Beispiel #12
0
/**
* @brief This function handles TIM1 up and TIM16 interrupts.
*/
void TIM1_UP_TIM16_IRQHandler(void)
{
  /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 0 */
	static int irqcounter = 0;



	HAL_ADC_Start_DMA(&hadc1,&adc1Samples, 10 *4 );
	HAL_ADC_Start_DMA(&hadc2,&adc2Samples, 7 *4 );
	HAL_ADC_Start_DMA(&hadc3,&adc3Samples, 3 *4);

	irqcounter++;
	if(irqcounter == 4){
		irqflag_timer1 = 1;
		irqcounter = 0;
	}

  /* USER CODE END TIM1_UP_TIM16_IRQn 0 */
  HAL_TIM_IRQHandler(&htim1);
  /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 1 */

  /* USER CODE END TIM1_UP_TIM16_IRQn 1 */
}
Beispiel #13
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
}
/**
  * @brief  CustomHID_Init
  *         Initializes the CUSTOM HID media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CustomHID_Init(void)
{
  GPIO_InitTypeDef   GPIO_InitStructure;
  ADC_ChannelConfTypeDef sConfig;
  
  /* Configure the ADC peripheral */
  AdcHandle.Instance = ADCx;
  
  /* Configure the ADC clock */
  __HAL_RCC_ADC1_CONFIG(RCC_ADC1PCLK2_DIV6);
  
  AdcHandle.Init.ScanConvMode = DISABLE;
  AdcHandle.Init.ContinuousConvMode = ENABLE;
  AdcHandle.Init.DiscontinuousConvMode = DISABLE;
  AdcHandle.Init.NbrOfDiscConversion = 0;
  AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  AdcHandle.Init.NbrOfConversion = 1;
  HAL_ADC_Init(&AdcHandle);
   
  /* Configure ADC regular channel */  
  sConfig.Channel = ADCx_CHANNEL;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
  HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);

  /* Start the conversion process and enable interrupt */  
  HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&ADCConvertedValue, 1);
    
  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /* Enable GPIOA clock */
  __GPIOA_CLK_ENABLE();
  
  /* Configure PA2 pin as input floating */
  GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStructure.Pull = GPIO_NOPULL;
  GPIO_InitStructure.Pin = GPIO_PIN_2;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Enable and set EXTI2_TSC Interrupt to the lowest priority */
  HAL_NVIC_SetPriority(EXTI2_TSC_IRQn, 3, 0);
  HAL_NVIC_EnableIRQ(EXTI2_TSC_IRQn);
  
  return (0);
}
Beispiel #15
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);
}
Beispiel #16
0
void mulimeterInit(void)
{
    ADC_ChannelConfTypeDef sConfig;

    /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
     */
    hadc1.Instance = ADC1;
    hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV8;
    hadc1.Init.Resolution = ADC_RESOLUTION12b;
    hadc1.Init.ScanConvMode = ENABLE;
    hadc1.Init.ContinuousConvMode = DISABLE;
    hadc1.Init.DiscontinuousConvMode = DISABLE;
    hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING;
    hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T4_CC4;
    hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
    hadc1.Init.NbrOfConversion = 3;
    hadc1.Init.DMAContinuousRequests = ENABLE;
    hadc1.Init.EOCSelection = EOC_SEQ_CONV;
    HAL_ADC_Init(&hadc1);

    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
     */
    sConfig.Channel = ADC_CHANNEL_7;
    sConfig.Rank = 1;
    sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
    HAL_ADC_ConfigChannel(&hadc1, &sConfig);

    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
     */
    sConfig.Channel = ADC_CHANNEL_15;
    sConfig.Rank = 3;
    HAL_ADC_ConfigChannel(&hadc1, &sConfig);

    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
     */
    sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
    sConfig.Rank = 2;
    HAL_ADC_ConfigChannel(&hadc1, &sConfig);

    /**Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time
     */

    multimeter.timer_cnt = 0;
    multimeter.gpio_vbat_state = 0;
    HAL_ADC_Start_DMA(&hadc1, (uint32_t*) ADC1MultimeterConvertedValues, 3);
}
Beispiel #17
0
void keyboard_update()
{
	HAL_ADC_Start_DMA(&keyboard_hadc, (uint32_t*)keyboard_ADC_values , 2);
	int8_t cul = keyboard_adc_to_lvl(keyboard_ADC_values[0]),
		cur = keyboard_adc_to_lvl(keyboard_ADC_values[1]);
	
	if(keyboard_lastLeftLvl == -1 && keyboard_lastRightLvl == -1 &&
			(cul >= 0 || cur >= 0))
	{
		int8_t cu = keyboard_lvl_to_key(cul, cur);
		keyboard_handle(cu);
		keyboard_lastKey = cu;
	}
	
	keyboard_lastLeftLvl = cul;
	keyboard_lastRightLvl = cur;
	printf("l %04i r %04i\n", keyboard_ADC_values[0], keyboard_ADC_values[1]);
}
/**
 * Callback that gets called by the HAL when ADC conversion is complete and
 * the DMA buffer is full. If a secondary buffer exists it will the buffers.
 *
 * @param ADC Handle
 */
void
HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
    int rc;
    struct adc_dev *adc;
    DMA_HandleTypeDef *hdma;
    struct stm32f4_adc_dev_cfg *cfg;
    void *buf;

    assert(hadc);
    hdma = hadc->DMA_Handle;

    ++stm32f4_adc_stats.adc_dma_xfer_complete;

    adc = adc_dma[stm32f4_resolve_dma_handle_idx(hdma)];
    cfg  = (struct stm32f4_adc_dev_cfg *)adc->ad_dev.od_init_arg;

    buf = cfg->primarybuf;
    /**
     * If primary buffer gets full and secondary buffer exists, swap the
     * buffers and start ADC conversion with DMA with the now primary
     * buffer(former secondary buffer)
     * If the secondary buffer(former primary buffer) doesn't get processed
     * by the application in sampling period required for the primary/secondary buffer
     * i,e; (sample itvl * ADC_NUMBER_SAMPLES), the buffers would get swapped resulting
     * in new sample data.
     */
    if (cfg->secondarybuf) {
        cfg->primarybuf = cfg->secondarybuf;
        cfg->secondarybuf = buf;

        if (HAL_ADC_Start_DMA(hadc, cfg->primarybuf, cfg->buflen) != HAL_OK) {
            ++stm32f4_adc_stats.adc_dma_start_error;
        }
    }

    rc = adc->ad_event_handler_func(adc, NULL, ADC_EVENT_RESULT, buf,
                                    cfg->buflen);

    if (rc) {
        ++stm32f4_adc_stats.adc_error;
    }
}
Beispiel #19
0
void initADC(void)
{
	/* Init ADC */
	hadc1.Instance = ADC1;
	hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
	hadc1.Init.Resolution = ADC_RESOLUTION12b;
	hadc1.Init.ScanConvMode = DISABLE;
	hadc1.Init.ContinuousConvMode = ENABLE;
	hadc1.Init.DiscontinuousConvMode = DISABLE;
	hadc1.Init.NbrOfDiscConversion = 1;
	hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
	hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
	hadc1.Init.NbrOfConversion = 4;
	hadc1.Init.DMAContinuousRequests = ENABLE;
	hadc1.Init.EOCSelection = EOC_SEQ_CONV;
	HAL_ADC_Init(&hadc1);
	
	/* DMA settings in msp.c file */

	/* Configure Channels */
	ADC_ChannelConfTypeDef sConfig;
	
	/* Configure channel sample order*/
	sConfig.Channel = ADC_CHANNEL_13;
	sConfig.Rank = 4;
	sConfig.SamplingTime = ADCSAMPLES;
	HAL_ADC_ConfigChannel(&hadc1, &sConfig);

	sConfig.Channel = ADC_CHANNEL_10;
	sConfig.Rank = 1;
	HAL_ADC_ConfigChannel(&hadc1, &sConfig);

	sConfig.Channel = ADC_CHANNEL_11;
	sConfig.Rank = 2;
	HAL_ADC_ConfigChannel(&hadc1, &sConfig);

	sConfig.Channel = ADC_CHANNEL_12;
	sConfig.Rank = 3;
	HAL_ADC_ConfigChannel(&hadc1, &sConfig);

	HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&rawADC, 4);
	print("\r\n[OK] ADC conversions started");
}
    result_t start(Port p)
    {
        if(false == initialised(p))
        {
            return resNOK;
        }

        if((nullptr == s_config.destination) || (0 == s_config.numberofitems))
        {
            return resNOK;
        }
        
        if(true == s_adc_isrunning)
        {
            stop(p);
        }
        
        s_adc_isrunning = true;
        HAL_ADC_Start_DMA(&hadc1, (uint32_t*)s_config.destination, s_config.numberofitems*static_cast<uint8_t>(s_config.itemsize));
        
        return resOK;           
    }
Beispiel #21
0
/* USER CODE BEGIN 4 */
void init_all(void)
{
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_SET); //mute buzzer
	HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_1);
	HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_2);
	HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_3);
	HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_4);
	HAL_ADC_Start_DMA(&hadc, (uint32_t *)ADC_Output,2);
	//HAL_DMA_Start(&hdma_adc, (uint32_t)ADC1_DR_Address, (uint32_t)&ADC_Output, 1);
	
	GPIO_InitTypeDef GPIO_InitStruct;
	GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_PULLDOWN;
	GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
	HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
	
	triac_set_duty(1,20);
	triac_set_duty(1,20);
	triac_set_duty(1,20);
	triac_set_duty(1,20);
}
Beispiel #22
0
/**
  * @brief  Main function. Executes all initialization and terminate its thread.
  * @param  None
  * @retval None
  */
int main(void)
{	
  ///////////////////////////////////////////////////////////////////////////////////////////
  /* Configure the MPU attributes as Write Through */
  MPU_Config();
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();
	// initialize CMSIS-RTOS
  osKernelInitialize();
	///////////////////////////////////////////////////////////////////////////////////////////
	// Hardware initialize
  if( HAL_Init() != HAL_OK)
		Error_Handler();
	if( ConfigureDMA(&g_DmaHandle, &g_AdcHandle) != HAL_OK)
		Error_Handler();
	if( ADC_INIT(&g_AdcHandle) != HAL_OK)
		Error_Handler();
	
	BSP_SDRAM_Init();
	Touch_Initialize();
	///////////////////////////////////////////////////////////////////////////////////////////
  /* Configure the System clock to have a frequency of 216 MHz */
  SystemClock_Config();
	// Thread initialization
	Init_TH_GUI();
	Init_TH_Touch();
	// RTOS Start Kernel
  osKernelStart();                      // start thread execution 
	// Get Main Thread ID
	Main_thID = osThreadGetId();
	///////////////////////////////////////////////////////////////////////////////////////////
	// Start data acquire
	HAL_ADC_Start_DMA(&g_AdcHandle, values, ADC_BUFFER_LENGTH);
	///////////////////////////////////////////////////////////////////////////////////////////
	// Terminate main thread
	osThreadTerminate(Main_thID);
	/* Infinite loop */
  while (1) {  }
}
/**
 * Trigger an ADC sample.
 *
 * @param ADC device structure
 * @return OS_OK on success, non OS_OK on failure
 */
static int
stm32f4_adc_sample(struct adc_dev *dev)
{
    int rc;
    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;

    rc = OS_EINVAL;

    if (HAL_ADC_Start_DMA(hadc, cfg->primarybuf, cfg->buflen) != HAL_OK) {
        ++stm32f4_adc_stats.adc_dma_start_error;
        goto err;
    }

    rc = OS_OK;

err:
    return rc;
}
Beispiel #24
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);
	  }

}
Beispiel #25
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xG 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();
  
  /*## Configure peripherals #################################################*/
  
  /* Initialize LEDs on board */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED1);
  
  /* Configure Key push-button in Interrupt mode */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
  
  /* Configure the ADC peripheral */
  ADC_Config();
  
  /* Run the ADC calibration */  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }


#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
  /* Configure the DAC peripheral */
  DAC_Config();
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */
  

  /*## Enable peripherals ####################################################*/
  
#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
  /* Set DAC Channel data register: channel corresponding to ADC channel CHANNELa */
  /* Set DAC output to 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V              */
  if (HAL_DAC_SetValue(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNELa, DAC_ALIGN_12B_R, RANGE_12BITS/2) != HAL_OK)
  {
    /* Setting value Error */
    Error_Handler();
  }
  
  /* Enable DAC Channel: channel corresponding to ADC channel CHANNELa */
  if (HAL_DAC_Start(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNELa) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */

  /*## Start ADC conversions #################################################*/
  
  /* Start ADC conversion on regular group with transfer by DMA */
  if (HAL_ADC_Start_DMA(&AdcHandle,
                        (uint32_t *)aADCxConvertedValues,
                        ADCCONVERTEDVALUES_BUFFER_SIZE
                       ) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
  
  
  /* Infinite loop */
  while (1)
  {

    /* Wait for event on push button to perform following actions */
    while ((ubUserButtonClickEvent) == RESET)
    {
    }
    /* Reset variable for next loop iteration */
    ubUserButtonClickEvent = RESET;

#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
    /* Set DAC voltage on channel corresponding to ADCx_CHANNELa              */
    /* in function of user button clicks count.                               */
    /* Set DAC output successively to:                                        */
    /*  - minimum of full range (0 <=> ground 0V)                             */
    /*  - 1/4 of full range (4095 <=> Vdda=3.3V): 1023 <=> 0.825V             */
    /*  - 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V              */
    /*  - 3/4 of full range (4095 <=> Vdda=3.3V): 3071 <=> 2.475V             */
    /*  - maximum of full range (4095 <=> Vdda=3.3V)                          */
    if (HAL_DAC_SetValue(&DacHandle,
                         DACx_CHANNEL_TO_ADCx_CHANNELa,
                         DAC_ALIGN_12B_R,
                         (RANGE_12BITS * ubUserButtonClickCount / USERBUTTON_CLICK_COUNT_MAX)
                        ) != HAL_OK)
    {
      /* Start Error */
      Error_Handler();
    }
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */

    /* Wait for DAC settling time */
    HAL_Delay(1);
    
    /* Start ADC conversion */
    /* Since sequencer is enabled in discontinuous mode, this will perform    */
    /* the conversion of the next rank in sequencer.                          */
    /* Note: For this example, conversion is triggered by software start,     */
    /*       therefore "HAL_ADC_Start()" must be called for each conversion.  */
    /*       Since DMA transfer has been initiated previously by function     */
    /*       "HAL_ADC_Start_DMA()", this function will keep DMA transfer      */
    /*       active.                                                          */
    HAL_ADC_Start(&AdcHandle);
      
    /* Wait for conversion completion before conditional check hereafter */
    HAL_ADC_PollForConversion(&AdcHandle, 1);
    
    /* Turn-on/off LED1 in function of ADC sequencer status */
    /* - Turn-off if sequencer has not yet converted all ranks */    
    /* - Turn-on if sequencer has converted all ranks */
    if (ubSequenceCompleted == RESET)
    {
      BSP_LED_Off(LED1);
    }
    else
    {
      BSP_LED_On(LED1);
      
      /* Computation of ADC conversions raw data to physical values */
      /* Note: ADC results are transferred into array "aADCxConvertedValues"  */
      /*       in the order of their rank in ADC sequencer.                   */
      uhADCChannelToDAC_mVolt    = COMPUTATION_DIGITAL_12BITS_TO_VOLTAGE(aADCxConvertedValues[0]);
      uhVrefInt_mVolt            = COMPUTATION_DIGITAL_12BITS_TO_VOLTAGE(aADCxConvertedValues[2]);
      wTemperature_DegreeCelsius = COMPUTATION_TEMPERATURE_STD_PARAMS(aADCxConvertedValues[1]);

      /* Reset variable for next loop iteration */
      ubSequenceCompleted = RESET;
    }
  }
}
Beispiel #26
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xB 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 64 MHz */
  SystemClock_Config();
  
  /*## Configure peripherals #################################################*/
  
  /* Initialize LED on board */
  BSP_LED_Init(LED2);
  
  /* Configure User push-button in Interrupt mode */
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);
  
  /* Configure the ADC peripheral */
  ADC_Config();
  
  /* Run the ADC calibration */  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }

#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Configure the TIM peripheral */
  TIM_Config();
#endif /* ADC_TRIGGER_FROM_TIMER */

  /* Note: This example, on some other STM32 boards, is performing            */
  /*       DAC configuration here.                                            */
  /*       On STM32F103RB-Nucleo, the device has no DAC available,            */
  /*       therefore analog signal must be supplied externally.               */

  /*## Enable peripherals ####################################################*/
#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Timer enable */
  if (HAL_TIM_Base_Start(&TimHandle) != HAL_OK)
  {
    /* Counter Enable Error */
    Error_Handler();
  }
#endif /* ADC_TRIGGER_FROM_TIMER */

  /* Note: This example, on some other STM32 boards, is performing            */
  /*       DAC signal generation here.                                        */
  /*       On STM32F103RB-Nucleo, the device has no DAC available,            */
  /*       therefore analog signal must be supplied externally.               */

  /*## Start ADC conversions #################################################*/
  
  /* Start ADC conversion on regular group with transfer by DMA */
  if (HAL_ADC_Start_DMA(&AdcHandle,
                        (uint32_t *)aADCxConvertedValues,
                        ADCCONVERTEDVALUES_BUFFER_SIZE
                       ) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
  
  
  /* Infinite loop */
  while (1)
  {
    /* Turn-on/off LED2 in function of ADC conversion result */
    /*  - Turn-off if voltage is into AWD window */ 
    /*  - Turn-on if voltage is out of AWD window */

    /* Variable of analog watchdog status is set into analog watchdog         */
    /* interrupt callback                                                     */
    if (ubAnalogWatchdogStatus == RESET)
    {
      BSP_LED_Off(LED2);
    }
    else
    {
      BSP_LED_On(LED2);
      
      /* Reset analog watchdog status for next loop iteration */
      ubAnalogWatchdogStatus = RESET;
    }
  
    /* For information: ADC conversion results are stored into array          */
    /* "aADCxConvertedValues" (for debug: check into watch window)            */
  
  
    /* Wait for event on push button to perform following actions */
    while ((ubUserButtonClickEvent) == RESET)
    {
    }
    /* Reset variable for next loop iteration */
    ubUserButtonClickEvent = RESET;

    /* Note: This example, on some other STM32 boards, is performing          */
    /*       DAC signal generation here.                                      */
    /*       On STM32F103RB-Nucleo, the device has no DAC available,          */
    /*       therefore analog signal must be supplied externally.             */
  }
}
Beispiel #27
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;
}
Beispiel #28
0
void TH_GUI (void const *argument) {
	static volatile uint16_t i=0;
	static uint16_t Triggered_Sample=0;	
	osEvent evt;
	GUI_MEMDEV_Handle hMem0;
	GUI_SelectLayer(0);
	hMem0 = GUI_MEMDEV_Create(0,0,480,272);
	
	if(!GUI_CURSOR_GetState())
		GUI_CURSOR_Select(&GUI_CursorCrossM);
	
	GUI_CURSOR_Show();
  while (1) {
																															Anal_CH1_Set(/*Main loop start*/);
																															Anal_CH2_Set(/*Wait start*/);
		evt = osSignalWait(DMA_ConvCpltSig,(uint32_t)2);
		if( evt.status == osEventTimeout)
				Error_Handler();
																															Anal_CH2_Reset(/*Wait finish*/);
		//osSignalSet(tid_Touch,GUI_TouchStateReqSig);
		
																															Anal_CH3_Set(/*Copy start*/);
		for(i=0;i<ADC_BUFFER_LENGTH;i++)	// <- Temporary. Take the full advantage of DMA !
		values_BUF[i]=255-values[i];
																															Anal_CH3_Reset(/*Copy finish*/);
		
		HAL_ADC_Start_DMA(&g_AdcHandle, values, ADC_BUFFER_LENGTH);
		osSignalClear(tid_TH_GUI, DMA_ConvCpltSig);
																															Anal_CH4_Set(/*Wait start*/);		
		osSignalWait(GUI_TouchGetSig,(uint32_t)0);
		GUI_CURSOR_SetPosition(g_Touched.pState->x,g_Touched.pState->y);
																															Anal_CH4_Reset(/*Wait finish*/);
		
		Trigger_Point = g_Touched.MSG;
		Triggered_Sample = Trigger(Trigger_Point, values_BUF, ADC_BUFFER_LENGTH, 1348000UL);
		//if(Triggered_Sample >=20)Triggered_Sample -=20; // Offset to see the edge in the center <- bullshit ?
		
		GUI_MEMDEV_Select(hMem0);
		GUI_MEMDEV_Clear(hMem0);
		
		GUI_SetColor(GUI_DARKGRAY);
		GUI_FillRect(0,0,480,272);
		
		GUI_SetColor(GUI_BLACK);
		GUI_DrawRect(34,5,474,266);		
		
		GUI_SetColor(GUI_WHITE);
		GUI_FillRect(35,6,475,266);
		
		Draw_GraphGrid(440,260,40,40);
		
		GUI_SetColor(GUI_BLUE);
		/*Draw garph start*/HAL_GPIO_TogglePin(GPIOI,GPIO_PIN_1);
		GUI_DrawGraph((short*)&values_BUF[Triggered_Sample],440,35,6); // Useful: GUI_COUNTOF(values)
		/*Draw garph finish*/HAL_GPIO_TogglePin(GPIOI,GPIO_PIN_1);
		
		GUI_SetColor(GUI_ORANGE);
		GUI_DrawHLine(Trigger_Point,0,480);
		GUI_FillCircle(15,Trigger_Point,10);
		
		GUI_SetColor(GUI_YELLOW);
		GUI_DrawCircle(15,Trigger_Point,10);
		
		GUI_MEMDEV_CopyToLCD(hMem0);
																															Anal_CH1_Reset(/*Main loop finish*/);
    osThreadYield ();                                           // suspend thread
  }
}
Beispiel #29
-1
void adcHandlerInit() {
	// The ADC should all be running by now

	HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_buffer[0],ADC_BUFFER_LEN);
	HAL_ADC_Start_DMA(&hadc2, (uint32_t *)adc_buffer[1],ADC_BUFFER_LEN);
	HAL_ADC_Start_DMA(&hadc3, (uint32_t *)adc_buffer[2],ADC_BUFFER_LEN);
}
Beispiel #30
-8
int main(void)
{

  /* USER CODE BEGIN 1 */
	char ADC_Tx_Data[70];
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */
	
	HAL_UART_Receive_IT(&huart1, (uint8_t *)Rx_Data, 1);
	HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&ADC_Value, 6);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		HAL_Delay(15);
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_4);
		HAL_Delay(15);
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_0);	
		HAL_Delay(15);
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_1);	
		HAL_Delay(15);
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);	
		HAL_Delay(15);		
	  sprintf(ADC_Tx_Data,"ADC1:%4d\tADC2:%4d\tADC3:%4d\tADC4:%4d\tADC5:%4d\tADC6:%4d\n\r", ADC_Value[0], ADC_Value[1], ADC_Value[2], ADC_Value[3], ADC_Value[4], ADC_Value[5]);
		HAL_UART_Transmit_IT(&huart1, (uint8_t *)ADC_Tx_Data, 70);
			
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}