ADC1BUFx Undeclared Error

Thread Starter

Harnee15

Joined Sep 14, 2015
24
Hello everyone,

I need some help with the ADC configuration of the dspic33fj128mc804 . I'm trying to configure ADC for 8 analog inputs such that they are sampled by one S&H channel CH0 (As given in 16.10.2 of data sheet). The problem I'm having is that when I try to read the result ADC1BUF1 ,ADC1BUF2..... ADC1BUF7, the program doesn't builds and the error shown is that all these buffers are undeclared.

Could anyone please help me with this? Any feedback is much appreciated!!

Many Thanks.


void initadc(void)
{
AD1PCFGL =0xff00;
AD1CSSL=0x00ff;
AD1CHS0=0;
AD1CON4=0;
AD1CON3=0x8001;
AD1CON2=0x0420;
AD1CON1=0x8406;// ASAM=1, SIMSAM=0
}


void __attribute__((auto_psv)) _AD1Interrupt(void)
{

adResults[0]=ADC1BUF1;//save
adResults[1]=ADC1BUF1;
adResults[2]=ADC1BUF2;
adResults[3]=ADC1BUF3;
adResults[4]=ADC1BUF4;
adResults[5]=ADC1BUF5;
adResults[6]=ADC1BUF6;
adResults[7]=ADC1BUF7;
shouldWriteResults =1;//set flag.

}
 

Thread Starter

Harnee15

Joined Sep 14, 2015
24
Have followed all the steps stated in the data sheet . I can access AD1BUF0 but not any other buffer. So I'm not sure about the problem.
 

nsaspook

Joined Aug 27, 2009
6,729
@nsaspook- I'm not using DMA. I'm following section 16.10.2 of the data sheet
On chips with a DMA module (enabled or not) ADCxBUF0 is all you have. You can learn how to use DMA or copy ADCxBUF0 to your application buffers after every conversion.


The ADC module contains a single-word, read-only, dual-port register (ADCxBUF0), which stores the A/D conversion result. If more than one conversion result needs to be buffered before triggering an interrupt, DMA data transfers can be used. Both ADC channels (ADC1 and ADC2) can trigger a DMA data transfer. Depending on which ADC channel is selected as the DMA IRQ source, a DMA transfer occurs when the ADC Conversion Complete Interrupt Flag Status (AD1IF or AD2IF) bit in the Interrupt Flag Status Register (IFS0 or IFS1, respectively) in the Interrupt Module gets set as a result of a sample conversion sequence. The result of every A/D conversion is stored in the ADCxBUF0 register. If a DMA channel is not enabled for the ADC module, each result should be read by the user application before it gets overwritten by the next conversion result. However, if DMA is enabled, multiple conversion results can be automatically transferred from ADCxBUF0 to a user-defined buffer in the DMA RAM area. Thus, the application can process several conversion results with minimal software overhead.
 
Last edited:

Thread Starter

Harnee15

Joined Sep 14, 2015
24
On chips with a DMA module (enabled or not) ADCxBUF0 is all you have. You can learn how to use DMA or copy ADCxBUF0 to your application buffers after every conversion.
In the data sheet it is mentioned as below. So, I reckon everything goes in different buffer.


Screen Shot 2016-03-26 at 20.02.45.png
 

dannyf

Joined Sep 13, 2015
2,197
It pays to read the datasheet a little bit more, :).

When you set up the dma, you can simply point the transfer address to your buffer and you are done - no need to even move the data out of the buffer.
 
Top