2

Following an impressive write-up in MagPi 32,there has been other write-ups for better parallel ADC control from a Raspberry Pi. It appears that the ADC can be driven by Raspberry on-board clock at 40MHz+, but the software side is a bottleneck, limited by a memcopy. Namely, the bottleneck operation in the driver / module code is this step:

//taking samples
while(counter<SAMPLE_SIZE){
    dataStruct.Buffer[counter++]= *(gpio.addr + 13); 
}

This, on a raspberry pi zero for example, enables sampling at 12MHz, whatever the speed of the clock itself. This is a practical bottleneck.

Would there be any way to accelerate this software memcpy, so to in practice boost the speed of gpio reading?

2

I don't see the point in using memcpy. This is a read of a 32-bit word which could be achieved by a simple assignment.

Neither do I see the point of speeding up this part of the software chain. It will be swamped in time by the bit manipulations needed to map the used GPIO to a binary value. E.g. if an ADC returns the reading on 6 GPIO they will need to shifted and separatley extracted (unless contiguous GPIO are used).

  • 1
    A plausible example reason for doing this could be to read some data very fast (e.g. a high frequency signal) and then process it later,for example as a software oscilloscope. – Mark Smith Oct 6 '17 at 20:36
  • 1
    @joan OP is overloading terms, he is using asignment, but calling it "memcopy" – crasic Oct 6 '17 at 20:44
  • @crasic I'd expect the code to be implemented as an assignment given that the 32-bit quantities are almost certain to be aligned. I suppose a memcpy could be done instead if the compiler thought the data wasn't aligned. – joan Oct 6 '17 at 21:05
  • Sure, but my point is that the example code in the question uses assignment, the reference to "memcopy", appears to be a description for assignment and not in reference to memcpy the standard library function. – crasic Oct 6 '17 at 21:08
  • This is correct, this is to obtain bursts of acquisitions with the pi. The code is within the module, in a no-interrupt loop. However, @Joan, the processing of this 32 bit word occurs after the acquisition. – Kelu124 Oct 8 '17 at 7:31
0

Short Answer: No, this type of data copy is quite fast, probably 2 ops per cycle, this is practically as fast as the core can move data around. To convince yourself, just look at the disassembly.

Additionally, There is no way, that you will get the full throughput you desire from a kernel module, there is too much stuff happening in linux kernel constantly. Your limit will be CPU scheduling for the module code to execute and not the read speed of the module itself. You would need to run real time kernel or baremetal code.

Note: By Parallel ADC I'm assuming you are referring to an ADC constructed from a resistor network using GPIO ports of the raspberry pi.


Other Answer: You are chasing a ghost, 12MHz sampling with a simple ADC like this is unphysical, the electrical response of the A/D circuit is probably in the KHz at most.

I will challenge your assertion

but the software side is a bottleneck

Disagree, there is a glaring electrical bottle neck. No way your simple ADC will respond at 40MHZ or even 12MHZ.

Remember the step response of your ADC is limited by RC time constant. You should estimate this first as it determines the a practical max sampling rate. A resistor based ADC is a massive Capacitance beast, this time constant will be very large and limit your response to significantly less than a MHz.

Put another way, the ADC acts (and IS!) a Low Pass Filter and a 12MHZ sampling rate is unrealistic. Dedicated ADC's designed to run at those rates are beasts that require careful electrical routing and signal conditioning.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.