This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

I'm having problems with ADC

I've been using memory addresses in the hopes of developing my own library for GPIO pins. Right now the problem I'm having is that Sampling Sequence 3 that I've implemented to be continuously sampling is acting strange. When I debug  (I have IAR embedded workbench) and go line by line it stops after ADCISC = (1U << 3); . It will not go into the while loop and also doesn't show its going into the interrupt handler: void ADC1SS3_Handler ( void ). As part of my debugging attempt I added HB_GPIOFDATA = BLUE and my onboard LED turns blue(when I try going step by step in debugger mode it does not go into the interrupt)! To make matters worse is that when I'm in disassemble it does go into the while loop. I'm out of ideas and could really use some help. Here is my code.

#define SYSCTL 0x400FE000U //this is the base HEX address for System controller
#define HB_GPIOE_BASE 0x4005C000U //Hex address for High performance Bus PORTE
#define HB_GPIOF_BASE 0x4005D000U //Hex Address for High performance Bus for PORTF
#define VTABLE_BASE 0xE000E000U //Hex address for Vector Table for Interrupts
#define ADC1_BASE 0x40039000U //No one wants to see the number 0x40039000 over and over again

//some offset for GPIO addresses defined to make reading the code easier
#define RCGCGPIO_OFFSET 0x608U
#define GPIOHBCTL_OFFSET 0x06CU
#define GPIO_DEN_OFFSET 0x51CU
#define GPIO_DIR_OFFSET 0x400U
#define GPIO_DATA_OFFSET 0x3FCU
//

//All this code is for ADC particularly for ADC1 Sample Sequencer 3
#define ADC_OFFSET 0x638U // This offset needs to be
#define AFSEL_OFFSET 0x420U
#define GPIO_AMSEL_OFFSET 0x528U
#define ADCACTS_OFFSET 0x000U
#define ADCEMUX_OFFSET 0x014U
#define SSPRI_OFFSET 0x020U
#define ADCT1MUX3_OFFSET 0x0A0U
#define ADCSSCTL3_OFFSET 0x0A4U //this offset is for initializing end of sequence and enable raw interrupts
#define ADCIM_OFFSET 0x008U
#define ADCISC_OFFSET 0x00CU //ADC interrupt service clear
#define ADC1SS3FIFO_OFFSET 0x0A8//What I primarily know about FIFO is that its where ADC info is stored
#define ADC1SS3_Handler_OFFSET 0x104U

#define RCGCGPIO_PORT (*((unsigned int*)(SYSCTL + RCGCGPIO_OFFSET))) //this enables a GPIOPORT of my choice, but to be clearer I have the intentions of for PORTF
#define GPIOHBCTL_PORT (*((unsigned int*)(SYSCTL + GPIOHBCTL_OFFSET))) //enables me to use High performance Bus

#define HB_GPIOEDEN (*((unsigned int*)(HB_GPIOE_BASE + GPIO_DEN_OFFSET))) //Digitally enable AHB_PORFTE to be used
#define HB_GPIOEDIR (*((unsigned int*)(HB_GPIOE_BASE + GPIO_DIR_OFFSET))) // I'll have to enable the HBGPIOE to input
#define HB_GPIOE_AMSEL (*((unsigned int*)(HB_GPIOE_BASE + GPIO_AMSEL_OFFSET)))
#define GPIOAFSEL_E (*((unsigned int*)(HB_GPIOE_BASE + AFSEL_OFFSET)))

