내 단계는 다음과 같습니다. ADC 및 AIN10 (PB4) 포트 용 클록을 활성화합니다. 핀 B4에 해당하는 DEN 및 DIR 레지스터의 각 비트를 비활성화합니다. AFSEL 레지스터 및 PCTL 레지스터 *에서 해당 핀을 활성화합니다. 다음과 같은 레지스터 설정 : 코드에 표시된 샘플링 속도, 우선 순위 (SS3) 등.내 ADC를 tm4c123gxl 마이크로 컨트롤러에서 작동시키는 방법은 무엇입니까?
그럼 다른 기능에서 트리거하지만 어떻게 든 내 ADC는 다른 전압인가를 읽지 않습니다.
내 첫 번째 질문은 PCTL에 관한 것이고 ADC를 사용하려면 어떤 값을 사용해야합니까?
나는 약 하루 동안 그것을 풀려고 노력하고있다. 그러나 나는 아직 그것을 이해하지 못했다. 어떤 도움이라도 대단히 감사합니다.
// Register definitions for clock enable
#define SYSCTL_RCGCGPIO_R (* ((volatile unsigned long *) 0x400FE608))
#define SYSCTL_RCGCADC_R (* ((volatile unsigned long *) 0x400FE638))
#define GPIO_PORTB_AFSEL_R (* ((volatile unsigned long *) 0x40058420))
#define GPIO_PORTB_PCTL_R (*((volatile unsigned long *)0x4005952C))
// Register definitions for GPIO port B ;;;;; AIN10 = PB4
#define GPIO_PORTB_DATA_R (* ((volatile unsigned long *) 0x400053FC))
#define GPIO_PORTB_DIR_R (* ((volatile unsigned long *) 0x40005400))
#define GPIO_PORTB_DEN_R ( *((volatile unsigned long *) 0x4000551C))
// Register definitions for ADC0 and Sample Sequencer 3
#define ADC0_PC_R (* ((volatile unsigned long *) 0x40038FC4))
#define ADC0_SSPRI_R (* ((volatile unsigned long *) 0x40038020))
#define ADC0_ACTSS_R (* ((volatile unsigned long *) 0x40038000))
#define ADC0_IM_R (* ((volatile unsigned long *) 0x40038008))
#define ADC0_RIS_R (* ((volatile unsigned long *) 0x40038004))
#define ADC0_ISC_R (* ((volatile unsigned long *) 0x4003800C))
#define ADC0_SAC_R (* ((volatile unsigned long *) 0x40038030))
#define ADC0_PSSI_R (* ((volatile unsigned long *) 0x40038028))
#define ADC0_SSCTL3_R (* ((volatile unsigned long *) 0x400380A4))
#define ADC0_SSFIFO3_R (* ((volatile unsigned long *) 0x400380A8))
unsigned char Lookup_7Seg_Disp [ 12 ] = {0xC0 , 0xF9 , 0xA4 , 0xB0 , 0x99 ,
0x92 , 0x82 , 0xF8 , 0x80 , 0x90 , 0xC6};
unsigned char Temperature_Value [ 3 ] = {0 , 0 , 0xA} ;
unsigned char i , value=0;
unsigned int ADC_value = 0 , voltage = 0 ;
int maxVoltage=0;
void ADC_Init() {
volatile unsigned long delay;
SYSCTL_RCGCGPIO_R |= 0x01; //Enable Clock for Port A
SYSCTL_RCGCADC_R |= 0x1; //Enable ADC0
delay = SYSCTL_RCGCGPIO_R; //Delay for clock to settle down
GPIO_PORTB_DIR_R &= ~(0x10);//PB4 as input
GPIO_PORTB_DEN_R &= ~(0x10);//PB4 as analog type
GPIO_PORTB_AFSEL_R |= 0x10;
GPIO_PORTB_PCTL_R |= 0x10;
//Clear sampling rate
ADC0_PC_R &= 0x00;
//Set sampling rate to 125ksps
ADC0_PC_R &= 0x01;
//Set priority to SSFI3
ADC0_SSPRI_R |= 0x3210;
//Disable sample sequence 3 befor configuration
ADC0_ACTSS_R &= ~0x8;
//Enable TS0, IE0 and END0 bits
ADC0_SSCTL3_R |= 0xE;
//Enable 16x hardware oversampling
ADC0_SAC_R |= 0x4;
//Disable Interrupt by writing 0 to corresponding bit
ADC0_IM_R &= ~(0x8);
//Activate sample sequencer
ADC0_ACTSS_R |= 0x8;
}
void SystemInit() {
}
void ADC_Voltage(void) {
ADC0_PSSI_R |= 0x8;
while ((ADC0_RIS_R & 0x8)==0);
ADC_value = (ADC0_SSFIFO3_R & 0xFFF);
voltage = (ADC_value)*44;
if(voltage>maxVoltage){
maxVoltage=voltage;
}
ADC0_ISC_R |= 0x08;
}
void delay(unsigned long counter) {
int i;
for(i=0;i<counter;i++)
{}
}
int main(void) {
ADC_Init();
delay(1000);
ADC_Voltage();
maxVoltage=maxVoltage*0.707;
}