jbentham / rpi

Source code for the Raspberry Pi
108 stars 30 forks source link

Convert for streaming with the ADS7884 #6

Open BryceDrechselSmith opened 3 years ago

BryceDrechselSmith commented 3 years ago

Hello, I commented in your streaming code, but i realize that this is the more appropriate folder to comment in. I have successfully gotten this code (rpi_adc_dma_test.c) to capture at 2.5Msamples/sec and store into a .csv file. I am now trying to make this continuously stream the data into a FiFo, similar to your other code in "streaming." I am trying to accomplish this by implementing a ping-pong buffer in the function "adc_dma_samples_ads7884" (line 325), but have had no real luck thus far. This is my first experience with DMA, and as such I am not really familiar with what must be done to set this up. My assumption is that I will need to double the number of control blocks and add another buffer (B), so that while A is being written, B can be read and visa-versa. In looking at your streaming code (rpi_adc_stream.c) for the MCP3008 as a guide, it looks like this is what you are doing in "adc_dma_init" (lines 403+); using several control blocks to write to rxd1, and then several more to write to rxd2, with a few other control blocks used for timing. Since the ADS7884 doesn't take input and is controlled purely by clock cycles, I believe that the timing blocks are unnecessary (that I don't need a third channel for triggering PWM?) though I do need a way to switch between the two. Currently it looks like it is continuously reading from the buffer until it is empty (dma_wait(DMA_CHAN_A)). But I don't think that this method will work for continuous streaming...

I guess my questions are; are my above assumptions correct? what would you recommend in terms of timing/coordinating for the ping-pong buffer?

Once again, thank you so much for your time. I really appreciate the time you have taken already to write this code and its corresponding guide, as well as the time to respond to my previous questions.

Cheers, Bryce

jbentham commented 3 years ago

I think you're on the right lines, and can't think of anything specific to suggest, but in my experience continuous data streaming is remarkably difficult to achieve - not just obtaining the data, but also doing something useful with it, before the buffers overflow.

As an alternative to ping-pong buffers, you could just use a single buffer, and monitor the current DMA address to detect when there is a block of data to process. I haven't got around to testing this, to see if it makes matters better or worse. However if you want a buffer size over 64K you must use a non-LITE DMA channel, see the 'DMA LITE Engines' topic in the 'BCM2835 ARM Peripherals' document.

I'd question whether your target of 2.5 MS/s will be achievable in practice, and would start with a much lower figure, then see how high it can be pushed before things start to go wrong.

Jeremy Bentham

On 25/06/2021 20:40, BryceDrechselSmith wrote:

Hello, I commented in your streaming code, but i realize that this is the more appropriate folder to comment in. I have successfully gotten this code (rpi_adc_dma_test.c) to capture at 2.5Msamples/sec and store into a .csv file. I am now trying to make this continuously stream the data into a FiFo, similar to your other code in "streaming." I am trying to accomplish this by implementing a ping-pong buffer in the function "adc_dam_samples_ads7884" (line 325), but have had no real luck thus far. This is my first experience with DMA, and as such I am not really familiar with what must be done to set this up. My assumption is that I will need to double the number of control blocks and add another buffer (B), so that while A is being written, B can be read and visa-versa. In looking at your streaming code (rpi_adc_stream.c) for the MCP3008 as a guide, it looks like this is what you are doing in "adc_dma_init" (lines 403+); using several control blocks to write to rxd1, and then several more to write to rxd2, with a few other control blocks used for timing. Since the ADS7884 doesn't take input and is controlled purely by clock cycles, I believe that the timing blocks are unnecessary (that I don't need a third channel for triggering PWM?) though I do need a way to switch between the two. Currently it looks like it is continuously reading from the buffer until it is empty (dma_wait(DMA_CHAN_A)). But I don't think that this method will work for continuous streaming...

I guess my questions are; are my above assumptions correct? what would you recommend in terms of timing/coordinating for the ping-pong buffer?

Once again, thank you so much for your time. I really appreciate the time you have taken already to write this code and its corresponding guide, as well as the time to respond to my previous questions.

Cheers, Bryce

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbentham/rpi/issues/6, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACNUSES6HWOJUQBZFRNYODLTUTLUHANCNFSM47KOTPFQ.