#define ADC1_ACTSS3 (*(unsigned int*)(ADC1_BASE + ADCACTS_OFFSET))//use sample sequence 3
#define ADC1EMUX (*(unsigned int*)(ADC1_BASE + ADCEMUX_OFFSET))
#define ADC1SSPRI (*(unsigned int*)(ADC1_BASE + SSPRI_OFFSET))//sample sequence priority
#define ADC1SSMUX3 (*(unsigned int*)(ADC1_BASE + ADCT1MUX3_OFFSET))//use analog input to determine what to add in
#define ADCSSCTL3 (*(unsigned int*)(ADC1_BASE + ADCSSCTL3_OFFSET))
#define ADCSS3IM (*(unsigned int*)(ADC1_BASE + ADCIM_OFFSET))
#define ADCISC (*(unsigned int*)(ADC1_BASE + ADCISC_OFFSET))
#define ADC1SS3FIFO (*(unsigned int*)(ADC1_BASE + ADC1SS3FIFO_OFFSET))
#define ADC1SS3_Handler_EN (*(unsigned int*)(VTABLE_BASE + ADC1SS3_Handler_OFFSET))

#define GPIOAFSEL_F (*((unsigned int*)(HB_GPIOF_BASE + AFSEL_OFFSET)))
#define HB_GPIOFDEN (*((unsigned int*)(HB_GPIOF_BASE + GPIO_DEN_OFFSET))) //Digitally enable AHB_PORFTE with some Data it can use
#define HB_GPIOFDIR (*((unsigned int*)(HB_GPIOF_BASE + GPIO_DIR_OFFSET)))
#define HB_GPIOFDATA (*(((unsigned int*)(HB_GPIOF_BASE + GPIO_DATA_OFFSET))))


#define RCGCADC (*(unsigned int*)(SYSCTL + ADC_OFFSET))

#define SetEn_0_31_OFFSET 0x100U //enables vector Interrupt numbers from 0 to 31, for this project our vector interrupt number for timer0A is 19


#define RED (1U << 1)
#define BLUE (1U << 2)
#define GREEN (1U << 3)

volatile static unsigned int PE1_Dig_Input = 0;

void Timer0A_Handler ( void )
{

HB_GPIOFDATA ^= RED;

}

void ADC1SS3_Handler ( void )
{

ADCISC = (1U << 3);
HB_GPIOFDATA = BLUE;
PE1_Dig_Input = ADC1SS3FIFO;

}

