watisthis WROTE:when you said Vref did you mean one on the PIC or IMU...
i connected the RA3 pin on PIC to 3.3V as ref. voltage,,
as for IMU the Vref pin is not connected to anywhere...
or did i get the wrong idea here?
Ya, you are right. I mean the PIC Vref.
mk99011 WROTE:hi a380,may i hav ur full programming?thanks
Sorry, I didn't keep the programming. Last time I used dsPIC6012A as my controller.
Something is like this
- CODE: SELECT_ALL_CODE
unsigned int read_adc(unsigned int channel)
{
unsigned int i;
ADCHS=channel; //select channel
ADCON1bits.SAMP=1; //start sampling adc
for(i=700;i>0;i-=1); //sampling delay
ADCON1bits.SAMP=0; //stop sampling, start conversion
while(ADCON1bits.DONE==0); //wait for conversion to finish
i=ADCBUF0;
return i;
}
This code is for dsPIC which I used last time and not suitable for 16F877A. The sampling delay is quite important for ADC sampling capacitor (C hold) charging.
For correct A/D conversions, the A/D conversion clock (TAD) must be selected to ensure minimum TAD time of 1.6 μs. (Page 131 of PIC16F877A datasheet, under section 11.2 Selecting the A/D Conversion Clock)
So, I think you can try to change the ADCS2:ADCS1:ADCS0, may be 32Tosc or 64Tosc.
Good Luck!