Skip to main content
Associate II
January 8, 2024
Question

Sequence of 4 measurements using ADC1

  • January 8, 2024
  • 6 replies
  • 3121 views

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.

6 replies

ST Employee
January 10, 2024

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.
bolurianAuthor
Associate II
January 10, 2024

Hi Sarra,

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

Where do I find it?

Thanks,

Yitzhak

ST Employee
January 11, 2024

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.
bolurianAuthor
Associate II
January 16, 2024

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
Super User
January 16, 2024

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""."
bolurianAuthor
Associate II
January 16, 2024

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.

 

AScha.3
Super User
January 16, 2024

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""."
bolurianAuthor
Associate II
January 16, 2024

Yes, STM32G474

AScha.3
Super User
January 16, 2024

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""."
bolurianAuthor
Associate II
January 16, 2024

Is this configuration setting both regular and injected results?

But the regular conversion has only one result register!

Which result register do I read my 4 results from?

AScha.3
Super User
January 16, 2024

read again ... i edit -> start injected . :)

regular is set : disabled.

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