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.

LM4F232H5QD ADC can't configurate - debuger freezes

Other Parts Discussed in Thread: TEST2

Hi,

i'm trying to configurate and use ADC peripherials with no result. I attached part of code below.

When i'm in ADCConfig at line ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0); deguger freezes and stop responding. I have no idea what is wrong. Please help me to solve this problem. Best regards

void ADCConfig(void){
     //
        // Enable the ADC peripherals and the associated GPIO port
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        //SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        //
        // Configure the pins to be used as analog inputs.
        //
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |
                       GPIO_PIN_2 | GPIO_PIN_3);// konfiguracja pinó na złączu ark
        GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3); // 5 pin na goldpin pd3 ain12
        //AIN3 AIN2 AIN 1 AIN 0 i AIN12
       // ADCIntEnable(ADC0_BASE,1);
              //  ADCIntEnable(ADC1_BASE,1);


        ADCSequenceDisable(ADC0_BASE, 0);
       // ADCSequenceDisable(ADC1_BASE, 1);
        //ustawienie próbkowania
        SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);
        //SysCtlDelay(1000);

      //  while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)){;}
        ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
        ADCSequenceStepConfigure(ADC0_BASE,0,0,ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE,0,1,ADC_CTL_CH1);
        ADCSequenceStepConfigure(ADC0_BASE,0,2,ADC_CTL_CH2);
        ADCSequenceStepConfigure(ADC0_BASE,0,3,ADC_CTL_CH3);
        ADCSequenceStepConfigure(ADC0_BASE,0,4,ADC_CTL_CH12 | ADC_CTL_IE | ADC_CTL_END);
        ADCIntEnable(ADC0_BASE, 3);
        ADCSequenceEnable(ADC0_BASE, 0);
        ADCIntEnable(ADC0_BASE, 0);
        IntEnable(INT_ADC0SS0);

}////////////////////////////////////////////////////////////////////////////////////////////////////////
//*******************************************************************************
//////////////////////////////////////////////////////////////////////////
////////////////////////////// TIMER///////////////
void TimerSet(void){
        SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
        //SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER0);
      ulPeriod = (SysCtlClockGet() / ulFrequency); //60K is close to max freq. period of 250
      TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
         TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / ulFrequency);
        TimerControlTrigger(TIMER0_BASE,TIMER_A,true);
        TimerEnable(TIMER0_BASE, TIMER_A);
        TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
        SysCtlDelay(1000);

      // ADCIntClear(ADC0_BASE, 0);     // Clear any outstanding Interrupts
       SysCtlDelay(1000);
       ; //ALLOW --  start of the collection Chain

       IntEnable(INT_ADC0SS1); // Turn on Sequence Interrupts fo Seq. 1
        IntMasterEnable();         // Finally -- enable all interrupts and go.
        //
}

  • MatthewFirst said:
    When i'm in ADCConfig at line ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0); deguger freezes and stop responding. I have no idea what is wrong.

     Hi, which IDE and which JTAG are you using for?

     Are all setting ok before this, is ISRFault service in place?

  • Hello,

    I'm using EKC-lm4F232 kit REL B. The problem is that uC stops on this line and doesn't continue.

    -----------------------------------------------------------------------------------------------------------------------------------------

    Now it works fine. I'm able to set up all peripherials, but i've got another problem in ADCINTHandler if i only have  UARTprintf("Przetwornik petla!\n"); i am not able to control the interupt frequency by  ulFrequency=8000000;
          TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / ulFrequency); and also when i try to read adc and pass it throgut uart, i only get one masage "Przetwornik wartosc value_here" and stops. When i comment everything and left UARTprintf("Przetwornik petla!\n"); it's working periodicly

    void  ADCIntHandler(void){
        uint32_t ulADC0Value;
        UARTprintf("Przetwornik petla!\n");
        SysCtlDelay(1000000);
        ROM_ADCSequenceDataGet(ADC0_BASE, 0, &ulADC0Value);
        //UARTprintf("\033[2J os X%d os Y%d os Z%d\r",ulADC0Value);
        UARTprintf("Przetwornik wartosc %d",ulADC0Value);

        ADCIntClear(ADC0_BASE, 0);

    ---------------------------------------------

    this is code for lm4f120xl the same problem.

    //*****************************************************************************
    //
    // hello.c - Simple hello world example.
    //
    // Copyright (c) 2012 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    //
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    //
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    //
    // This is part of revision 9453 of the EK-LM4F120XL Firmware Package.
    //
    //*****************************************************************************
    #include <stdint.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "utils/uartstdio.h"
    #include "driverlib/gpio.h"
    #include "utils/ustdlib.h"
    #include "inc/hw_types.h"
    #include "driverlib/adc.h"
    #include "driverlib/timer.h"
    #include "inc/hw_ints.h"

    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"

    //*****************************************************************************
    //
    //! \addtogroup example_list
    //! <h1>Hello World (hello)</h1>
    //!
    //! A very simple ``hello world'' example.  It simply displays ``Hello World!''
    //! on the UART and is a starting point for more complicated applications.
    //!
    //! UART0, connected to the Stellaris Virtual Serial Port and running at
    //! 115,200, 8-N-1, is used to display messages from this application.
    //
    //*****************************************************************************


    void TimerSet(void){
            SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
            //SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER0);
            unsigned long ulFrequency;
          TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);
          ulFrequency=80000;
          TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / ulFrequency);
           TimerControlTrigger(TIMER0_BASE,TIMER_A,true);
           TimerEnable(TIMER0_BASE, TIMER_A);
           SysCtlDelay(1000);
           TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
            SysCtlDelay(1000);

    //       ADCIntClear(ADC0_BASE, 0);     // Clear any outstanding Interrupts

           ; //ALLOW --  start of the collection Chain

           IntEnable(INT_ADC0SS1); // Turn on Sequence Interrupts fo Seq. 1
            IntMasterEnable();         // Finally -- enable all interrupts and go.
            //
    }

    void ADCConfig(void){
         //
            // Enable the ADC peripherals and the associated GPIO port
            //
            SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
            //SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
            SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
            SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
            //
            // Configure the pins to be used as analog inputs.
            //
            GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 );// konfiguracja pinó na złączu ark
            GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1 | GPIO_PIN_2); // 5 pin na goldpin pd3 ain12
            //AIN3 AIN2 AIN 1 AIN 0 i AIN12
           // ADCIntEnable(ADC0_BASE,1);
                  //  ADCIntEnable(ADC1_BASE,1);

           //wyłączenie sekensera
            ADCSequenceDisable(ADC0_BASE, 0);

            //ustawienie próbkowania

            SysCtlDelay(1000);
            //ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
            while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)){}
            ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);

            ROM_ADCSequenceStepConfigure(ADC0_BASE,0,0,ADC_CTL_CH7);
            ROM_ADCSequenceStepConfigure(ADC0_BASE,0,1,ADC_CTL_CH6);
            ROM_ADCSequenceStepConfigure(ADC0_BASE,0,2,ADC_CTL_CH5);
            ROM_ADCSequenceStepConfigure(ADC0_BASE,0,3,ADC_CTL_CH2);
            ROM_ADCSequenceStepConfigure(ADC0_BASE,0,4,ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
            //ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);
            //ROM_ADCIntEnable(ADC0_BASE, 3);
            ROM_ADCSequenceEnable(ADC0_BASE, 0);
            SysCtlDelay(1000);
            ROM_ADCIntEnable(ADC0_BASE, 0);
            SysCtlDelay(1000);
            IntEnable(INT_ADC0SS0);
               // interrupt on ADC1 to toggle between sequences
            SysCtlDelay(1000);       // interrupt on ADC1 to toggle between sequences



    }///////////////////////////////////////

    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, unsigned long ulLine)
    {
    }
    #endif

    //*****************************************************************************
    //
    // Print "Hello World!" to the UART on the Stellaris evaluation board.
    //
    //*****************************************************************************
    int
    main(void)
    {
        volatile unsigned long ulLoop;

        //
        // Enable lazy stacking for interrupt handlers.  This allows floating-point
        // instructions to be used within interrupt handlers, but at the expense of
        // extra stack usage.
        //
        ROM_FPULazyStackingEnable();

        //
        // Set the clocking to run directly from the crystal.
        //
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                           SYSCTL_OSC_MAIN);

                           
        //
        // Enable the GPIO port that is used for the on-board LED.
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

        //
        // Enable the GPIO pins for the LED (PF2 & PF3).  
        //
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

                           
        //
        // Initialize the UART.
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
        ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
        ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
        UARTStdioInit(0);

        //
        // Hello!
        //
        UARTprintf("Hello, world!\n");
        TimerSet();
        ADCConfig();
        //
        // We are finished.  Hang around doing nothing.
        //
        while(1)
        {
            //
            // Turn on the BLUE LED.
            //
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

            //
            // Delay for a bit.
            //
            SysCtlDelay(SysCtlClockGet() / 10 / 3);

            //
            // Turn off the BLUE LED.
            //
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
            
            //
            // Delay for a bit.
            //
            SysCtlDelay(SysCtlClockGet() / 10 / 3);    }
    }
    void  Timer0IntHandler(void){UARTprintf("test2\n");

    }
    void  ADCIntHandler(void){
        //ADCIntClear(ADC0_BASE, 0);
        //ROM_TimerIntClear(TIMER2_BASE, TIMER_CAPA_EVENT);
        TimerDisable(TIMER0_BASE, TIMER_A);
        unsigned long ulADC0Value;
        ROM_ADCProcessorTrigger(ADC0_BASE, 0);
        UARTprintf("Przetwornik petla!\n");
        SysCtlDelay(1000000);
        ROM_ADCSequenceDataGet(ADC0_BASE, 0, &ulADC0Value);
        //UARTprintf("\033[2J os X%d os Y%d os Z%d\r",ulADC0Value);
        UARTprintf("Przetwornik wartosc %d",ulADC0Value);

        //ADCIntClear(ADC0_BASE, 0);
        TimerEnable(TIMER0_BASE, TIMER_A);
        UARTprintf("Przetwornik koniec!\n");
        //unsigned long samples_aquired;

        //samples_aquired = ADCSequenceDataGet(ADC0_BASE, 0, &adc_data[0]);
    }