Мои шаги таковы: включение часов для АЦП и порта AIN10 (PB4). Отключение соответствующих битов в регистрах DEN и DIR, соответствующих контакту B4. Включение соответствующих контактов в регистре AFSEL и регистре PCTL*. Установка регистров для: частоты дискретизации, приоритета (SS3) и т. д., как показано в коде.
Затем я запускаю его в другой функции, но почему-то мой АЦП не считывает другое значение приложенного напряжения.
Мой первый вопрос о 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;
}