Jump to content
Sign in to follow this  
RAKSH

ADC on Tiva C Series

Recommended Posts

I'm trying to read analog values from a photoresistor(off of a voltage divider) connected to pin PC5 .
I use the following code 

 
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"

#ifdef DEBUG
void__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

int main(void)
{
uint32_t ui32ADC0Value[1];


SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    GPIOPinTypeADC(GPIO_PORTC_BASE,GPIO_PIN_5);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
 ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |ADC_CTL_END);

ADCSequenceEnable(ADC0_BASE, 3);

  ADCIntClear(ADC0_BASE, 3);
while(1)
{
ADCProcessorTrigger(ADC0_BASE, 3);

  while(!ADCIntStatus(ADC0_BASE, 3, false))
  {
  }
  ADCIntClear(ADC0_BASE, 3);

  ADCSequenceDataGet(ADC0_BASE, 3, ui32ADC0Value); // Watch on ui32ADC0Value
 

  SysCtlDelay(20000);

}
}
 
 

But unfortunately I'm getting random values of ui32ADC0Value that don't correspond to the ambient light .
What am i doing wrong here ? 

Share this post


Link to post
Share on other sites

HI @

Which your Microcontroller ?  Do you have 'Tiva C Series LaunchPad ( EK-TM4C123GXL) ?

 

 

if you have 'Tiva C Series LaunchPad', you can connect pin 'PE3'

 

GPIO_PORTC_BASE ==> GPIO_PORTE_BASE

 

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |ADC_CTL_END);

Share this post


Link to post
Share on other sites

Thanks but I resolved my issue .
The problem was , I was using a wrong channel to read values .
And also ,that it is necessary to clear all Interrupts on the ADC before proceeding .

Thanks a lot guys !

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...