Re: dspic ADC的問題

作者 CHS 於 2017年03月14日 23:02:03
以下是我ADC的相關設定:

void ADCInit(void) // will set 12bit, 4.96us/sample or 202KS/sec
{
AD1CON1 = 0; // POR: 10-bit @4ch mode, ADC disabled, manual sample
AD1CON2 = 0; // POR: AVdd/Avss for Vref, do not scan, IRQ every sample
AD1CON3 = 0; // POR: Use system clock, TAD = 1Tcyc, SAMC = 0TAD
AD1CON4 = 0; // POR: no DMA

AD1CHS123 = 0; // not used in 12bit mode, as only 1 S/H available
AD1CON1bits.FORM = 0; // integer data format (unsigned)
AD1CON1bits.ASAM = 1; // continuous automatic sampling enabled

AD1CON3bits.ADCS = 8; // 9 Tcy = 1TAD (so TAD = 9*25ns = 225ns = 4.44MHz)
AD1CON3bits.SAMC = 8; // set auto sample time as 8TAD = 1.8us


AD1CON1bits.AD12B = 1; // 12-bit conversion, 14TAD convert time

AD1CON1bits.ADON = 1; // enable converter

//
// Turn on port RG8, which supplies +5V to pot
//
_TRISG8 = 0;
_LATG8 = 1;

//
// there is a delay time required from ADC ebable until application can begin converting
// 150us is sufficient. Also allows pot voltage to stabilize, charges up anti-aliasing filter
__delay_us(150);

AD1CON1bits.SAMP = 1; // begin continuous sampling/conversion

}

麻煩了!

來自: http://www.microchip.com.tw/newbb/viewtopic.php?forum=2&topic_id=20414&post_id=74567