Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIT 18 AD Converter Test 로봇 SW 교육원 조용수.

Similar presentations


Presentation on theme: "UNIT 18 AD Converter Test 로봇 SW 교육원 조용수."— Presentation transcript:

1 UNIT 18 AD Converter Test 로봇 SW 교육원 조용수

2 학습 목표 조도 센서 값 읽기 가변 저항 값 읽기 가변 저항 값 읽어서 LED에 적용

3 조도 센서 값 읽기 APDS-9007 : Ambient Light Photo Sensor with Logarithmic Current Output

4 ADC Init void SYS_Init(void) { /* Unlock protected registers */
SYS_UnlockReg(); /* Enable IP clock */ CLK->APBCLK |= CLK_APBCLK_UART0_EN_Msk; CLK->APBCLK |= CLK_APBCLK_ADC_EN_Msk; /* Update System Core Clock */ /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock and cyclesPerUs automatically. */ SystemCoreClockUpdate(); /* Set P3 multi-function pins for UART0 RXD and TXD */ SYS->P3_MFP = SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0; /* Set P1.0 to AIN0 function */ SYS->P1_MFP = SYS_MFP_P10_AIN0 ; /* Lock protected registers */ SYS_LockReg(); }

5 ADC Init ADC Channel 0 Settings void ADC_Init() {
ADC->ADCR &= ~(0x2 << 2); // Single Mode ADC->ADCR |= 0x1 ; // ADEN Set }

6 ADC Init Read ADC Channel 0 int value0 = 0;
ADC->ADCHER = (0x1 << 0) ; // ADC Channel 0 Set ADC->ADCR |= 0x1 << 11 ; // Start Convert while(ADC->ADSR & (0x1 << 3)); value0 = ADC->ADDR[0] & 0xFFFF; printf("Photo Sensor Value 11 : "); printf("%d \n", value0);

7 ADC Init Set Interrupt Handler void ADC_IRQHandler() { int value0 = 0;
NVIC->ICPR[0] = (0x1 << 29); ADC->ADSR &= ~0x1; // Clear Interrupt ADC->ADCR &= ~(0x1 <<1) ; // Disable Interrupt value0 = ADC->ADDR[0] & 0xFFFF; printf("ADC(Interrupt) : "); printf("%d \n", value0); }

8 ADC Init Start ADC using Interrupt Int main() { …
//NVIC_EnableIRQ(ADC_IRQn); NVIC->ISER[0] = (0x1 << 29); printf("Stat ADC\n"); ADC->ADCHER = 0x1 ; // ADC Channel 0 Set ADC->ADCR |= (0x1 <<1) ; // Enable Interrupt ADC->ADCR |= 0x1 << 11 ; // Start Convert }

9 가변 저항 값 읽기 VCC , GND , ADC1 연결

10 가변 저항 값 읽기 ADC 0, 1 선택 void SYS_Init(void) {
/* Unlock protected registers */ SYS_UnlockReg(); /* Set P1.0 to AIN0 function */ SYS->P1_MFP = SYS_MFP_P10_AIN0 | SYS_MFP_P11_AIN1; /* Lock protected registers */ SYS_LockReg(); }

11 가변 저항 값 읽기 ADC 0, 1 선택 void ADC_IRQHandler() { int value0 = 0;
NVIC->ICPR[0] = (0x1 << 29); ADC->ADSR |= 0x1; // Clear Interrupt ADC->ADCR &= ~(0x1 <<1) ; // Disable Interrupt value0 = ADC->ADDR[0] & 0xFFFF; value1 = ADC->ADDR[1] & 0xFFFF; printf("ADC(Interrupt) : "); printf("%d , %d\n", value0, value1); }

12 가변 저항 값 읽기 ADC 0, 1 선택 printf("Stat ADC\n");
ADC->ADCHER = (0x3 << 0) ; // ADC Channel 0,1 Set ADC->ADCR |= (0x1 <<1) ; // Enable Interrupt ADC->ADCR |= 0x1 << 11 ; // Start Convert

13 가변 저항 값 읽기 Single Cycle Scan Mode void ADC_Init() {
ADC->ADCR &= ~(0x3 << 2); // Single Mode ADC->ADCR |= 0x2 << 2 ; // Single Cycle Scan Mode ADC->ADCR |= 0x1 ; // ADEN Set }

14 가변 저항 값 읽어서 LED에 적용 가변 저항 값 읽어서 구간 별로 4개의 LED On 0 ~ 10 : All OFF


Download ppt "UNIT 18 AD Converter Test 로봇 SW 교육원 조용수."

Similar presentations


Ads by Google