【发布时间】:2017-10-17 09:18:32
【问题描述】:
我的步骤如下: 为 ADC 和 AIN10 (PB4) 端口启用时钟。 禁用与引脚 B4 对应的 DEN 和 DIR 寄存器中的相应位。 使能 AFSEL 寄存器和 PCTL 寄存器中的相应引脚*。 设置寄存器:采样率,优先级(SS3)等,如代码所示。
然后我在另一个函数中触发它,但不知何故我的 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;
}
【问题讨论】:
标签: arm keil cortex-m microprocessors