2023-07-30 09:17 AM - edited 2023-07-31 12:55 AM
I saw a similar post here that is related to my problem. But unlike in this post, I want to read to adc channel inside a timer interrupt which has a sampling rate of 50KHz. How do I do it? I tried following this post and but adding start and stop adc insider the timer didn't work. The timer interrupt stopped working. So, is there any other way around or what is it that I am doing wrong? I don't have a code sample for this particular problem at the moment but if anyone could help me get started, I'd appreciate your help.
2023-07-30 08:22 PM
Hi, try using these keywords in searches:
https://www.google.com/search?q=stm32+adc+multi+channel+interrupt+example
2023-07-30 08:28 PM
Note that the STM32 has to have multiple ADCs, this model you mentioned seems to only have 1 ADC (1x 12bits ADC). It would have to read one channel (ANALOG PIN) at a time.
https://www.st.com/en/microcontrollers-microprocessors/stm32g071rb.html
2023-07-31 01:22 AM - edited 2023-07-31 01:25 AM
But it says, 16-channels like in DAC where it has 2 channels. I used two DAC channels successfully.
It should be able to read sequentially inside the timer, I assume? Maybe my question was a bit misleading. But thanks for the video, i did check it out and will try now. Hopefully, will work.
2023-07-31 01:40 AM
@RShre.2 wrote:But it says, 16-channels like in DAC where it has 2 channels. I used two DAC channels successfully.
It should be able to read sequentially inside the timer, I assume? Maybe my question was a bit misleading. But thanks for the video, i did check it out and will try now. Hopefully, will work.
I believe there was a mistake, DAC is used to input a Digital value and output an Analog value. When the input is Analog and the read value is Digital, the ADC is used.
This channel part is really confusing, but it's like this: there are 16 input channels, but only 1 ADC. So this STM32 model has to read one channel at a time. For example this image of 1 ADC and 8 input channels:
2023-07-31 01:51 AM
For example the STM32F405OE has 3 ADC and 24 channels. In this way it is possible to read 3 channels at the same time:
2023-07-31 01:55 AM
Hello @RShre.2,
First of all, I'm not in favor to start the ADC conversion inside a Timer interrupt. An interrupt must be as short as possible!
As you want to read the ADC->DR register inside the timer interrupt, I understand the conversion is already done, doesn't it?
The easiest way is to trigger a DMA transfer from ADC->DR to memory based on timer. In case of multiple channels, the best way will remain also to transfer all data by DMA configured in circular mode.
Best Regards,
Gwénolé
2023-07-31 02:35 AM - edited 2023-07-31 02:45 AM
2023-07-31 02:39 AM
Hmm okay.
As i understand these three adcs can read values simulatenously.
In my case, it's fine for me if the same adc with two different channels read values sequentially because I assume the HAL get value is fast enough that i can read two values within 50KHz. If that's possible, but when I tried that it's giving me weird value as I posted in another comment.
If this is unavoidable with my stm then I have no other choice than drop this idea.
2023-07-31 02:57 AM
Hi,
I'll try on my side and propose you a solution that can fit with your need.
I keep in you in touch,
Best Regards,
Gwénolé