Part Number: TM4C123GH6PM
hi
I am currently working on a project with TM4c123GH6PM.
Am usingTIMER1A_Handler to trigger ADC conversion at GPIOB port 5 which is connected to a potentiometer .when conversion is triggered , am storing the result from ADC1->SSFIFO3 at adc_results .If adc_results value is greater than 2048 the GREEN LED is turned on . The code compiles with no errors but the GREEN LED does not turn on thus it seems my ADC conversion is not successful .
If you have any idea of what might be wrong with my code please help me out .
Kind regards ,
Earnest .
Below is my code :
#include "TM4C123.h" // Device header
void adc_init (void);
void timer_init(void);
void led_init(void);
void TIMER1A_Handler (void);
volatile int adc_results;
int main(void)
{
led_init(); //
adc_init(); //call adc initialization function
timer_init(); //call timer initialization function
//enable timer interrupt
__enable_irq();
while(1)
{
while((ADC1->RIS & 0x08) == 0){}//raw interrupt on the ss //wait for interrupt
if(adc_results > 2048)
{
GPIOF->DATA |= 0x08; //led on
}
else{
GPIOF->DATA &= ~0x08; //led off
}
ADC1->ISC = 0x08 ;//clear interrupt
}
}
//function to initialize ADC
void adc_init(void)
{
SYSCTL->RCGCGPIO |= 0x02; //clock for pB
SYSCTL->RCGCADC |= 0x02 ; //clock for ADC 1
GPIOB->AFSEL = 0x20 ; //pB5
GPIOB->DEN &= ~0x20 ; //digital disable
GPIOB->AMSEL |= 0x20 ;
//ss configuration
ADC1->ACTSS &= ~0x08 ; //disable ss3
ADC1->EMUX = 0x5000; //timer event trigger
ADC1->SSMUX3 = 11 ; //AIN 11 as input source
ADC1->SSCTL3 = 0x06 ; // end bit ,interrupt enable
ADC1->ACTSS |= 0x08 ; //enable ss3
}
void timer_init(void)
{
SYSCTL->RCGCTIMER |= 0x02 ; //clock for timer 1
TIMER1->CTL &= ~0x01 ; //disable timer
TIMER1->CFG = 0x04 ; //16 bit configuration
TIMER1->TAMR = 0x02 ; //1periodic mode
TIMER1->TAPR = 4; //prescaler
TIMER1->TAILR = 16000000 ; //load value
TIMER1->IMR = 0x01 ; //interrupt mask enabled
TIMER1->CTL |= 0x01 ; //enable timer
TIMER1->ICR |= 0x01 ; //clear prior interrupts
NVIC->ISER[0] = (1U<<21); //enable irq
}
void led_init(void)
{
SYSCTL->RCGCGPIO |= 0x20 ; //clock for pF
GPIOF->DIR = 0x0E ;
GPIOF->DEN = 0x0E;
}
//timer handler
//it will trigger adc conversion
void TIMER1A_Handler (void)
{
if(TIMER1->MIS & 0x01 )
{
while((ADC1->RIS & 0x08 ) == 0 ){} //wait for adc conversion to complete
adc_results = ADC1->SSFIFO3 ;
TIMER1->ICR |= 0x01 ;
GPIOF->DATA |= 0x04; //for debbuging purpose
}
}