//X means I programmed it correctly
int main()
{

RCGCADC = (1U << 1); //enable me to use ADC (X)
RCGCGPIO_PORT = (1U << 4) | (1U << 5); // I've enabled GPIOPORTE and PortF aswell (X)
GPIOHBCTL_PORT = (1U << 4) | (1U << 5); // High performance Bus PORTE and PortF (X)

HB_GPIOFDEN |= (RED | BLUE); // enabled RED
HB_GPIOFDIR |= (RED | BLUE); // I've set RED as an output
GPIOAFSEL_F = 0x00U;

//This is for ADC, using PORTE1
HB_GPIOEDIR = (0U << 1); // HBGPIOE_Pin_1 is now an input, shifting 1 bits to the left indicates I wish to use HBGPIOE1 as an input (X)
GPIOAFSEL_E = (1U << 1); //This is the Alternative function select, it allows me to use PE1 (X)
HB_GPIOEDEN = (0U << 1); //using HB_GPIOE 1 and disabling the Digital Enable (X)
HB_GPIOE_AMSEL = (1U << 1); //analog mode select, I shifted 1 to the left becauseI wanted to use PE1, which has analog input of 2, so 1 << 1 = 10 which 2 in binary (X)



ADC1_ACTSS3 &= ~(1U << 3);//clear the bits (X)
ADC1EMUX |= (0xF << 12); //This is the trigger select 0xF mean continous(X)
//ADC1SSPRI = (0x3U << 12); //(X) supposed to be lowest priority
ADC1SSMUX3 = 2; //(somethings an issue here)
ADCSSCTL3 = 0x6;//0x6 or 3'b110 (X)
ADCSS3IM = (1U << 3); //enable my type of interrupts to be used (X)

ADC1SS3_Handler_EN = (1U << 19);

ADC1_ACTSS3 |= (1U << 3); //enable analog digital converstion Sample sequencer 3
ADCISC = (1U << 3); //clear interrupt before using it


    while(1)
    {
        if(PE1_Dig_Input < 2435)
        {
                   HB_GPIOFDATA = 0x0;
        }
        else if(PE1_Dig_Input > 4035)
       {
                   HB_GPIOFDATA = (RED|BLUE);
        }

    }

}

  • Hello Sunny,

    Well the better way out is to first use the TivaWare example for ADC. This will be more useful to understand and debug the ADC and the micro controller. DRM is a good tool only when very experienced with the micro controller and want to optimize the code.

    Regards
    Amit
  • General Geo. Armstrong Custer said:
    7th CAV. is superior to (few) Indians!

    and

    Sunny Chan said:
    I've been using memory addresses in the hopes of developing my own library

    One notes - (same) bad outcome - poorly thought/considered objectives lead (most always) to "pain/suffering."   (hair-line modification...)

    Why on earth would poster "invite" such (unneeded/unwanted) complications?   Tried, true, tested solution (API), "knocks @ his doorstep!"

  • This is for educational reasons so I can better understand the controller. I find this an unwanted answer.
  • I've heard to take a look at Tivaware examples but I can't find them. I think another TI employee gave me a link to the library but I was confused on what to download. I am using the IAR embedded workbench simply because I have to start from somewhere. So I will continue using it so I can become more familiar with it.
  • Your educational reasons prove SO "educational" that you cannot achieve a most basic operation.   How does that make sense?

    If you reject tried/true (the API) - can that (ever) be considered, "educational"?

    The vendor's "Driver Library" provides all that you need - should you (really) seek education...

  • Hello Sunny,

    The software is available at the following link

    http://www.ti.com/tool/sw-tm4c

    Once installed the reference example code for ADC can be found at

    D:\ti\TivaWare_C_Series-2.1.2.111\examples\peripherals\adc

    Regards
    Amit
  • Thank you I appreciate this helpful information.
  • cb1 this will be my last response to you as you offered no real answer to my question nor suggestion other than "use an api". I have flagged both your responses as spam as it adds nothing to my question. First off I've been reading the micro-controller data sheet from the TM4123G. In case you don't know what I'm doing this is called SW/HW interface and embedded C programming. So yes this is an educational process and as expected I will not always get a desired output but I will LEARN what went wrong.

    If you seriously think ADC is basic from a hardware perspective then I'm assuming you've only been using API and have no real clue what happens behind the scenes. I do not wish to be as ignorant as you are. Unlike you I will provide something. Below me is the datasheet I'm using. No ABSTRACTIONS no Libraries, so I will LEARN how hardware is used in the hopes to develop my own no matter how inefficient it may be and despite how condescending you are.

    www.ti.com/.../tm4c123gh6pm.pdf
  • It would be of interest to note how one "ignorant" could co-found - take tech firm public. (and be 1 "per-center")

    You embarked upon the creation of "your own" GPIO library - did you not? And the fact that you did such - when a wondrous API stands at the ready - (may) qualify as "ignorant." Surely it signals extremely POOR investigatory skills.

    Vendor's Amit steered you away from DRM - did he not? If you were (at all) consistent - shouldn't that post receive "Sunny's spam notice" as well?

    If the "truth" so hurts - you may want to alter your reality...
  • If the "truth" so hurts - you may want to alter your reality...

    Quite often (and unfortunately), self-confidence is indirectly proportional to knowledge and insight.

    And, for most people, the "standard procedure" in case of cognitive dissonances (as those evoked by your post) is to suppress the unpleasant information.

  • Well said, Sir - attacking the hand which (really) is extended in "help" (even when unrecognized) proves unwise.

    And - clearly - I was, "Going for humor" w/the "good General's" equally poor decision.   Lack of US history likely caused that reference to "fly overhead"...

    As I'm tasked now w/training "eight" new hires/interns - I'm especially sensitive to the "best means of learning" - which was not the course chosen by our friend.