cancel
Showing results for 
Search instead for 
Did you mean: 

Sequence of 4 measurements using ADC1

bolurian
Associate II

I was unable to configure ADC1 to measure a "4 channel sequence" and then generate an interrupt.

I am using the injected result registers to read the values in the ISR.

Adc_Value[0]= ADC1->JDR1;

Adc_Value[1]= ADC1->JDR2;

Adc_Value[2]= ADC1->JDR3;

Adc_Value[3]= ADC1->JDR4;

All values show zero!

 Can anyone provide an example code for reading injected results + interrupt?

Alternatively the DMA may be used, but when I try to use regular/non injected results via DMA, I am not able to generate an interrupt anymore!

 The sequence is triggered by TIM1 at every 15.8 uS.

11 REPLIES 11
Sarra.S
ST Employee

Hello @bolurian

Please check AN3116, paragraph "injected conversion mode", also check the related firmware example " Indep_InjectedGroup"   

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Sarra,

Could you please point me to "Indep_InjectedGroup" firmware example?

Where do I find it?

Thanks,

Yitzhak

ofc, here is the link to the software 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

bolurian
Associate II

This code is using APIs/Functions that are not compatible with my project/code.

Any code example that is compatible with the recent Cube MX/Cube IDE code?

 

 

AScha.3
Chief II

Just you want results every 15,8 us, so about 300000 data per second - right?

What you want to do with this amount of data?

If you just do anything with the data, your CPU would have no time to do anything else.

If you feel a post has answered your question, please click "Accept as Solution".
bolurian
Associate II

253164 results to be exact.

We do not really have to use all 4 measurement each 15.8 uS.
But let's address that later. The ADC should be able to do this.

Let's even think that the sample rate is slower.

 

Ok, should be possible;  on what G4 ?

+ can you attach your x.ioc ? (maybe as zip, if forum still not "allowed" ioc )

If you feel a post has answered your question, please click "Accept as Solution".
bolurian
Associate II

Yes, STM32G474

setup adc1 :

AScha3_0-1705434661995.png

then try to start it:

 

  MX_ADC1_Init();
  MX_TIM1_Init();
  /* USER CODE BEGIN 2 */

  HAL_ADCEx_Calibration_Start(&hadc1);			// adc1 kalib.
  HAL_Delay(2);						// wait a little
  HAL_ADCEx_InjectedStart_IT(&hadc1);			// start adc for int mode
  HAL_TIM_Base_Start(&htim1);				// Trigger ADCs
  
  
  /* USER CODE END 2 */

 

-> then set breakpoint in adc int , check results in debug mode...

If you feel a post has answered your question, please click "Accept as Solution".