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.

TM4C123GH6PM: Peak Overshoot problem during Sampling.

Part Number: TM4C123GH6PM
#define PWM_FREQUENCY 55

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/pwm.h"
#include "driverlib/adc.h"
uint32_t sysclock;
uint32_t input_value;
uint32_t i;
int sample_val[100],pinVal,pinVal1;
extern  unsigned long ulADC0Value[100];




//PG1 is the PWM Pin
void main()
{

 // 600KHz Signal on    PE5

  //  float PWM_FREQ;
  //  float CPU_FREQ;
  //  float pwm_word;



  //  PWM_FREQ = 1434; //
   // CPU_FREQ = 120000000;
   // pwm_word = (1/PWM_FREQ)*CPU_FREQ;
    //sysclock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), CPU_FREQ);


    SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_5);
    GPIOPinConfigure(GPIO_PE5_M0PWM5);
    PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_DB_NO_SYNC);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 200); //Setting for 200KHz
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 200); // 50% Duty Cycle
    PWMGenEnable(PWM0_BASE, PWM_GEN_2);
    PWMOutputState(PWM0_BASE, PWM_OUT_5_BIT, true);

    uint32_t PWMClock = SysCtlClockGet() / 64;
    uint32_t Load = (PWMClock / PWM_FREQUENCY) - 1;

    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, Load);
    while(1);




    //ADC Sampling on PE3

      // SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);


       GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);


        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 266);
        ADCSequenceDisable(ADC0_BASE, 1);

        ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PWM0*3, 0);
        ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0);
        ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
                   ADCSequenceEnable(ADC0_BASE, 1);

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

                                 while(!ADCIntStatus(ADC0_BASE, 1, false))
                                 {


                                 }

                                 ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value[100]);
                                // uint32_t pinVal; // variable to hold the pinRead
                                 pinVal= GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_3);
                                pinVal1= GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4);
                                 int a=0;

                                 for ( a=1;a<=1; a++){

                              uint32_t res=a;

                                 }




/*for (i=0;i<100;i++){
int a=GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_3);

uint32_t adc_val[]=
}*/

}

}

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

I am facing certain problem during debugging. Here, I am generating a signal in a pin of the MCU and then sampling the signal using the ADC.

I get to warnings which seem to have some effect in my code.

#112-D statement is unreachable    project.c    /ADC_Sampling2    line 66    C/C++ Problem
#169-D argument of type "unsigned long" is incompatible with parameter of type "uint32_t *"    project.c    /ADC_Sampling2    line 91    C/C++ Problem
#177-D subscript out of range    project.c    /ADC_Sampling2    line 91    C/C++ Problem

