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.

CCS/TMS320F28027: TOGGLING

Part Number: TMS320F28027


Tool/software: Code Composer Studio

HEY EVERYONE , 

I am a newbie to this ti world , i have just starte programming it , my first program was to just a control a led using a switch (gpio 12) for which i wrote the follwing programme but the the the thing is the only else part is working not the if part can anyone please help me with this .. 

/*
PROJECT NAME : PWM_MODULE
VERSION : 1.0.0
AUTHOR : RAHUL GOEL
FILE NAME : MAIN.C
DESCRIPTION : GENERATE PWM SIGNAL WITH VARIABLE DUTY CYCLES
GPIO0 - ePWM1A
GPIO2 - ePWM2A
GPIO4 - ePWM3A
*/

#include "DSP28x_Project.h"

#define EPWM1_TIMER_TBPRD 1500

void GPIO_SELECT(void);
void EPWM1_Example1(void);
void Gpio_Toggle(void);
void delay_loop(void);

int main(void)
{
int a;

InitSysCtrl();

GPIO_SELECT();

for(;;)
{

a = GpioCtrlRegs.GPADIR.bit.GPIO12;

if(a == 1)
{
EPWM1_Example1();


}
else
Gpio_Toggle();

}

}

void GPIO_SELECT(void)
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO0 =1;
GpioCtrlRegs.GPAPUD.bit.GPIO1 =1;
GpioCtrlRegs.GPAPUD.bit.GPIO3 =1;


GpioCtrlRegs.GPAMUX1.bit.GPIO0=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO1=1;

GpioCtrlRegs.GPAMUX1.bit.GPIO2=0;
GpioCtrlRegs.GPAMUX1.bit.GPIO12=0;

GpioCtrlRegs.GPADIR.bit.GPIO2=1;
GpioCtrlRegs.GPADIR.bit.GPIO12=0;

EDIS;
}


void EPWM1_Example1(void)
{
EPwm1Regs.TBPRD= EPWM1_TIMER_TBPRD ;
EPwm1Regs.TBPHS.half.TBPHS= 0;
EPwm1Regs.TBCTR= 0x0000;

EPwm1Regs.CMPA.half.CMPA = 1500;
EPwm1Regs.CMPB=0;

EPwm1Regs.TBCTL.bit.CTRMODE = 0x2;
EPwm1Regs.TBCTL.bit.PHSEN=0x0;
EPwm1Regs.TBCTL.bit.SYNCOSEL=0x1;

EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0x0;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = 0x0;
EPwm1Regs.CMPCTL.bit.LOADAMODE = 0x0;
EPwm1Regs.CMPCTL.bit.LOADBMODE = 0x0;

EPwm1Regs.AQCTLA.bit.CAU = 0x2;
EPwm1Regs.AQCTLA.bit.CAD = 0x1;

EPwm1Regs.AQCTLB.bit.CBU = 0x2;
EPwm1Regs.AQCTLB.bit.CBD = 0x1;
};

void Gpio_Toggle()
{
GpioDataRegs.GPASET.bit.GPIO2=1;
delay_loop();
GpioDataRegs.GPACLEAR.bit.GPIO2=1;
delay_loop();
};

void delay_loop(void)
{
long int i;
for(i=0;i<100000;i++)
{

Thanks in advance.

  • You are setting the GPIO12 direction bit to 0, in this line:
    GpioCtrlRegs.GPADIR.bit.GPIO12=0;

    ...then testing the same bit, here:
    a = GpioCtrlRegs.GPADIR.bit.GPIO12;

    The variable 'a' will always be 0 because that's how you've set the direction bit, so your 'if' condition always evaluates false. Possibly you wanted to read the logic level on GPIO12, in which case you should have:

    a = GpioDataRegs.GPADAT.bit.GPIO12;

    Regards,

    Richard

  • On a different note, if you insert a code snippet in your post, always paste it using the “Syntax Highlighter” option. That makes the code easier to read.