hello Mrs ,
i m working on ADC sampling with Arduino due , the ADC is triggered with TC at 13.2khz
the audio signal to be sampled at A0 is an FSK signal with f1=1.2khz and f2=2.2khz , i need to recover samples in the main loop to process them , but received sample from serial port are not correctly sampled (i dont obtein my sent signal) ,
the signal apear like aliasing (the ADC samples at lower frequency than 13.2khz ) but i dont know why ?? here is the code :any help please slight_smile:
the code is :volatile int bufn,obufn;
uint16_t buf[2][1024]; // 4 buffers of 256 readings
void ADC_Handler(){
int f=ADC->ADC_ISR;
if (f&(1<<27)){
bufn=(bufn+1)&1;
ADC->ADC_RNPR=(uint32_t)buf[bufn];
ADC->ADC_RNCR=1024;
}
}
//
void setup() {
//
Serial.begin(19200);
pmc_enable_periph_clk (TC_INTERFACE_ID + 0*3+0) ; // clock the TC0 channel 0
TcChannel * t = &(TC0->TC_CHANNEL)[0] ; // pointer to TC0 registers for its channel 0
t->TC_CCR = TC_CCR_CLKDIS ; // disable internal clocking while setup regs
t->TC_IDR = 0xFFFFFFFF ; // disable interrupts
t->TC_SR ; // read int status reg to clear pending
t->TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 | // use TCLK1 (prescale by 2, = 42MHz)
TC_CMR_WAVE | // waveform mode
TC_CMR_WAVSEL_UP_RC | // count-up PWM using RC as threshold
TC_CMR_EEVT_XC0 | // Set external events from XC0 (this setup TIOB as output)
TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_CLEAR |
TC_CMR_BCPB_CLEAR | TC_CMR_BCPC_CLEAR ;
t->TC_RC = 3182 ; // counter resets on RC, so sets period in terms of13200hz
t->TC_RA = 1591 ; // roughly square wave
t->TC_CMR = (t->TC_CMR & 0xFFF0FFFF) | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET ; // set clear and set from RA and RC compares
t->TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG ; // re-enable local clocking and switch to hardware trigger source.
NVIC_EnableIRQ(ADC_IRQn);
ADC->ADC_CHDR = 0xFFFF ; // disable all channels
ADC->ADC_CHER = 0x80 ; // enable just A0
ADC->ADC_CGR = 0x15555555 ; // All gains set to x1
ADC->ADC_COR = 0x00000000 ; // All offsets off
ADC->ADC_MR = (ADC->ADC_MR & 0xFFFFFFF0)| (1 << 1) | ADC_MR_TRGEN; // 1 = trig source TIO from TC0
ADC->ADC_IDR=~(1<<27);
ADC->ADC_IER=1<<27;
ADC->ADC_RPR=(uint32_t)buf[0]; // DMA buffer
ADC->ADC_RCR=1024;
ADC->ADC_RNPR=(uint32_t)buf[1]; // next DMA buffer
ADC->ADC_RNCR=1024;
bufn=1;
obufn=0;
ADC->ADC_PTCR |= ADC_PTCR_RXTEN; // Enable PDC Receiver channel request
ADC->ADC_CR = ADC_CR_START;
//
}
//
void loop(){
while((obufn + 1)%2==bufn);// wait for buffer to be full
obufn=(obufn+1)&1;
Serial.println(*buf[obufn]); // send it
}

