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.

Enable and Disable GPIO's in 28335

Hi,

I have programmed to GPIO pins from GPIO-0/1/2/3/4/5 which are PWM1A/1B, PWM2A/2B and PWM3A/3B.

1.  When I want to disable the PWM's 1/2/3, I am setting the following GPIO pins to LOW that is GPIO0/1, GPIO2/3 and GPIO4/5 bit to 0.  I am not sure whether I need to set the

    GPIO control registers everytime to perform.   Can I use

  GpioDataRegs.GPACLEAR.bit.GPIO0     = 0;   // SET INPUT TO LOW

  GpioDataRegs.GPASET.bit.GPIO1       = 1;   // SET INPUT TO HIGH.   without performing on GPIO control registers? Please clarify?

 Code:                                                           
{                                                                                   
    // PWM1a & PWM 1B are set to ZERO in GPIO Pin 0 and 1.                          
    EALLOW;                                                                         
    GpioCtrlRegs.GPAPUD.bit.GPIO0       = 1;   // Enable pulldown on GPIO0   PWM-1A 
    GpioCtrlRegs.GPAMUX1.bit.GPIO0      = 0;   // GPIO0 = GPIO0                     
    GpioCtrlRegs.GPADIR.bit.GPIO0       = 1;   // GPIO0 = output                    
    EDIS;                                                                           
    GpioDataRegs.GPACLEAR.bit.GPIO0     = 0;   // SET INPUT TO LOW.                 
                                                                                    
    EALLOW;                                                                         
    GpioCtrlRegs.GPAPUD.bit.GPIO1       = 1;   // Enable pulldown on GPIO1   PWM-1B 
    GpioCtrlRegs.GPAMUX1.bit.GPIO1      = 0;   // GPIO1 = GPIO1                     
    GpioCtrlRegs.GPADIR.bit.GPIO1       = 1;   // GPIO1 = output                    
    EDIS;                                                                           
    GpioDataRegs.GPACLEAR.bit.GPIO1     = 0;   // SET INPUT TO LOW.                 
                                                                                    
                                                                                    
    // PWM2A & PWM 2B are set to ZERO in GPIO Pin 2 and 3                           
    EALLOW;                                                                         
    GpioCtrlRegs.GPAPUD.bit.GPIO2       = 1;   // Enable pulldown on GPIO2   PWM-2A 
    GpioCtrlRegs.GPAMUX1.bit.GPIO2      = 0;   // GPIO2 = GPIO2                     
    GpioCtrlRegs.GPADIR.bit.GPIO2       = 1;   // GPIO2 = output                    
    EDIS;                                                                           
    GpioDataRegs.GPACLEAR.bit.GPIO2     = 0;   // SET INPUT TO LOW                  
                                                                                    
                                                                                    
    EALLOW;                                                                         
    GpioCtrlRegs.GPAPUD.bit.GPIO3       = 1;   // Enable pulldown on GPIO2   PWM-2B 
    GpioCtrlRegs.GPAMUX1.bit.GPIO3      = 0;   // GPIO3 = GPIO3                     
    GpioCtrlRegs.GPADIR.bit.GPIO3       = 1;   // GPIO3 = output                    
    EDIS;                                                                           
    GpioDataRegs.GPACLEAR.bit.GPIO3     = 0;   // SET INPUT TO LOW                  
                                                                                    
                                                                                    
    // PWM3A & PWM 3B are set to ZERO in GPIO Pin 4 and 5                           
    EALLOW;                                                                         
    GpioCtrlRegs.GPAPUD.bit.GPIO4       = 1;   // Enable pulldown on GPIO2   PWM-3A 
    GpioCtrlRegs.GPAMUX1.bit.GPIO4      = 0;   // GPIO4 = GPIO4                     
    GpioCtrlRegs.GPADIR.bit.GPIO4       = 1;   // GPIO4 = output                    
    EDIS;                                                                           
    GpioDataRegs.GPACLEAR.bit.GPIO4     = 0;   // SET INPUT TO LOW                  
                                                                                    
                                                                                    
    EALLOW;                                                                         
    GpioCtrlRegs.GPAPUD.bit.GPIO5       = 1;   // Enable pulldown on GPIO2   PWM-3B 
    GpioCtrlRegs.GPAMUX1.bit.GPIO5      = 0;   // GPIO5 = GPIO5                     
    GpioCtrlRegs.GPADIR.bit.GPIO5       = 1;   // GPIO4 = output                    
    EDIS;                                                                           
    GpioDataRegs.GPACLEAR.bit.GPIO5     = 0;   // SET INPUT TO LOW                  
                                                                                    
}          

