RAKSH 1 Posted October 5, 2013 Share Posted October 5, 2013 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 ? Quote Link to post Share on other sites
pao 0 Posted October 6, 2013 Share Posted October 6, 2013 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); RAKSH 1 Quote Link to post Share on other sites
L.R.A 78 Posted October 7, 2013 Share Posted October 7, 2013 Btw this seemed important: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/294691.aspx Quote Link to post Share on other sites
RAKSH 1 Posted October 7, 2013 Author Share Posted October 7, 2013 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 ! Quote Link to post Share on other sites
veimmone 0 Posted October 7, 2013 Share Posted October 7, 2013 Btw this seemed important: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/294691.aspx Not really relevant in this case, it only affects unregistering an interrupt handler. For most projects, this is not needed. Plus, it works perfectly well on ADC0 Best, Veikko Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.