본문 바로가기
코스웨어/16년 스마트컨트롤러

20160323_업무일지_정우민_ADC

by 알 수 없는 사용자 2016. 3. 23.
728x90
반응형

ADC(Analog Digital Converter)

- ADC (EX. 녹음)

 - DAC (EX. 재생)

 *ADC 특징

 • 10-bit Resolution
 • 1 LSB Integral Non-linearity
 • ±2 LSB Absolute Accuracy
 • 13μs - 260μs Conversion Time
 • Up to 76.9kSPS (Up to 15kSPS at Maximum Resolution)
 • 16 Multiplexed Single Ended Input Channels

 • 14 Differential input channels
 • 4 Differential Input Channels with Optional Gain of 10× and 200×
 • Optional Left Adjustment for ADC Result Readout
 • 0V - VCC ADC Input Voltage Range
 • 2.7V - VCC Differential ADC Voltage Range
 • Selectable 2.56V or 1.1V ADC Reference Voltage
 • Free Running or Single Conversion Mode
 • Interrupt on ADC Conversion Complete
 • Sleep Mode Noise Canceler


 *MUX (MULTIPLEXER)
 - 여러개 중 하나를 선택하는 것.  ->> 여러개 PIN중 하나를 선택하는 것.
 - ADC[15:0]


==========================================================================================================

#include "adc.h"


void adc_Init (void)    // ADLAR=0 오른족정렬 사용
{
 ADMUX   = (0 << REFS1) | (0 << REFS0) | (0 << ADLAR) | (0 << MUX4) | (0 << MUX3) | (0 << MUX2) | (0 << MUX1) | (0 << MUX0);
 ADCSRB  = (0 << ACME) | (0 << MUX5) | (0 << ADTS2) | (0 << ADTS1) | (0 << ADTS0);  // ADC0 사용.
 ADCSRA  = (1 << ADEN) | (0 << ADSC) | (0 << ADATE) | (0 << ADIF) | (0 << ADIE) | (1 << ADPS2) | (1 << ADPS1) | (0 << ADPS0);
 //64분주 사용
 
 
}


unsigned int adc_Run0 (void)
{
 adc_Init();
 ADCSRA  = ADCSRA | (1 << ADSC);

 while( 0 != (ADCSRA & (1 << ADSC)) );
 
 return ADC;

}

==========================================================================================================

#ifndef __ADC_H__
#define __ADC_H__

#include "main.h"

void adc_Init (void);
unsigned int adc_Run0 (void);


#endif //__ADC_H__


==========================================================================================================

#include "main.h"
#include "lcd.h"
#include "tc0.h"
#include "usart.h"
#include "adc.h"

int main(void)
{
 
 char caVal[] = "....";
 unsigned int uiVal;
 
 lcd_Init ();         //  함수 초기화
 usart1_Init ();
 adc_Init();
 
 while(1)
 {
  uiVal = adc_Run0();      // ADC 값

  caVal[0] = '0' + (uiVal / 1000);    // 각자리수 추출
  caVal[1] = '0' + ((uiVal % 1000) / 100);
  caVal[2] = '0' + ((uiVal % 100) / 10);
  caVal[3] = '0' + (uiVal % 10);

  lcd_Str(caVal);       // lcd 출력
  usart1_Str(caVal);
  lcd_Inst(LCD_HOME);     
 }

 
 return 0;
}



728x90