I am not sure why I get those warning. Secondly, during the graphical analysis I am seeing a irrelavantpeak rise, causes unknown. I am attaching the graph image.

  • Hello,

    Soumyadeb Bhattacharjee said:

    get to warnings which seem to have some effect in my code.

    #112-D statement is unreachable    project.c    /ADC_Sampling2    line 66    C/C++ Problem
    #169-D argument of type "unsigned long" is incompatible with parameter of type "uint32_t *"    project.c    /ADC_Sampling2    line 91    C/C++ Problem
    #177-D subscript out of range    project.c    /ADC_Sampling2    line 91    C/C++ Problem

    Clearing up the several warnings would be the first step would it not? The first one 112-D is a code killer, 169-D integer type mismatch must be corrected, 177-D subscript # is set incorrectly in the array.

    Double click on the warning in CCS Problems tab left view pane will take you to the code in error.

  • I am getting #112-D statement is unreachable project.c /ADC_Sampling2 line 66 C/C++ Problem for
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    and I am unable to find it's cause.

    and for #169-D, I have changed the datatype to uint_32

    #169-D argument of type "uint32_t" is incompatible with parameter of type "uint32_t *" project.c /ADC_Sampling2 line 91 C/C++ Problem
    which I don't understand because I getting type mismatch error for the same datatypes.

    and I did not understand #177-D
  • Soumyadeb Bhattacharjee said:
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    and I am unable to find it's cause

    Line 56 While(1); is missing {} and has return ;

    Soumyadeb Bhattacharjee said:
    and for #169-D, I have changed the datatype to uint_32

    Your code syntax is not visible in forum Quote mode so we can't refer to your posted code snips.

    Perhaps try (&ui32MyVariable) versus an array, omit the (). 

  • The statement on line 56:

     

      while(1);

    This puts the CPU into an infinite branch to self (doing nothing). None of the rest of the statements are executed. I think you should delete that line.


  • #10010 null: errors encountered during linking; "ADC_Sampling2.out" not built    ADC_Sampling2             C/C++ Problem
    <a href="processors.wiki.ti.com/.../10234"> null: unresolved symbols remain    ADC_Sampling2             C/C++ Problem
    gmake: *** [ADC_Sampling2.out] Error 1    ADC_Sampling2             C/C++ Problem
    gmake: Target 'all' not remade because of errors.    ADC_Sampling2             C/C++ Problem
    unresolved symbol ulADC0Value, first referenced in ./project.obj    ADC_Sampling2             C/C++ Problem

    I am getting these errors after removing the while loop , I don't see any highlighted red lines in my code. I unable to understand the cause of these errors.

  • Sir, I was able to resolve #169-D but wasn't able to solve #112-D even after putting on the curly brackets. I was suggested to remove the while loop below but after removing the while loop and getting 5 new errors which I have mentioned below.
  • Where did you put the brackets? What is the purpose of that while loop? You seem to be struggling understanding basic C code. Teaching C is not really the purpose of this forum, and is very inefficient for you and for me. I suggest that you contact your professor or teaching assistant for this help.
  • Brackets were for the while loop, after removing the while loop I got the errors;.

    Description    Resource    Path    Location    Type
    #10010 null: errors encountered during linking; "ADC_Sampling2.out" not built    ADC_Sampling2             C/C++ Problem
    <a href="processors.wiki.ti.com/.../10234"> null: unresolved symbols remain    ADC_Sampling2             C/C++ Problem
    gmake: Target 'all' not remade because of errors.    ADC_Sampling2             C/C++ Problem
    unresolved symbol ulADC0Value, first referenced in ./project.obj    ADC_Sampling2             C/C++ Problem

  • Soumyadeb Bhattacharjee said:
    null: unresolved symbols remain    

    Your code may be referring to a variable/s in another module where an include path to such variable is missing. 

  • #define PWM_FREQUENCY 55
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pwm.h"
    #include "driverlib/adc.h"

    uint32_t sysclock;
    uint32_t input_value;
    uint32_t i;
    int sample_val[100],pinVal,pinVal1;
    uint32_t ulADC0Value[100];




    //PG1 is the PWM Pin
    void main()
    {

     // 600KHz Signal on    PE5

      //  float PWM_FREQ;
      //  float CPU_FREQ;
      //  float pwm_word;



      //  PWM_FREQ = 1434; //
       // CPU_FREQ = 120000000;
       // pwm_word = (1/PWM_FREQ)*CPU_FREQ;
        //sysclock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), CPU_FREQ);


        SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
        GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_5);
        GPIOPinConfigure(GPIO_PE5_M0PWM5);
        PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_DB_NO_SYNC);
        PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 200); //Setting for 200KHz
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 200); // 50% Duty Cycle
        PWMGenEnable(PWM0_BASE, PWM_GEN_2);
        PWMOutputState(PWM0_BASE, PWM_OUT_5_BIT, true);

        uint32_t PWMClock = SysCtlClockGet() / 64;
        uint32_t Load = (PWMClock / PWM_FREQUENCY) - 1;

        PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, Load);
         //while(1){}




        //ADC Sampling on PE3

          SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);


           GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);


            SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
            ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 266);
            ADCSequenceDisable(ADC0_BASE, 1);

            ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PWM0*3, 0);
            ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
            ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH0);
            ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0);
            ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
                       ADCSequenceEnable(ADC0_BASE, 1);

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

                                     while(!ADCIntStatus(ADC0_BASE, 1, false))
                                     {


                                     }

                                     ADCSequenceDataGet(ADC0_BASE, 1, &ulADC0Value[100]);
                                    // uint32_t pinVal; // variable to hold the pinRead
                                     pinVal= GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_3);
                                    pinVal1= GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4);
                                     int a=0;

                                     for ( a=1;a<=1; a++){

                                 // uint32_t res=a;

                                     }




    /*for (i=0;i<100;i++){
    int a=GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_3);

    uint32_t adc_val[]=
    }*/

    }

    }


    Currently, in this code there are no errors or warnings. But I am still getting the peak overshoot which I had mentioned earliier and I am unable to fix it.

  • Hello Soumyadeb,

    We came across this thread as one of the ones that had been opened to help you with your ADC issues, as Bob was able to help resolve these issues on another thread in the meantime, I am going to go ahead and mark this as a closed issue as well.