CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I need help for ADC adjustment

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

I need help for ADC adjustment
PostPosted: Wed Sep 25, 2013 11:55 pm     Reply with quote

Greetings! I want to use the ADC of dsPIC30F5015. I connected Pins 15 and 16 through 10 ohms resistors to GRD and Vcc (Vref +/- datasheet page 144 figure 20-2). I added the additional capacitors as the schematics says. In this controller Vref is on AN0 and AN1, so I connected AN2 and AN3 (PINs13 and 14) to the voltages I want to measure.
I made a small program for testing the schematic.
Code:

        int value=0;
   setup_adc_ports( sAN3|sAN2 );
   setup_adc(ADC_CLOCK|ADC_TAD_MUL_0);
   set_adc_channel( 0 );
        while(1)
        {
              value=read_adc();
        }

As figure 20.1 of the datasheet says AN2 is multiplexed on CH3, but AN3 on CH0.
So I selected CH0, but the read_adc() always returns 2 as result. I have around 5V on AN3 so this is not correct.
Can you tell me what am I doing wrong? I suppose I haven't adjusted the ADC correctly.
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Thu Sep 26, 2013 12:51 am     Reply with quote

Step through things:

1) You are not selecting pins 15/16 as the ADC VREF. This is the VREF_VREF option in setup_adc_ports.
2) The ADC needs time to acquire. It is disconnected from the signal when reading and has to re-acquire the signal between. You either need to add a delay in your loop, or specify an acquisition time with the ADC_TAD_MUL value.
3) You don't say how fast your CPU clock is. You are selecting to clock the ADC directly from the peripheral clock. Max just under 4MHz (links to below).
4) Then 'set_adc_channel', refers directly to the ANx pins. The default setting used by the 'direct reading' mode like this, is the bottom one in Table 20-1.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Thu Sep 26, 2013 6:10 am     Reply with quote

OK! I fixed the setup function:
Code:

     setup_adc(ADC_CLOCK|ADC_TAD_MUL_31|VREF_VREF);


I think this sets the Vref and TAD time. I`m using 10MHz clock with H2_PLL16 option = 80M.

There is no change in the result...
What do you mean by :
Quote:
Then 'set_adc_channel', refers directly to the ANx pins. The default setting used by the 'direct reading' mode like this, is the bottom one in Table 20-1.

AN2 = channel 2?!
Thanks!
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Fri Sep 27, 2013 3:50 am     Reply with quote

I fixed it! It seems the project was compromised.
Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group