I successfully used one ADC to measure 4 analog signals by switching between them in a round robin fashion.
Now, I want to extend this to use the second adc on the Teensy 3.1 and capture 8 analog signals.
I tried the straightforward method of duplicating my dma and adc definitions as follows;
DMA setup:
ADC setup:
Interrupt routines:
Channel configurations (pin numbers):
Completely symmetrical.
Unfortunately I am only able to record the analog signals coming from adc0.
Here is a plot of the captured signals:
ch 1,2,3,4 are coming from adc0 and ch 5,6,7,8 are samples from adc1.
So channel 4,5,6,7 show a signal that seems to be grounded, but this seems weird because the reference is 1.2V.
Does anyone have an idea about what I am doing wrong here?
Thanks in advance
Now, I want to extend this to use the second adc on the Teensy 3.1 and capture 8 analog signals.
I tried the straightforward method of duplicating my dma and adc definitions as follows;
DMA setup:
Code:
void setup_dma() {
dma0->begin(true); // allocate the DMA channel
dma0->TCD->SADDR = &ADC0_RA; // where to read from
dma0->TCD->SOFF = 0; // source increment each transfer
dma0->TCD->ATTR = 0x101;
dma0->TCD->NBYTES = 2; // bytes per transfer
dma0->TCD->SLAST = 0;
dma0->TCD->DADDR = &adcbuffer_0[0][0];// where to write to
dma0->TCD->DOFF = 2;
dma0->TCD->DLASTSGA = -2*BUF_SIZE;
dma0->TCD->BITER = BUF_SIZE;
dma0->TCD->CITER = BUF_SIZE;
dma0->triggerAtHardwareEvent(DMAMUX_SOURCE_ADC0);
dma0->disableOnCompletion(); // require restart in code
dma0->interruptAtCompletion();
dma0->attachInterrupt(dma0_isr);
dma1->begin(true); // allocate the DMA channel
dma1->TCD->SADDR = &ChannelsCfg_0[0];
dma1->TCD->SOFF = 2; // source increment each transfer
dma1->TCD->ATTR = 0x101;
dma1->TCD->SLAST = -8;
dma1->TCD->BITER = 4;
dma1->TCD->CITER = 4;
dma1->TCD->DADDR = &ADC0_SC1A;
dma1->TCD->DLASTSGA = 0;
dma1->TCD->NBYTES = 2;
dma1->TCD->DOFF = 0;
dma1->triggerAtTransfersOf(*dma0);
dma1->triggerAtCompletionOf(*dma0);
dma2->begin(true); // allocate the DMA channel
dma2->TCD->SADDR = &ADC1_RA; // where to read from
dma2->TCD->SOFF = 0; // source increment each transfer
dma2->TCD->ATTR = 0x101;
dma2->TCD->NBYTES = 2; // bytes per transfer
dma2->TCD->SLAST = 0;
dma2->TCD->DADDR = &adcbuffer_1[0][0];// where to write to
dma2->TCD->DOFF = 2;
dma2->TCD->DLASTSGA = -2*BUF_SIZE;
dma2->TCD->BITER = BUF_SIZE;
dma2->TCD->CITER = BUF_SIZE;
dma2->triggerAtHardwareEvent(DMAMUX_SOURCE_ADC1);
dma2->disableOnCompletion(); // require restart in code
dma2->interruptAtCompletion();
dma2->attachInterrupt(dma2_isr);
dma3->begin(true); // allocate the DMA channel
dma3->TCD->SADDR = &ChannelsCfg_1[0];
dma3->TCD->SOFF = 2; // source increment each transfer
dma3->TCD->ATTR = 0x101;
dma3->TCD->SLAST = -8;
dma3->TCD->BITER = 4;
dma3->TCD->CITER = 4;
dma3->TCD->DADDR = &ADC1_SC1A;
dma3->TCD->DLASTSGA = 0;
dma3->TCD->NBYTES = 2;
dma3->TCD->DOFF = 0;
dma3->triggerAtTransfersOf(*dma2);
dma3->triggerAtCompletionOf(*dma2);
dma0->enable();
dma1->enable();
dma2->enable();
dma3->enable();
}
ADC setup:
Code:
void setup_adc() {
adc->adc0->setResolution(16); // set bits of resolution
adc->adc1->setReference(INTERNAL);
adc->adc0->setResolution(16); // set bits of resolution
adc->adc1->setReference(INTERNAL);
adc->adc0->enableDMA();
adc->adc1->enableDMA();
ADC0_SC1A = ChannelsCfg_0[3];
ADC1_SC1A = ChannelsCfg_1[3];
}
Interrupt routines:
Code:
void dma0_isr(void) {
ibuf_0=(ibuf_0+1) % NO_BUFFERS;
dma0->TCD->DADDR = &adcbuffer_0[ibuf_0][0];
dma0->clearInterrupt();
dma0->enable();
}
void dma2_isr(void) {
ibuf_1=(ibuf_1+1) % NO_BUFFERS;
dma2->TCD->DADDR = &adcbuffer_1[ibuf_1][0];
dma2->clearInterrupt();
dma2->enable();
}
Channel configurations (pin numbers):
Code:
const uint16_t ChannelsCfg_0 [] = { 0x46, 0x47, 0x4F, 0x44 };
const uint16_t ChannelsCfg_1 [] = { 0x44, 0x45, 0x46, 0x47 };
Completely symmetrical.
Unfortunately I am only able to record the analog signals coming from adc0.
Here is a plot of the captured signals:
ch 1,2,3,4 are coming from adc0 and ch 5,6,7,8 are samples from adc1.
So channel 4,5,6,7 show a signal that seems to be grounded, but this seems weird because the reference is 1.2V.
Does anyone have an idea about what I am doing wrong here?
Thanks in advance
Last edited: