Dear Youngtae Jo, thanks for your kindness on sharing your code. It pushed me to finally obtain some results.
However there are certain points that you need to take care on your code. I will try to list at least most of them here:
-
you haven’t set anything to the ADC_CLKDIV register. On my BBB, this register is set to 7 by default, so the ADC Clock turns out to be 24MHz/(7+1) = 3 MHz, and the PRU’s clock is not a multiple of it. So I suggest to set the ADC_CLKDIV to something that divides the 24 MHz by 3 (2, 5, 11…). Check the SPRUH73L guide for more information on this register.
-
your code will only work with the PRU0 because of the way things are defined in the .hp file. I know you got it from the am335x github, but I believe they didn’t make a good job on that header file. You can read more about this problem here.
-
that offset has no reason, I know it was also taken by the am335x github file, but I believe they made that for pedagogical reasons only, as it is an example so they are showing possibilities. I would set the C28 register to 0x100 so that it will point to the first shared memory address (0x10000). Once that’s done you can take rid of the offsets in the C code.
-
your calculation on the number of loops is wrong. If you know the sampling frequency, then you need the time step between two samples, then you know how many 5 ns instructions fit on it. Finally divide it by 2, as you did, as every loop takes 2 instructions.
-
I believe that anyone coding an ADC capture in assembly is really looking for some time precision, so you’d need to count every single instruction you make outside of the delay loop and compensate that many instructions in the loop. That’s a tedious job as you need to make the number of instructions even, and make that number be the same no matter where the code jumps to.
-
you have used bone_capemgr.8 but that could vary, and it does, as on my BBB that number is 9.
-
according to the SPRUH73L guide, the Enabled bit from the CTRL register must be set only after all the steps configs are set.
-
the first “sample” on the Results.txt file is actually the buffer flag, I suggest to remove the first line to avoid misreadings.
-
you have some divisions in your numerical defines, I don’t recommend that because one may have a numerator which is not a multiple of the denominator and then he’ll lose precision.
-
I suggest a complete restructure of the communication between the C code and the P code, so that you don’t have to manually edit each parameter twice. Sampling frequency, buffer size, you know…
-
less important, but it would be great if you defined a register to contain the ADC_TSC base register, and then define the offsets of the others. It would have made your code more readable and flexible.
-
you don’t need to define PRUSS0_SHARED_DATARAM because it already exists with that name in the pruss headers.
-
you don’t need the ProcessingADC1 function. According to the SPRUH73L guide, the channel number will be printed together only if bit 1 is set, which is not the case.
-
you can tune your code to use 16 bits for each sample, but as you are using two buffers it doesn’t seem to matter here.
Well those are some of the points that I dedicated for my final work and I decided to share with you as your code reeeally helped to go ahead.
Thank you very much!