I’m sorry for the long delay of responding the the answers you took the time to write.
Let me start of by saying that I am very novice in the area of DSP and I am after reading your answers begiining to think that I am way of base in my persuit.
What a timestamp should look like?.. well it’s suppose to be a value representing when the sample was read(duhh)… But I have perhaps overstated the importance of achiving this, I usually learn by doing and when I had set up a DMA assisted ADC transfer into Matlab I thought that timestamps is something that you always need to be accurate and from the begining I was simply exploring if the Due can be made to do this properly.
I don’t want to disable or delay the DMA transfer since I like the speed of samples but I had thought that maybe I can use as suddgested some interrupt, the DMA is triggered from a Interrupt and as such why could I not take the time by that same interrupt… But I’m not sure the interrupt might be End of RX buffer which could still work.
Even if you both havent aid it straight out I gather from your posts that timestamping might be pointless if I know that every second approximatly this many samples is generated and that I might be better of trusting that the samples is more ore less uniformly spaced over a lets say one second time period.
I know nothing of any implementation of timestamps so my request has been defined by my many assumptions which I am begining to realize that I had.
In any case the code I use is from the friendliness of a member here on the forum, its this:
// Arduino Due ADC->DMA->USB 1MSPS
// by stimmer
// from http://forum.arduino.cc/index.php?topic=137635.msg1136315#msg1136315
// 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
// Edited by David
#define n 256 // Buffer size
// LCD pin definitions:(though the LCD is not in use as it stands now)
#define RS 41
#define RW 43
#define E 45
#define D4 47
#define D5 49
#define D6 51
#define D7 53
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
volatile int bufn, obufn;
uint16_t buf[n]; // 4 buffers of 256 readings
void ADC_Handler() // move DMA pointers to next buffer
int f = ADC->ADC_ISR;
if (f & (1 << 27)) //f = ADC_ISR register, (1 << 27) = // ADC_ISR_ENDRX MASK
bufn = (bufn + 1) & 3;
ADC->ADC_RNPR = (uint32_t)buf[bufn];
ADC->ADC_RNCR = 256;
// Set LCD to Write mode(R/W pin to GND).
// set up the LCD's number of columns and rows:
// Enable external reference voltage ICs supply voltage.
// I have a REF2030 on a tiny PCB that sits in D13, GND , Vref(after resoldering the Vref jumper resistor).
pmc_enable_periph_clk(ID_ADC); // Enable ADC peripheral clock
adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST); // Initilize ADC
ADC->ADC_MR |= 0x80; // free running
ADC->ADC_CHER = 0x40; //CH7 = A0
NVIC_EnableIRQ(ADC_IRQn); // Enable ADC Interrupt Vector
ADC->ADC_IDR = 0xFFFFFFFF; //Disable all ADC interrupts alt. use ADC->ADC_IDR=~(1<<27);
ADC->ADC_IER = (1 << 27); // 27 = ADC_IER_ENDRX
ADC->ADC_RPR = (uint32_t)buf; // DMA Receive Pointer Register... Buffer
ADC->ADC_RCR = n; // DMA Receive counter Register... Buffer Size
ADC->ADC_RNPR = (uint32_t)buf; // DMA Receive Next Pointer Register... Buffer
ADC->ADC_RNCR = n; // DMA Receive Next counter Register... Buffer Size
bufn = obufn = 1;
ADC->ADC_PTCR = 1;
ADC->ADC_CR = 2;
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;
I have to get into how SAM3x’s timers work, about time but I am not comfortable with counters for some reason, ADD and programming is not o particularly good mix.
I might have missed to answer some of your posts but my mind is in a very volatile state but I will return to check you post again later today.
Untill the, have a nice day.