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.

Related to GPIO initialization

Other Parts Discussed in Thread: TMS320F28335

I am working with tms320f28335. Currently I am working on programing for generating PWM using sine triangular technique. so for that i need to initialize GPIO pin. here i am attaching my code can u please tell me the problem with initilization?????????
 #include "DSP28335_Regs.h"
 #include "DSP28335_RegDef.h"
 #include "adc.h"
 #include "Pwms.h"
 #include "gpio.h"
 
void main(void)
{        
    DemoADC.stop = 0;
    DemoADC.ret_val_mon = 1;
    DemoADC.count_saved = 0;
    DemoADC.count_adc = 0;
   DemoADC.timer_period = 0xFFF0;
    DemoADC.n_samples = 1000;
    DemoADC.ch_sel1 = 0x0021;
    DemoADC.ch_sel2 = 0;
    DemoADC.ch_sel3 = 0;
    DemoADC.ch_sel4 = 0;
    DemoADC.max_ch = 1;
        
 


        EALLOW;                                           // Enable writing to EALLOW protected registers
    SysCtrlRegs.HISPCP.bit.HSPCLK = 0;                // HSPCLK = SYSCLKOUT / 1 = 150MHz
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;            // Start all the timers synced
    EDIS;                                             // Disable writing to EALLOW protected areas

    EALLOW;                                           // Enable writing to EALLOW protected registers
    SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK=1;             // Enable ePWM1 clock
    SysCtrlRegs.PCLKCR0.bit.ADCENCLK=1;               // Enable ADC clock
    EDIS;

         EALLOW;
         GpioCtrlRegs.GPAMUX1.bit.GPIO0=1;
          EDIS;
     
    // Allow synchronization
    EPwm1Regs.TBCTL.bit.SYNCOSEL = 0;                 // Pass through
    EPwm1Regs.TBCTL.bit.PHSEN = 0;                    // Phase loading disabled
    EPwm1Regs.TBCTL.bit.CLKDIV = 0;                   // Clock ratio to SYSCLKOUT
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;                //
    EPwm1Regs.TBPHS.half.TBPHS = 0;                   // Set Phase register to zero

    EPwm1Regs.TBPRD = DemoADC.timer_period;           // Set timer period
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;    // Count up-down


    EALLOW;                                           // Enable writing to the EALLOW protected areas
    PieVectTable.ADCINT = &adc_isr;                   // Set the interrupt vector for ADC interrupt                                
    EDIS;                                             // Disable writing to the EALLOW protected areas    

    EALLOW;                                           // Enable writing to the EALLOW protected areas
    AdcRegs.ADCTRL3.all = 0x00E0;                     // Power up bandgap/reference/ADC circuits
    DELAY_US(5000);                                   // Delay before converting ADC channels
    EDIS;                                             // Disable writing to the EALLOW protected areas
    AdcRegs.ADCTRL1.bit.SEQ_CASC=1;
    AdcRegs.ADCTRL1.bit.ACQ_PS = 0xF;                 // S/H width in ADC module periods                  = 16 ADC clocks
    AdcRegs.ADCTRL3.bit.ADCCLKPS = 3;                 // ADC module clock = HSPCLK/(1*8)   = 150MHz/(1*8) = 18.75MHz

// Set Maximum Conversion Channels Register:
    AdcRegs.ADCMAXCONV.all = DemoADC.max_ch;          // Setup the number of conv's on SEQ1
// Initialize ADC Input Channel Select Sequencing Control Register:
    AdcRegs.ADCCHSELSEQ1.all = DemoADC.ch_sel1;       // Setup the 1st to 4th SEQ1 conv.
    AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;           // Enable SOCA from ePWM to start SEQ1
    AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;             // Enable SEQ1 interrupt (every EOS)
    
    // Start ADC with timer 1 event:    
    EPwm1Regs.ETSEL.bit.SOCAEN = 1;                   // Enable SOC on A group
    EPwm1Regs.ETSEL.bit.SOCASEL = 1;                  // Generate SOC when time-base counter equal to zero.
    EPwm1Regs.ETPS.bit.SOCAPRD = 1;                   // Generate pulse on 1st event

    // start PWM generation
    EALLOW;                                           // Enable writing to EALLOW protected registers
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;            // Start all the timers synced
    EDIS;                                             // Disable writing to EALLOW protected areas
    DELAY_US(500);                                    // Delay before converting ADC channels

// Enable ADCINT in PIE
   PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
   PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
  IER |= M_INT1; // Enable CPU Interrupt 1

      EINT;                                             // Enable Global interrupt INTM
    ERTM;                                             // Enable Global realtime interrupt DBGM
 

// Generate system reset
    DINT;
    EALLOW;                                     // Enable writing to EALLOW protected registers
    SysCtrlRegs.WDCR = 0x000F;                  // Enable Watchdog and write incorrect WD Check Bits
                                               // (001 in lieu of 101) to force a system reset
    asm(" NOP");
    asm(" NOP");
    asm(" NOP");

 }     
