본문 바로가기

Cortex-M/INFINEON

XMC1300 EVM - ADC 테스트

[XMC1300 EVM] - ADC 테스트




XMC1300은 저렴한 CORTEX-M0 코어를 가진 MCU임에도 아날로그 기능은 풍부하다. 두채널의 독립된 12비트 ADC모듈이 있고 각각 8채널 입력 가능하다. 특히 하드웨어적으로 FIR/IIR 필터가 존재 하는것이 특이하다.


XMC1300 ADC특징

- Two independent sample and hold stages with 8 analog input channels each

- Selectable result width of 8/10/12 bits

– Fast Compare Mode

– Independent result registers

– Configurable limit checking against programmable border values

– Data rate reduction through adding a selectable number of conversion results

– FIR/IIR filter with selectable coefficients




XMC1300 ADC 테스트 동영상

ADC5 에 연결되어 있는 가변저항의 전압값을 TFT LCD에 출력하는 예제




XMC1300 EVM ADC 핀맵

P2.0 -> VADC0.G0CH5


P2.6 -> VADC0.G0CH0

P2.7 -> VADC0.G0CH1




XMC1300 ADC초기화코드

void ADC_Init()

{

        // Global ADC Initialization

WR_REG(VADC->CLC, VADC_CLC_DISR_Msk, VADC_CLC_DISR_Pos, 0);

// Wait till module clock is enabled

while((RD_REG(VADC->CLC, VADC_CLC_DISS_Msk, VADC_CLC_DISS_Pos))!= 0);


// Enable ORC; required due to erratum ADC_AI.003

WR_REG(COMPARATOR->ORCCTRL, COMPARATOR_ORCCTRL_ENORC0_Msk, COMPARATOR_ORCCTRL_ENORC0_Pos, 1);


// Initiate start up calibration

WR_REG(VADC->GLOBCFG, VADC_GLOBCFG_SUCAL_Msk, VADC_GLOBCFG_SUCAL_Pos, 1);


// Enable wait-for-read mode

WR_REG(VADC_G0->RCR[0], VADC_G_RCR_WFR_Msk, VADC_G_RCR_WFR_Pos, 1);


// Configure Scan source

// Select G1CH7 on P2.5 as input channel

WR_REG(VADC_G0->ASSEL, VADC_G_ASSEL_CHSEL5_Msk, VADC_G_ASSEL_CHSEL5_Pos, 1);

WR_REG(VADC_G0->ASMR, VADC_G_ASMR_ENGT_Msk, VADC_G_ASMR_ENGT_Pos, 1); //Enable gate

WR_REG(VADC_G0->ASMR, VADC_G_ASMR_SCAN_Msk, VADC_G_ASMR_SCAN_Pos, 1); //Enable autoscan

WR_REG(VADC_G0->ASMR, VADC_G_ASMR_LDEV_Msk, VADC_G_ASMR_LDEV_Pos, 1); //Generate a load event

    

// Arbitration

// Select normal operation

WR_REG(VADC_G0->ARBCFG, VADC_G_ARBCFG_ANONC_Msk, VADC_G_ARBCFG_ANONC_Pos, 3);

// Enable arbitration slot 1

WR_REG(VADC_G0->ARBPR, VADC_G_ARBPR_ASEN1_Msk, VADC_G_ARBPR_ASEN1_Pos, 1);


// Wait till calibration is completed

while((RD_REG(VADC_G0->ARBCFG, VADC_G_ARBCFG_CAL_Msk, VADC_G_ARBCFG_CAL_Pos))!= 0);    

}



XMC1300 ADC Read 함수

adc_result =  VADC_G0->RES[0];


// Check if new conversion result is available

if (adc_result & VADC_G_RES_VF_Msk)

{

adc_result &= VADC_G_RES_RESULT_Msk;

adc_result = (adc_result >> 2);

        

                DebugPrint("%d\r\n", adc_result);

}   




반응형