RAKSH 1 Posted October 11, 2013 Share Posted October 11, 2013 Here's code performing ADC on Pin E5 on the Tiva C Series meant for struggling beginners like myself #include <stdbool.h> #include <stdint.h> #include "inc/hw_memmap.h" #include "driverlib/adc.h" #include "driverlib/gpio.h" #include "driverlib/sysctl.h" #include "driverlib/adc.h" #include "inc/hw_types.h" #include "driverlib/debug.h" main(void) { uint32_t pui32ADC0Value[1]; SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN| SYSCTL_XTAL_16MHZ); //Set clock at 40 Mhz , Sometimes //ADC may not work at 80Mhz SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ADCReferenceSet(ADC0_BASE, ADC_REF_INT); //Set reference to the internal reference // You can set it to 1V or 3 V GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5); //Configure GPIO as ADC ADCSequenceDisable(ADC0_BASE, 3); //It is always a good practice to disable ADC prior //to usage ,else the ADC may not be accurate // due to previous initializations ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); //Use the 3rd Sample sequencer ADCSequenceStepConfigure(ADC0_BASE, 3, 0,ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END); //Configure ADC to read from channel 8 ,trigger the interrupt to end data capture // ADCSequenceEnable(ADC0_BASE, 3); //Enable the ADC ADCIntClear(ADC0_BASE, 3); //Clear interrupt to proceed to data capture while (1) { ADCProcessorTrigger(ADC0_BASE, 3); //Ask processor to trigger ADC while (!ADCIntStatus(ADC0_BASE, 3, false)) { //Do nothing until interrupt is triggered } ADCIntClear(ADC0_BASE, 3); //Clear Interrupt to proceed to next data capture ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value); //pui32ADC0Value is the value read SysCtlDelay(SysCtlClockGet() / 12); } //Suitable delay } It is important to refer to datasheet before selecting the GPIO for the ADC and the channel through which it is done . gcshyamsundhar and austen520 2 Quote Link to post Share on other sites
rnightbane 0 Posted February 10, 2014 Share Posted February 10, 2014 how do i test the output of this adc using matlab? does this need a USB initialization code? Quote Link to post Share on other sites
gcshyamsundhar 0 Posted April 15, 2014 Share Posted April 15, 2014 Hi, The sequences for initializing ADC are given beautifully in this program. I have a doubt though. In the program you have posted, you are using only ADC0 for sampling one sample from channel 8. But I need to use both the ADCs 0 and 1 for sampling. These are the connections I need to sample: 1. ADC0 samples PE1 and PE3 2. ADC1 samples PE2 and PE4. How to configure the ADCs to sample in the above configuration ? Moreover, in one cycle I need to sample once from PE3 and PE4 and 128 times from PE1 and PE2. How can I accomplish this ? 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.