본문 바로가기

[FreeScale]/KINETIS

K20 EVM - Kinetis Cortex-M4 K20 16bit ADC 테스트

K20 EVM - Kinetis Cortex-M4 K20  16bit  ADC 테스트





Kinetis 시리즈는 기존 Cortex-M 시리즈들에서 보기 힘든 16bit ADC를 기본으로 내장하고 있다. K20 시리즈의 경우 특히 ADC부분에 기능이 풍부해 아날로그에 있어 강점이 있는것 같다.

특히 HW 평균필터가 내장되어 있어 32 Sample까지 필터링 가능하다.



K20 ADC테스트 동영상

K20 EVM 보드를 이용하여 가변저항에 연결된 전압값을 ADC해서 그래프로 출력하는 테스트를 진행해 보았다.





K20 의 ADC 블록도





K20 ADC 레지스터

아주 복잡해 보이지만 자세히 보면 ADCx_SC1 레지스터만 설정하면 아주 간단히 ADC를 할 수 있도록 되어 있다. 





5-DIFF

Differential mode enable

차동으로 받을지 싱글로 받을지 설정 한다.

0 Single-ended conversions and input channels are selected.

1 Differential conversions and input channels are selected.


4–0 ADCH

ADC 채널 선택

00000 When DIFF=0, DADP0 is selected as input; when DIFF=1, DAD0 is selected as input.

00001 When DIFF=0, DADP1 is selected as input; when DIFF=1, DAD1 is selected as input.

00010 When DIFF=0, DADP2 is selected as input; when DIFF=1, DAD2 is selected as input.

00011 When DIFF=0, DADP3 is selected as input; when DIFF=1, DAD3 is selected as input.

00100 When DIFF=0, AD4 is selected as input; when DIFF=1, it is reserved.

00101 When DIFF=0, AD5 is selected as input; when DIFF=1, it is reserved.

00110 When DIFF=0, AD6 is selected as input; when DIFF=1, it is reserved.

00111 When DIFF=0, AD7 is selected as input; when DIFF=1, it is reserved.

01000 When DIFF=0, AD8 is selected as input; when DIFF=1, it is reserved.

01001 When DIFF=0, AD9 is selected as input; when DIFF=1, it is reserved.

01010 When DIFF=0, AD10 is selected as input; when DIFF=1, it is reserved.

01011 When DIFF=0, AD11 is selected as input; when DIFF=1, it is reserved.

01100 When DIFF=0, AD12 is selected as input; when DIFF=1, it is reserved.

01101 When DIFF=0, AD13 is selected as input; when DIFF=1, it is reserved.

01110 When DIFF=0, AD14 is selected as input; when DIFF=1, it is reserved.

01111 When DIFF=0, AD15 is selected as input; when DIFF=1, it is reserved.

10000 When DIFF=0, AD16 is selected as input; when DIFF=1, it is reserved.

10001 When DIFF=0, AD17 is selected as input; when DIFF=1, it is reserved.

10010 When DIFF=0, AD18 is selected as input; when DIFF=1, it is reserved.

10011 When DIFF=0, AD19 is selected as input; when DIFF=1, it is reserved.

10100 When DIFF=0, AD20 is selected as input; when DIFF=1, it is reserved.

10101 When DIFF=0, AD21 is selected as input; when DIFF=1, it is reserved.

10110 When DIFF=0, AD22 is selected as input; when DIFF=1, it is reserved.

10111 When DIFF=0, AD23 is selected as input; when DIFF=1, it is reserved.

11000 Reserved.

11001 Reserved.

11010 When DIFF=0, Temp sensor (single-ended) is selected as input; when DIFF=1, Temp sensor

(differential) is selected as input.

11011 When DIFF=0,Bandgap (single-ended) is selected as input; when DIFF=1, Bandgap (differential)

is selected as input.

11100 Reserved.

11101 When DIFF=0, VREFSH is selected as input; when DIFF=1, -VREFSH (differential) is selected as

input. Voltage reference selected is determined by the REFSEL bits in the SC2 register.

11110 When DIFF=0, VREFSL is selected as input; when DIFF=1, it is reserved. Voltage reference

selected is determined by the REFSEL bits in the SC2 register.

11111 Module disabled.




ADCx_SC3

하드웨어 평균화 필터 설정이 가능하다.




K20 ADC 초기화 소스코드

#define ADC_CFG1_MODE_8_9_BIT       0x0

#define ADC_CFG1_MODE_12_13_BIT     0x1

#define ADC_CFG1_MODE_10_11_BIT     0x2

#define ADC_CFG1_MODE_16_BIT        0x3

#define ADC_SC3_AVGS_32_SAMPLES     0x3


void AdcInit(void)

{

    SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK;

    

    ADC0_CFG1 = ADC_CFG1_MODE(ADC_CFG1_MODE_16_BIT);

    ADC0_SC3 = ADC_SC3_AVGE_MASK | ADC_SC3_AVGS(ADC_SC3_AVGS_32_SAMPLES);

}



K20 ADC Read 소스코드

unsigned int AdcRead(unsigned char Channel)

{

//ADC 채널 선택

ADC0_SC1A  =  Channel;

//ADC 변환 완료 까지 대기

while((ADC0_SC1A & ADC_SC1_COCO_MASK) == 0)

{

}

    //ADC값 출력

return ADC0_RA;

}





[K20 EVM] 보드에는 ADC8(PB0), ADC9(PB1), ADC14(PC0), ADC15(PC1) 포트에서 ADC테스트 해볼 수 있다.




PTC0 - ADC0_SE14

PTC1 - ADC0_SE15





레퍼런스 입력은 LM4040 으로 설정 가능하다.







반응형