ADC1BUFx Undeclared Error

Discussion in 'Embedded Systems and Microcontrollers' started by Harnee15, Mar 26, 2016.

  1. Harnee15

    Thread Starter New Member

    Sep 14, 2015
    24
    0
    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.

    }
     
  2. dannyf

    Well-Known Member

    Sep 13, 2015
    1,818
    362
    What does the datasheet say about that?
     
  3. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,169
    Last edited: Mar 26, 2016
  4. Harnee15

    Thread Starter New Member

    Sep 14, 2015
    24
    0
    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.
     
  5. Harnee15

    Thread Starter New Member

    Sep 14, 2015
    24
    0
    @nsaspook- I'm not using DMA. I'm following section 16.10.2 of the data sheet
     
  6. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,169
    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.


     
    Last edited: Mar 26, 2016
  7. Harnee15

    Thread Starter New Member

    Sep 14, 2015
    24
    0
    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
     
  8. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,392
    497
    DS70183D: http://ww1.microchip.com/downloads/en/DeviceDoc/70183D.pdf
    Page 16-4
    Figure 16-1
    ADC Block Diagram for Devices with DMA

    It shows only one buffer.
    Like nsaspook said, you don't have the other buffers to use.
     
  9. Harnee15

    Thread Starter New Member

    Sep 14, 2015
    24
    0
    @shteii01 , I'm using ADC without DMA and in the same data sheet Page 16-5 and Figure 16-2 , it shows that it has 16 buffers. So, I believe I can use them
     
  10. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,392
    497
    You are incorrect.
    dspic33fj128mc804 has DMA.


    blind.jpg


    blind.jpg
     
    Last edited: Mar 26, 2016
  11. dannyf

    Well-Known Member

    Sep 13, 2015
    1,818
    362
    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.
     
  12. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,169
    I think we have that finally settled.
    [​IMG]
     
Loading...