arduino-libraries / Arduino_AdvancedAnalog

Advanced Analog Library
GNU Lesser General Public License v2.1
7 stars 5 forks source link

Adding Interleaved Sampling for 2X Sample Rate improvement #68

Open jmdodd95682 opened 3 months ago

jmdodd95682 commented 3 months ago

Looking through the Reference Manual for the STM32H7xx I see there is another Dual mode called Interleaved. It seems likely that by putting an input signal into two Analog Input pins (e.g. A0 and A1) and enabling Dual interleaved mode it will be possible to sample at twice the current maximum rate. So, instead of say 2.9MS/sec we can reach 5.8MS/sec at 16b resolution.

Also, one can also enable a single DMA to handle this dual interleaved data so that all the captured data needs to re-arranging once retrieved from the DMA buffers.

I'm going to try some experiments and see if it works.

iabdalkader commented 3 months ago

Also, one can also enable a single DMA to handle this dual interleaved data so that all the captured data needs to re-arranging once retrieved from the DMA buffers.

Yes a single DMA channel can be used in all dual modes, to read the combined sample register. However, I read on the forums that this may be broken, the two halves of the register go out of sync, and more importantly, I don't think we'll be able to reuse the code that we have. So I think this is secondary, not very high priority improvement.

I see there is another Dual mode called Interleaved.

You can add a mode argument to ADCDual, and implement more modes if you like.

jmdodd95682 commented 3 months ago

Good to know about the DMA. I'll check it out. If not then there's a little reassembly to do after capture, but it's not bad.

Yes I was thinking to add this feature to AdvancedADCDual.


From: Ibrahim Abdelkader @.> Sent: Thursday, March 28, 2024 3:01:02 AM To: arduino-libraries/Arduino_AdvancedAnalog @.> Cc: jmdodd95682 @.>; Author @.> Subject: Re: [arduino-libraries/Arduino_AdvancedAnalog] Adding Interleaved Sampling for 2X Sample Rate improvement (Issue #68)

Also, one can also enable a single DMA to handle this dual interleaved data so that all the captured data needs to re-arranging once retrieved from the DMA buffers.

Yes a single DMA channel can be used in all dual modes, to read the combined sample register. However, I read on the forums that this may be broken, the two halves of the register go out of sync, and more importantly, I don't think we'll be able to reuse the code that we have. So I think this is secondary, not very high priority improvement.

I see there is another Dual mode called Interleaved.

You can add a mode argument to ADCDual, and implement more modes if you like.

— Reply to this email directly, view it on GitHubhttps://github.com/arduino-libraries/Arduino_AdvancedAnalog/issues/68#issuecomment-2024818147, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALCX2KH5BUP5LHFVG54RTLLY2PS55AVCNFSM6AAAAABFLHHHKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRUHAYTQMJUG4. You are receiving this because you authored the thread.Message ID: @.***>

jmdodd95682 commented 3 months ago

I have the 2x sample rate using interleaved Dual mode working. I can now sample up to 9.2MS/sec at 8b resolution (5.8MS/sec @ 16b res). I want to do more testing before I do a pull request. I would also like to test the unified DMA which, as you said, probably will not work reliably.

Very cool though. I should be able to make a pretty good capture scope app with this.

iabdalkader commented 3 months ago

Thanks @jmdodd95682 excellent work!

. I would also like to test the unified DMA which, as you said, probably will not work reliably.

For reference, here's the post that mentions that issue: https://community.st.com/t5/stm32-mcus-products/stm32h7-adc-dual-mode-simultanious-mode-problem/td-p/294976