what kind of language is it, it does not look like the regular C

here is a link

I see you can do a lot with the codes like speeding DMA access or ADC

where can I learn some of the coding ? I do not know even the name of the language

Post a sample of the code here!

Mark

It's C / C++, probably using pre-defined processor register names.

the second file is python (.py)

here is the code, I do not understand it (know some C), but it is very interesting it allows to sample with 1MSPS

would you know how to put the data into array instead of sending to USB port. Like making array[1000] so it can be access later but simpler C code. like declaring first int myArray[1000]; and using it to put the data at that speed, I mean every 1 us.

#undef HID_ENABLED

// Arduino Due ADC->DMA->USB 1MSPS
// by stimmer
// from speed of analogRead - #7 by stimmer - Arduino Due - Arduino Forum
// Input: Analog in A0
// Output: Raw stream of uint16_t in range 0-4095 on Native USB Serial/ACM

// on linux, to stop the OS cooking your data:
// stty -F /dev/ttyACM0 raw -iexten -echo -echoe -echok -echoctl -echoke -onlcr

volatile int bufn,obufn;
uint16_t buf[4][256]; // 4 buffers of 256 readings

void ADC_Handler(){ // move DMA pointers to next buffer
int f=ADC->ADC_ISR;
if (f&(1<<27)){
bufn=(bufn+1)&3;
ADC->ADC_RNPR=(uint32_t)buf[bufn];
ADC->ADC_RNCR=256;
}
}

void setup(){
SerialUSB.begin(0);
while(!SerialUSB);
pmc_enable_periph_clk(ID_ADC);
adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST);
ADC->ADC_MR |=0x80; // free running

ADC->ADC_CHER=0x80;

NVIC_EnableIRQ(ADC_IRQn);
ADC->ADC_IDR=~(1<<27);
ADC->ADC_IER=1<<27;
ADC->ADC_RPR=(uint32_t)buf[0]; // DMA buffer
ADC->ADC_RCR=256;
ADC->ADC_RNPR=(uint32_t)buf[1]; // next DMA buffer
ADC->ADC_RNCR=256;
bufn=obufn=1;
ADC->ADC_PTCR=1;
ADC->ADC_CR=2;
}

void loop(){
while(obufn==bufn); // wait for buffer to be full
SerialUSB.write((uint8_t *)buf[obufn],512); // send it - 512 bytes = 256 uint16_t
obufn=(obufn+1)&3;
}

Grab yourself the datasheet for the processor on the Due:
http://www.atmel.com/Images/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf
and start learning what all those register accesses do.

would you know how to put the data into array instead of sending to USB port.

That code already puts the data in an array. If you don't want to send it to the serial port, don't.

this code is regular C++ used in Arduino ino file. what part looks strange for you?

The code is regular C/C++, with the exception that Aurduino.h is automatically included, and certain forward declarations are automatically generated. The include pulls in type.h and some other standard C include files. It also predefines a number of constants specific to the arduino environment, which you need to know about if you want to understand what a sketch is doing.

Perhaps the other main difference is that a main() function is provided by the environment, and it performs certain hardware initialisations and then calls setup() and then calls loop() repeatedly. That is: setup() and loop() are the entry points into the sketch, rather than main().

You need to know the API, but the language is C++ compiled with the gcc compiler.

PaulS:
That code already puts the data in an array. If you don't want to send it to the serial port, don't.

I know that the data collected from A0 pin goes into memory, I just cannot figure out the coding.

Can I transfer the data later for example into array, making sure it does not slow the sampling rate.

if I declare array like this.

int myArray[2000];

how do I put the data into myArray[1], myArray[2], ....., myArray[2000]

thanks

As you can see by reading stimmer's code, he declares 4 consecutive buffers : uint16_t buf[4][256]; then the PDC DMA (Direct Memory Address) fills 256 samples in the first one buf[0], and before the end of the first buffer, the address of the second one is passed to the PDC DMA into ADC_Handler() to prepare for the filling of the second one, and so on....The process of a PDC DMA is not obvious at first sight.

Now if you want to keep the 256 samplings of buffer[0] before it is overriden, you can store them elswhere into the SRAM, or an EEPROM or the Flash (DUEFlashStorage lib) depending on the amount of data you want to keep.
Do that in loop(), instead of a SerialUSB.Write().

As already stated, the best place to learn is the SAM3X datasheet. Even though the SAM3X datasheet is ~1400 pages, reading through it is the best way to learn how to use it. It's intimidating, but as you go from chapter to chapter you will see that there are a lot of similarities in the way peripherals are setup and used.

I got this datasheet downloaded but going over 1400 pages takes time, something I am planning to do.

once I have my array declared how do I move the data from buffer

the problem is storing in RAM for example, and how do I access it later to make the array.

I want to do this without slowing the sampling rate

now I understand that uint16_t buf[4][256] gives me 1000 samples, can I increase it to give me 2000 or 4000 samples for example uint16_t buf[4][1024]

A memcpy() should do the job, copy 256 samples by 256 samples. A more sophisticated solution would require an AHB DMA to copy, without core clock cycles, a buffer into another one:

I wonder why he did uint16_t buf[4][256], it this limitation of the buffer ? can I store more ?

I am reading the datasheet, nothing there so far.

it is rather complicated code when you are just beginner.

A DUE has 96 KBytes of SRAM, so yes you can extend the size of buffers.

thanks for the help I heard about the buffers , DMA etc but I have no clue about the coding.

I have to find a way to write each reading into array so I can manipulate it later with the C coding I know

looks like I just might need a few lines of code to do this.