|
I have a Z8F1680, I use this code to initialize and gather groups of reads
It may be close enough for you
void ADCInit( void )
{
// assuming CPU speed of 20 Mhz
ADCCP = 0x04; // DIV8
// [3:0] minimum specified sample select time is .5 us
//ADCSST = 0x03; // this should give 3 * .4 us
ADCSST = 0x0F; // this should give 3 * .4 us
// [5:0] minimum specified sample time is 1.8 us
//ADCST = 0x0A; // this should give 10 * .4 us
ADCST = 0x3F; // this should give 10 * .4 us
}
unsigned short ADCGetSample( ADCChannel_t inputsel, char SamplesToAverage )
{
char sampleno, samplestodo;
unsigned short sampletotal, thissample;
char inputmask;
inputmask = inputsel & 0x0F;
ADCCTL0 = inputmask | ( 1 << 4 ) | (1 << 6 ) | ( 1 << 5 ) ;
while ( (ADCCTL0 & ( 1 << 7)) )
{
// wait for ADC ready
}
sampletotal = 0;
for (sampleno = 0; sampleno <= SamplesToAverage; sampleno ++)
{
ADCCTL0 |= ( 1 << 7) | inputmask ;
while ( (ADCCTL0 & ( 1 << 7)) )
{
// wait for ADC ready/done
}
thissample = ADCD_H<<2;
thissample |= ADCD_L>>6;
if (sampleno) // throw away first sample
sampletotal += thissample;
}
thissample = sampletotal / SamplesToAverage;
return (thissample);
}
|