dsPIC30F4011, ADC module???

Status
Not open for further replies.

member_tdh

Member level 5
Joined
Feb 6, 2006
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,187
dspic30f4011 adc

Hi!

Now, I'm working with a dsPIC30F4011 project, use ADC module. My problem is: If I read the only AN0 or AN1, I'm getting correct result. But if I read the chanel AN0,AN1 both at the same time, I'm getting: the result of AN0 chanel affected the result of AN1 chanel. I don't know why?

Could anybody help me???
Best regard!

void read_adc(void)
{
ADCON1bits.ADON = 1; //Bat module ADC
while(!IFS0bits.ADIF); //Wait till conversion is done
IFS0bits.ADIF = 0; //Xoa co ngat ADC
adc.temp_ADC[chanel0][0]=ADCBUF0;
adc.temp_ADC[chanel1][0]=ADCBUF1;
}

void Init_ADC(void)
{
ADPCFG = 0xFFFC; //Setup chanel AN0,AN1 as "analog" and configure rest as "digital"
ADCSSL = 0x0003; //Only chanel AN0,AN1 scanning is enable
ADCON2bits.VCFG = 0; //Set VREF+ = AVDD (+5V), VREF- = AVSS (0V)
ADCON2bits.CSCNA= 1; //CH0 S/H input for MUX A input multiplexer setting bit
ADCON2bits.CHPS = 0; //Select chanel CH0 to be converted "if it is enable"
ADCON2bits.SMPI = 3; //Setup A/D for interrupting after 4 samples get filled in the buffer
ADCON2bits.BUFM = 0; //Buffer configure as one 16 word buffer ADCBUF[15...0]
ADCON2bits.ALTS = 0; //Always use MUX A input multiplexer settings, setup to sample on 1 S/H amplifiers "CH0"
ADCON1bits.SIMSAM=1; //Sample multiple chanels in same sequence

ADCON1bits.ASAM = 1; //Khoi dong che do tu dong lay mau
ADCON1bits.FORM=0; //Set the output of ADC to "unsigned integer"
ADCON1bits.SSRC=7; //Internal Counter ends sampling and starts conversion (auto convert)==> (SSRC=111)

ADCON3 = 0x1F07; //Dung dung clock he thong, TAD = 200 ns
// ADCHS = 0; //Setup A/D chanel select register to convert AN0,AN1 on MUX A input of CH0 S/H amplifiers
ADCHS = 1; //AN0->AN1

IFS0bits.ADIF = 0; //Xoa co ngat ADC
IEC0bits.ADIE = 0; //Cam ngat ADC
ADCON1bits.ADON = 1; //Bat module ADC
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…