文档版本:
Document Number: MC9S08PA4RM
Rev 3, 08/2014
第320页
有个ADC使用FIFO的例子,可是经过测试结果不正确
======初始化代码======
Example: 15.5.2.1.1 FIFO ADC initialization routine
void ADC_init(void)
{
/* The following code segment demonstrates how to initialize ADC by low-power mode, long
sample time, bus frequency, hardware triggered from AD1, AD3, AD5, and AD7 external pins
with 4-level FIFO enabled */
ADC_APCTL1 = ADC_APCTL1_ADPC6_MASK | ADC_APCTL1_ADPC5_MASK | ADC_APCTL1_ADPC3_MASK |
ADC_APCTL1_ADPC1_MASK;
ADC_SC3 = ADC_SC3_ADLPC_MASK | ADC_SC3_ADLSMP_MASK | ADC_SC3_MODE1_MASK;
// setting hardware trigger
ADC_SC2 = ADC_SC2_ADTRG_MASK ;
//4-Level FIFO
ADC_SC4 = ADC_SC4_AFDEP1_MASK | ADC_SC4_AFDEP0_MASK;
// dummy the 1st channel
ADC_SC1 = ADC_SC1_ADCH0_MASK;
// dummy the 2nd channel
ADC_SC1 = ADC_SC1_ADCH1_MASK | ADC_SC1_ADCH0_MASK;
// dummy the 3rd channel
ADC_SC1 = ADC_SC1_ADCH2_MASK | ADC_SC1_ADCH0_MASK;
// dummy the 4th channel and ADC starts conversion
ADC_SC1 = ADC_SC1_AIEN_MASK | ADC_SC1_ADCH2_MASK | ADC_SC1_ADCH1_MASK | ADC_SC1_ADCH0_MASK;
}
======中断程序======
Example: 15.5.2.1.2 FIFO ADC interrupt service routine
unsigned short buffer[4];
interrupt VectorNumber_Vadc void ADC_isr(void)
{
/* The following code segment demonstrates read AD result FIFO */
// read conversion result of channel 1 and COCO bit is cleared
buffer[0] = ADC_R;
// read conversion result of channel 3
buffer[1] = ADC_R;
// read conversion result of channel 5
buffer[2] = ADC_R;
// read conversion result of channel 7
buffer[3] = ADC_R;
}
按手册上说的buffer[0]-buffer[4]结果应该是 1、3、5、7 通道的值,可结果是buffer[0]-buffer[4]全是通道 1 的结果
求指点,求真像 |