2.  Secondly, I want to set PWM1A to LOW and PWM1B to HIGH. Similary for PWM2A/3A  to LOW and PWM2B/3B to HIGH. Below is the code.

function:

 // PWM1A is set to ZERO and PWM1B is set to HIGH on GPIO Pin 0 and 1.                 
EALLOW;                                                                               
GpioCtrlRegs.GPAPUD.bit.GPIO0       = 1;   // Enable pulldown on GPIO1   PWM-1A       
GpioCtrlRegs.GPAMUX1.bit.GPIO0      = 0;   // GPIO0 = GPIO0                           
GpioCtrlRegs.GPADIR.bit.GPIO0       = 1;   // GPIO0 = output                          
EDIS;                                                                                 
GpioDataRegs.GPACLEAR.bit.GPIO0     = 0;   // SET INPUT TO LOW.                       
                                                                                      
EALLOW;                                                                               
GpioCtrlRegs.GPAPUD.bit.GPIO1       = 1;   // Enable pulldown on GPIO1   PWM-1B       
GpioCtrlRegs.GPAMUX1.bit.GPIO1      = 0;   // GPIO1 = GPIO1                           
GpioCtrlRegs.GPADIR.bit.GPIO1       = 1;   // GPIO1 = output                          
EDIS;                                                                                 
GpioDataRegs.GPASET.bit.GPIO1       = 1;   // SET INPUT TO HIGH.                      
                                                                                      
// PWM2A is set to ZERO and PWM2B to HIGH in GPIO Pin 2 and 3                         
EALLOW;                                                                               
GpioCtrlRegs.GPAPUD.bit.GPIO2       = 1;   // Enable pulldown on GPIO2   PWM-2A       
GpioCtrlRegs.GPAMUX1.bit.GPIO2      = 0;   // GPIO2 = GPIO2                           
GpioCtrlRegs.GPADIR.bit.GPIO2       = 1;   // GPIO2 = output                          
EDIS;                                                                                 
GpioDataRegs.GPACLEAR.bit.GPIO2     = 0;   // SET INPUT TO LOW                        
                                                                                      
                                                                                      
EALLOW;                                                                               
GpioCtrlRegs.GPAPUD.bit.GPIO3       = 1;   // Enable pulldown on GPIO3   PWM-2B       
GpioCtrlRegs.GPAMUX1.bit.GPIO3      = 0;   // GPIO3 = GPIO3                           
GpioCtrlRegs.GPADIR.bit.GPIO3       = 1;   // GPIO3 = output                          
EDIS;                                                                                 
GpioDataRegs.GPASET.bit.GPIO3       = 0;   // SET INPUT TO HIGH                       
                                                                                      
// PWM3A is set to ZERO and PWM3B is set to HIGH in GPIO Pin 4 and 5                  
EALLOW;                                                                               
GpioCtrlRegs.GPAPUD.bit.GPIO4       = 1;   // Enable pulldown on GPIO4   PWM-3A       
GpioCtrlRegs.GPAMUX1.bit.GPIO4      = 0;   // GPIO4 = GPIO4                           
GpioCtrlRegs.GPADIR.bit.GPIO4       = 1;   // GPIO4 = output                          
EDIS;                                                                                 
GpioDataRegs.GPACLEAR.bit.GPIO4     = 0;   // SET INPUT TO LOW                        
                                                                                      
EALLOW;                                                                               
GpioCtrlRegs.GPAPUD.bit.GPIO5       = 1;   // Enable pulldown on GPIO5   PWM-3B       
GpioCtrlRegs.GPAMUX1.bit.GPIO5      = 0;   // GPIO5 = GPIO5                           
GpioCtrlRegs.GPADIR.bit.GPIO5       = 1;   // GPIO5 = output                          
EDIS;                                                                                 
GpioDataRegs.GPASET.bit.GPIO5       = 0;   // SET INPUT TO HIGH                       
                                                                                      

Regards,

Kuldeep                                                                         

  • Kuldeep,

    The main issue that I see with your code is that:
    GpioCtrlRegs.GPACLEAR.bit.GPIO0 = 0;  
    does nothing to the GPIO.  If instead you do:
    GpioCtrlRegs.GPACLEAR.bit.GPIO0 = 1;
    GPIO0 will become low.

    In general, to change the output of a GPIO, you only need the GPxCLEAR, GPxSET, or GPxDAT instruction.  The GPIO control registers only need to be edited during initialization (or whenever you want the basic functionality of a pin to change (ie GPIOoutput to PWM output) )


    Thank you,
    Brett