View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
I need help for ADC adjustment |
Posted: Wed Sep 25, 2013 11:55 pm |
|
|
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: 19513
|
|
Posted: Thu Sep 26, 2013 12:51 am |
|
|
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
|
|
Posted: Thu Sep 26, 2013 6:10 am |
|
|
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
|
|
Posted: Fri Sep 27, 2013 3:50 am |
|
|
I fixed it! It seems the project was compromised.
Thanks! |
|
|
|