int count_adc;
int n_samples;
/*unsigned int ad0;
unsigned int ad1;*/

//===========================================
// ADC interrupt service routine
//===========================================

interrupt void adc_isr(void)
{
    long int a=AdcRegs.ADCRESULT0;
    long int b=AdcRegs.ADCRESULT1;
           EALLOW;
            
                     GpioCtrlRegs.GPADIR.bit.GPIO0=1;
    EDIS;

    if(a>b)
                 
              GpioDataRegs.GPASET.bit.GPIO0=1;
                
  else
                
                GpioDataRegs.GPACLEAR.bit.GPIO0=1;
                        
        
// Reinitialize for next ADC sequence
    AdcRegs.ADCTRL2.bit.RST_SEQ1 =1 ;            // Reset SEQ1
    AdcRegs.ADCST.bit.INT_SEQ1_CLR =1 ;          // Clear INT SEQ1 bit
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;      // Acknowledge interrupt to PIE

}
void Delay(unsigned long LoopCnt)
{
    unsigned long i;
    
    for (i = 0; i < LoopCnt; i++){}
}

  • Hi Manan,

    Here's how one has to initialize ePWMs for F28335:

    // TI File $Revision: /main/1 $
    // Checkin $Date: August 18, 2006   13:46:19 $
    //###########################################################################
    //
    // FILE:   DSP2833x_EPwm.c
    //
    // TITLE:  DSP2833x ePWM Initialization & Support Functions.
    //
    //###########################################################################
    // $TI Release: DSP2833x/DSP2823x C/C++ Header Files V1.31 $
    // $Release Date: August 4, 2009 $
    //###########################################################################
    
    #include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
    #include "DSP2833x_Examples.h"   // DSP2833x Examples Include File
    
    //---------------------------------------------------------------------------
    // InitEPwm: 
    //---------------------------------------------------------------------------
    // This function initializes the ePWM(s) to a known state.
    //
    void InitEPwm(void)
    {
       // Initialize ePWM1/2/3/4/5/6
    
       //tbd...
     
    }
    
    //---------------------------------------------------------------------------
    // Example: InitEPwmGpio: 
    //---------------------------------------------------------------------------
    // This function initializes GPIO pins to function as ePWM pins
    //
    // Each GPIO pin can be configured as a GPIO pin or up to 3 different
    // peripheral functional pins. By default all pins come up as GPIO
    // inputs after reset.  
    // 
    
    void InitEPwmGpio(void)
    {
       InitEPwm1Gpio();
       InitEPwm2Gpio();
       InitEPwm3Gpio();
    #if DSP28_EPWM4
       InitEPwm4Gpio();
    #endif // endif DSP28_EPWM4
    #if DSP28_EPWM5    
       InitEPwm5Gpio();
    #endif // endif DSP28_EPWM5
    #if DSP28_EPWM6
       InitEPwm6Gpio();
    #endif // endif DSP28_EPWM6 
    }
    
    void InitEPwm1Gpio(void)
    {
       EALLOW;
       
    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user. 
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0;    // Enable pull-up on GPIO0 (EPWM1A)
        GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0;    // Enable pull-up on GPIO1 (EPWM1B)   
       
    /* Configure ePWM-1 pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be ePWM1 functional pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;   // Configure GPIO0 as EPWM1A
        GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;   // Configure GPIO1 as EPWM1B
       
        EDIS;
    }
    
    void InitEPwm2Gpio(void)
    {
       EALLOW;
    	
    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user. 
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAPUD.bit.GPIO2 = 0;    // Enable pull-up on GPIO2 (EPWM2A)
        GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0;    // Enable pull-up on GPIO3 (EPWM3B)
    
    /* Configure ePWM-2 pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be ePWM2 functional pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;   // Configure GPIO2 as EPWM2A
        GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;   // Configure GPIO3 as EPWM2B
       
        EDIS;
    }
    
    void InitEPwm3Gpio(void)
    {
       EALLOW;
       
    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user. 
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAPUD.bit.GPIO4 = 0;    // Enable pull-up on GPIO4 (EPWM3A)
        GpioCtrlRegs.GPAPUD.bit.GPIO5 = 0;    // Enable pull-up on GPIO5 (EPWM3B)
           
    /* Configure ePWM-3 pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be ePWM3 functional pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1;   // Configure GPIO4 as EPWM3A
        GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1;   // Configure GPIO5 as EPWM3B
    	
        EDIS;
    }
    
    
    #if DSP28_EPWM4
    void InitEPwm4Gpio(void)
    {
       EALLOW;
    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user. 
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0;    // Enable pull-up on GPIO6 (EPWM4A)
        GpioCtrlRegs.GPAPUD.bit.GPIO7 = 0;    // Enable pull-up on GPIO7 (EPWM4B)
    
    /* Configure ePWM-4 pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be ePWM4 functional pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 1;   // Configure GPIO6 as EPWM4A
        GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 1;   // Configure GPIO7 as EPWM4B
    	
        EDIS;
    }
    #endif // endif DSP28_EPWM4  
    
    
    #if DSP28_EPWM5
    void InitEPwm5Gpio(void)
    {
       EALLOW;
    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user. 
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAPUD.bit.GPIO8 = 0;    // Enable pull-up on GPIO8 (EPWM5A)
        GpioCtrlRegs.GPAPUD.bit.GPIO9 = 0;    // Enable pull-up on GPIO9 (EPWM5B)
    
    /* Configure ePWM-5 pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be ePWM5 functional pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 1;   // Configure GPIO8 as EPWM5A
        GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 1;   // Configure GPIO9 as EPWM5B
    	
        EDIS;
    }
    #endif // endif DSP28_EPWM5
    
    
    #if DSP28_EPWM6
    void InitEPwm6Gpio(void)
    {
       EALLOW;
    
    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user. 
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAPUD.bit.GPIO10 = 0;    // Enable pull-up on GPIO10 (EPWM6A)
        GpioCtrlRegs.GPAPUD.bit.GPIO11 = 0;    // Enable pull-up on GPIO11 (EPWM6B)
    
    /* Configure ePWM-6 pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be ePWM6 functional pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 1;   // Configure GPIO10 as EPWM6A
        GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 1;   // Configure GPIO11 as EPWM6B
    	
        EDIS;
    }
    #endif // endif DSP28_EPWM6  
    
    //---------------------------------------------------------------------------
    // Example: InitEPwmSyncGpio: 
    //---------------------------------------------------------------------------
    // This function initializes GPIO pins to function as ePWM Synch pins
    //
    
    void InitEPwmSyncGpio(void)
    {
    
       EALLOW;
    
    /* Configure EPWMSYNCI  */
       
    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user. 
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    
       GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0;    // Enable pull-up on GPIO6 (EPWMSYNCI)
    // GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;   // Enable pull-up on GPIO32 (EPWMSYNCI)    
    
    /* Set qualification for selected pins to asynch only */
    // This will select synch to SYSCLKOUT for the selected pins.
    // Comment out other unwanted lines.
    
       GpioCtrlRegs.GPAQSEL1.bit.GPIO6 = 0;   // Synch to SYSCLKOUT GPIO6 (EPWMSYNCI)
    // GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 0;  // Synch to SYSCLKOUT GPIO32 (EPWMSYNCI)    
    
    /* Configure EPwmSync pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be EPwmSync functional pins.
    // Comment out other unwanted lines.   
    
       GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 2;    // Enable pull-up on GPIO6 (EPWMSYNCI)
    // GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 2;   // Enable pull-up on GPIO32 (EPWMSYNCI)    
    
    
    
    /* Configure EPWMSYNC0  */
    
    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user. 
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    
    // GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0;    // Enable pull-up on GPIO6 (EPWMSYNC0)
       GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;   // Enable pull-up on GPIO33 (EPWMSYNC0)    
    
    // GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 3;    // Enable pull-up on GPIO6 (EPWMSYNC0)
       GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 2;   // Enable pull-up on GPIO33 (EPWMSYNC0)    
    
    }
    
    
    
    //---------------------------------------------------------------------------
    // Example: InitTzGpio: 
    //---------------------------------------------------------------------------
    // This function initializes GPIO pins to function as Trip Zone (TZ) pins
    //
    // Each GPIO pin can be configured as a GPIO pin or up to 3 different
    // peripheral functional pins. By default all pins come up as GPIO
    // inputs after reset.  
    // 
    
    void InitTzGpio(void)
    {
       EALLOW;
       
    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user. 
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
       GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;    // Enable pull-up on GPIO12 (TZ1)
       GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;    // Enable pull-up on GPIO13 (TZ2)
       GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0;    // Enable pull-up on GPIO14 (TZ3)
       GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0;    // Enable pull-up on GPIO15 (TZ4)
    
       GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;    // Enable pull-up on GPIO16 (TZ5)
    // GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0;    // Enable pull-up on GPIO28 (TZ5)
    
       GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;    // Enable pull-up on GPIO17 (TZ6) 
    // GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0;    // Enable pull-up on GPIO29 (TZ6)  
       
    /* Set qualification for selected pins to asynch only */
    // Inputs are synchronized to SYSCLKOUT by default.  
    // This will select asynch (no qualification) for the selected pins.
    // Comment out other unwanted lines.
    
       GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3;  // Asynch input GPIO12 (TZ1)
       GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 3;  // Asynch input GPIO13 (TZ2)
       GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 3;  // Asynch input GPIO14 (TZ3)
       GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3;  // Asynch input GPIO15 (TZ4)
    
       GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3;  // Asynch input GPIO16 (TZ5)
    // GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3;  // Asynch input GPIO28 (TZ5)
    
       GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3;  // Asynch input GPIO17 (TZ6) 
    // GpioCtrlRegs.GPAQSEL2.bit.GPIO29 = 3;  // Asynch input GPIO29 (TZ6)  
    
       
    /* Configure TZ pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be TZ functional pins.
    // Comment out other unwanted lines.   
       GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;  // Configure GPIO12 as TZ1
       GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 1;  // Configure GPIO13 as TZ2
       GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 1;  // Configure GPIO14 as TZ3
       GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 1;  // Configure GPIO15 as TZ4
    
       GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 3;  // Configure GPIO16 as TZ5
    // GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 3;  // Configure GPIO28 as TZ5
    
       GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 3;  // Configure GPIO17 as TZ6               
    // GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 3;  // Configure GPIO29 as TZ6  
    
       EDIS;
    }
    
    
    
    //===========================================================================
    // End of file.
    //===========================================================================
    

    Regards,

    Gautam

  • hi Gautam,

    I have already initialize what you have sent but i am not getting the output kindly suggest any other ans. if you know...

    Thanks...

  • I hope you're not experiencing any errors while building. When you go for continuous debug mode, only then you don't get any output right?

    Regards,

    Gautam