How to use ADC

Infineon
HOT XC886/888
May 2006
1
May 2006 – ADC Example 7 Queued Conversion
XC886/888CLM
How to use the ADC – ADC-Demo 7
„ ADC7 – Quasi synchronous sampling of AN4/AN5 and
AN6/AN7 (XC886)
HOT XC886/888
May 2006
2
„
T12 in single shot mode to trigger
„
multi-stage queue without refill
„
one result interrupt after conversion of AN4/AN5,
one after conversion of AN6/AN7
How to use the ADC – ADC-Demo 7
„ Copy or type following code
– main.c
// USER CODE BEGIN (MAIN_Main,3)
ADC_vStartSeqReqChNum(1, 0, 0, 4);
ADC_vStartSeqReqChNum(0, 0, 0, 5);
ADC_vStartSeqReqChNum(0, 0, 0, 5);
ADC_vStartSeqReqChNum(0, 0, 0, 4);
CC6_vStartTmr(CC6_TIMER_12);
while(ADC_ubGetQueueEmpty() == 0)
{}
ADC_vStartSeqReqChNum(1, 0, 0, 6);
ADC_vStartSeqReqChNum(0, 0, 0, 7);
ADC_vStartSeqReqChNum(0, 0, 0, 7);
ADC_vStartSeqReqChNum(0, 0, 0, 6);
CC6_vStartTmr(CC6_TIMER_12);
// USER CODE END
HOT XC886/888
May 2006
3
while(1)
{
// USER CODE BEGIN (MAIN_Main,4)
// USER CODE END
}
} // End of function main
„ Copy or type following code
– adc.c
// USER CODE BEGIN (ADC_Isr,1)
int reg0_buf, reg1_buf, reg2_buf, reg3_buf;
unsigned char i=0;
// USER CODE END
void ADC_vIsr(void) interrupt ADCINT
{
SFR_PAGE(_su0, SST2);
// switch to page 0
// Check Interrupt Request 1 Flag
if (((IRCON1 & 0x10) != 0))
{
IRCON1 &= ~(ubyte)0x10; // clear ADCSRC1
SFR_PAGE(_su0, RST2); // restore old page
// USER CODE BEGIN (ADC_Isr,4)
if(i==0)
{
reg0_buf = ADC_uwGetResultData0();
reg1_buf = ADC_uwGetResultData1();
}
else
{
reg2_buf = ADC_uwGetResultData2();
reg3_buf = ADC_uwGetResultData3();
}
i++;
// USER CODE END