View previous topic :: View next topic |
Author |
Message |
Hakk
Joined: 20 Aug 2014 Posts: 3
|
[solved] A/D program returns just 0 |
Posted: Wed Aug 20, 2014 10:33 am |
|
|
Hi Folks,
I'm quite new to PICs and currently working on a dsPIC30F6015. I got the CAN device and other stuff working but the A/D gives me issues. My program just returns 0 regardless of the used analog input, so I saw a very basic program in this forum with A/D and tried it, but returns 0 nonetheless.
The used compiler is the CCS Compiler.
On AN0 a constant 5V is applied, but the program shows still 0 if switched to AN0
On AN8 a signal between 0-5V is applied, still zero.
I'm thankful for any thoughts that might help
Code: | #include <30F6015.H>
#include <stdint.h>
#device ADC=10
#case
#fuses HS2_PLL16,NOPROTECT,NOWDT,PUT16
#define CLOCK_FREQ 80000000
#use delay(clock=CLOCK_FREQ)
#use rs232(baud=115200,xmit=PIN_F3,rcv=PIN_F2, BRGH1OK)
void main()
{
int16 r;
setup_adc_ports(sAN8);
setup_adc(ADC_CLOCK_DIV_16);
set_adc_channel(0);
while(TRUE)
{
r =read_adc();
printf("AD value is %4LD \r\n", r);
delay_ms(1000);
}
} |
Last edited by Hakk on Thu Aug 21, 2014 1:43 am; edited 1 time in total |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Wed Aug 20, 2014 10:35 am |
|
|
sAN8 would be channel 8 not 0 as in your set_adc_channel(8) |
|
|
Hakk
Joined: 20 Aug 2014 Posts: 3
|
|
Posted: Wed Aug 20, 2014 10:51 am |
|
|
Sure? The datasheet suggests that there are only 4 channels and AN8 is connected to 0 and 3.
And in your case it should have worked when I applied sAN0 with channel 0 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed Aug 20, 2014 12:02 pm |
|
|
You are misunderstanding.
The 'setup_adc_ports' command, sets what pins are physically connected to the internal ADC multiplexer. There are a total of 32 different inputs that can be connected here.
The set_adc_channel then selects which of these is connected to the internal ADC channels.
Alan is correct sAN8, is adc_channel 8 at the multiplexer.
This is connected to pin B8.
Then internally the ADC has four sample and hold channels, that are used to do overlapped sampling (this is not used for the simple setup).
It should work with sAN0, and channel 0, but only when feeding B0, or sAN8, and channel 8, on B8. |
|
|
Hakk
Joined: 20 Aug 2014 Posts: 3
|
|
Posted: Thu Aug 21, 2014 1:42 am |
|
|
Thanks a lot guys for your help
Sry alan that I thought you were mistaken.
I was really confused by the 4 internal channels :D |
|
|
|