Hiiii all
i want to use ADC on this processor. My code is listed below. i am using Uvision keil. but code is not working. kindly help..
#include "ADCSWTrigger.h"
#include "../tm4c123gh6pm.h"
#include "PLL.h"
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
long StartCritical (void); // previous I bit, disable interrupts
void EndCritical(long sr); // restore I bit to previous value
void WaitForInterrupt(void); // low power mode
volatile unsigned long ADCvalue;
// The digital number ADCvalue is a representation of the voltage on PE4
// voltage ADCvalue
// 0.00V 0
// 0.75V 1024
// 1.50V 2048
// 2.25V 3072
// 3.00V 4095
int main(void){unsigned long volatile delay;
PLL_Init(); // 80 MHz
ADC0_InitSWTriggerSeq3_Ch1(); // ADC initialization PE2/AIN1
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // activate port F
delay = SYSCTL_RCGC2_R;
GPIO_PORTF_DIR_R |= 0x04; // make PF2 out (built-in LED)
GPIO_PORTF_AFSEL_R &= ~0x04; // disable alt funct on PF2
GPIO_PORTF_DEN_R |= 0x04; // enable digital I/O on PF2
// configure PF2 as GPIO
GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF0FF)+0x00000000;
GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF
while(1){
GPIO_PORTF_DATA_R |= 0x04; // profile
ADCvalue = ADC0_InSeq3();
GPIO_PORTF_DATA_R &= ~0x04;
for(delay=0; delay<100000; delay++){};
}
}
another file
#include "../tm4c123gh6pm.h"
// This initialization function sets up the ADC according to the
// following parameters. Any parameters not explicitly listed
// below are not modified:
// Max sample rate: <=125,000 samples/second
// Sequencer 0 priority: 1st (highest)
// Sequencer 1 priority: 2nd
// Sequencer 2 priority: 3rd
// Sequencer 3 priority: 4th (lowest)lab123\
// SS3 triggering event: software trigger
// SS3 1st sample source: Ain1 (PE2)
// SS3 interrupts: flag set on completion but no interrupt requested
void ADC0_InitSWTriggerSeq3_Ch1(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000010; // 1) activate clock for Port E
delay = SYSCTL_RCGC2_R; // allow time for clock to stabilize
GPIO_PORTE_DIR_R &= ~0x04; // 2) make PE2 input
GPIO_PORTE_AFSEL_R |= 0x04; // 3) enable alternate function on PE2
GPIO_PORTE_DEN_R &= ~0x04; // 4) disable digital I/O on PE2
GPIO_PORTE_AMSEL_R |= 0x04; // 5) enable analog function on PE2
SYSCTL_RCGC0_R |= 0x00010000; // 6) activate ADC0
delay = SYSCTL_RCGC2_R;
SYSCTL_RCGC0_R &= ~0x00000300; // 7) configure for 125K
ADC0_SSPRI_R = 0x0123; // 8) Sequencer 3 is highest priority
ADC0_ACTSS_R &= ~0x0008; // 9) disable sample sequencer 3
ADC0_EMUX_R &= ~0xF000; // 10) seq3 is software trigger
ADC0_SSMUX3_R = (ADC0_SSMUX3_R&0xFFFFFFF0)+1; // 11) channel Ain1 (PE2)
ADC0_SSCTL3_R = 0x0006; // 12) no TS0 D0, yes IE0 END0
ADC0_ACTSS_R |= 0x0008; // 13) enable sample sequencer 3
}
//------------ADC0_InSeq3------------
// Busy-wait Analog to digital conversion
// Input: none
// Output: 12-bit result of ADC conversion
unsigned long ADC0_InSeq3(void){
unsigned long result;
ADC0_PSSI_R = 0x0008; // 1) initiate SS3
while((ADC0_RIS_R&0x08)==0){}; // 2) wait for conversion done
result = ADC0_SSFIFO3_R&0xFFF; // 3) read result
ADC0_ISC_R = 0x0008; // 4) acknowledge completion
return result;
}