Hi I using this code to read from ADC (A0 channel 7):
val = *(ADC->ADC_CDR + 7) ;
This is where the conversion resulte is.
I am trying now to read from 2 diffrent channels. This is because I need to sample to diffrent signals (at the same time).
I have tried to understand how to read from two channels one after another but I dont understand how can I do it.
what I have now is:
I am using timer for sampling frequency, then at (EOF - End Of Conversion) I get an interrupt, then I read from the ADC using the code above the sample.
I dont understand the names of different channels and unfortunately I dont know were I can find it.
I want to use A1 also (that is Channel 6), but how can I read from both of them. And as far as I understand, when more then one channel is active then the ADC speed will increed.
I have written the code so that on EOC (End Of Conversion) of channel 7 I will receive an interrupt, can I at the same interrupt read from to different channels? like:
Val_1 = ADC->ADC_CDR[7];
Val_2 = ADC->ADC_CDR[6];
I have written the code so I can sample at the rate of 12kHz using timer.
Do I need to change the sample rate then?
This is the code that is being executed when the EOC occurs:
void ADC_Handler (void)
{
if (ADC->ADC_ISR & ADC_ISR_EOC7) // ensure there was an End-of-Conversion and we read the ISR reg
{
val = *(ADC->ADC_CDR + 7) ; // get conversion result
samples [sptr] = val ; // stick in circular buffer
sptr = (sptr+1) & BUFMASK ; // move pointer
EOC_flag = true;
}
}
If you trigger conversions thru a timer, the ADC peripheral will automatically multiply the timer frequency by the number of channel conversions (up to 1 Msps).
// Timer Counter (TC)
void ADC_Timer_Setup(int Frequency){
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
// The pointer is used insted of writing: TC0->TC_CHANNEL[0], I can write: t->
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
// In Waveform Mode TIOB is set as output
t->TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK4 | // use TCLK4 (prescale by 128, = 656.25kHz)
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 = 0x080; // 0x80 = 5.126kHz
t->TC_RA = 80; // setup time for next itteration
t->TC_CMR = (t->TC_CMR & 0xFFF0FFFF) | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET ; // set clear and set from RA and RC compares
// re-enable local clocking and switch to hardware trigger source.
t->TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG ;
}
And just to clarify:
If let say I setup the timer with a frequency of 12kHz, using two channels would multiply this setting.
What I would like to know and filed to find is who will the ADC sample from two channels? (using the EOC interrupt)
For example if I work with the timer with a frequency of 12kHz, Two channel -> double the frequency of the time; will the ADC firts after 12kHz sample A0 and after another 12kHz it will sample A1, then again after 12kHz it will sample A0 and so... ?
OR
It will sample A0, the immediately it will sample A1 ..... ?