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.

reference program for external interrupt in tms320f28335

Other Parts Discussed in Thread: CONTROLSUITE

Hi,

I want to do a simple program for counting external pulses using interrupt but i dont know which are the registers to initialize and in what sequence. so anybody who has worked on this is requested to give some information regarding this. It will be very helpful for me if i can get a reference program so that i can refer to it for my better understanding.

Hoping for early replies.

arun

  • Hi Arun,

    Did you download the latest controlSuite? It has all the reference sample codes and documentation.

    Let me know if you need any help.

    Regards,

    Gautam

  • Hi Gautam,

    thanks for your reply. yes i have already tried the program from control suite, but i am facing some problems.

    Is it possible to use any GPIO pin as an external interrupt other than pin no.1 or 2.? If yes then can you please tell me the syntax of doing this.

  • Hi,


    Why use interrupts to count pulses? You could miss them (overlapping pules).. You could use EQEP module to count for you! datasheet

    If you really like to use the GPIO interrupts than it's possible to configure a GPIO group to generate XINTn interrupts, but thats only possible as a group of IO pins. See page 101 and below in datahseet

    Otherwise you could use the NMI (non maskable interrupt).


    Tjarco

  • Hi Arun,

    s it possible to use any GPIO pin as an external interrupt other than pin no.1 or 2.?

    Offcourse, you can implement it using other GPIOs. Here's the syntax:

    // GPIO2 and GPIO3 are inputs
       EALLOW;
       GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;         // GPIO2
       GpioCtrlRegs.GPADIR.bit.GPIO2 = 0;          // input
       GpioCtrlRegs.GPAQSEL1.bit.GPIO2 = 0;        // Xint1 Synch to SYSCLKOUT only
    
       GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0;         // GPIO3
       GpioCtrlRegs.GPADIR.bit.GPIO3 = 0;          // input
       GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 2;        // XINT2 Qual using 6 samples
       GpioCtrlRegs.GPACTRL.bit.QUALPRD0 = 0xFF;   // Each sampling window is 510*SYSCLKOUT
       EDIS;
    
    // GPIO2 is XINT1, GPIO3 is XINT2
       EALLOW;
       GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 2;   // Xint1 is GPIO2
       GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = 3;   // XINT2 is GPIO3
       EDIS;
    
    // Configure XINT1 & XINT2
       XIntruptRegs.XINT1CR.bit.POLARITY = 0;      // Falling edge interrupt
       XIntruptRegs.XINT2CR.bit.POLARITY = 1;      // Rising edge interrupt

    Regards,

    Gautam

  • thanks gautam,

    i tried your program for making GPIO pin no.50 and 51 as interrupt but it is not working. Actually the kit which i am using has only GPIO 48 to 63 pins available for connection rest all are not accessible.

    Also i tried interrupt program from control suite but i am not able to understand it . Is there any other resource available?   

  • Hi,

    Thanks for your advice!

    I have tried to do it using EQEP module but i couldn't do it. If you can help me with a sample program it would be very helpful to me. I tried EQEP program from control suite for reference but it seems a bit difficult to understand. 

  • Maybe this could be something to try for you, I havent tried it but it's copied from existing EQEP configuration.

    <code>


    void  EQEP1_Init(void)
    {        EALLOW;

            if(SysCtrlRegs.PCLKCR1.bit.EQEP1ENCLK != 0) asm(" ESTOP1");    //ALREADY INITIALISED BY OTHER CODE IN THS PROJECT!

            SysCtrlRegs.PCLKCR1.bit.EQEP1ENCLK =1;
            asm(" NOP"); asm(" NOP");

            EQep1Regs.QDECCTL.all=00;        // Quad mode, Latch on position counter read by CPU.
            EQep1Regs.QEPCTL.bit.FREE_SOFT=2;    // free run
            EQep1Regs.QEPCTL.bit.PCRM=00;        // PCRM=00 mode
            EQep1Regs.QPOSMAX=0xffffffff;        // use full 32 bits as reference to measure up and down
            EQep1Regs.QPOSINIT = 0x7fffffff;            // Initial value 0x7fffffff
            EQep1Regs.QEPCTL.bit.QPEN=1;         // QEP enable
            EQep1Regs.QDECCTL.bit.SWAP = 0;        // swap A and B inputs.

            GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 1;    // GPIO20 is EQEP1A
                GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 1;    // GPIO21 is EQEP1B

            GpioCtrlRegs.GPAPUD.bit.GPIO20 = 0;    // pull-up enabled
            GpioCtrlRegs.GPAPUD.bit.GPIO21 = 0;    // pull-up enabled

            EQep1Regs.QEPCTL.bit.SWI = 1;        // Initialize position counter (QPOSCNT=QPOSINIT).
            EQep1Regs.QEPCTL.bit.SWI = 0;

            EDIS;
    }

    void  EQEP2_Init(void)
    {        EALLOW;

            if(SysCtrlRegs.PCLKCR1.bit.EQEP2ENCLK != 0) asm(" ESTOP1");    //ALREADY INITIALISED BY OTHER CODE IN THS PROJECT!

            SysCtrlRegs.PCLKCR1.bit.EQEP2ENCLK =1;
            asm(" NOP"); asm(" NOP");
            
            EQep2Regs.QDECCTL.all=00;        // Quad mode, Latch on position counter read by CPU.
            EQep2Regs.QEPCTL.bit.FREE_SOFT=2;    // free run
            EQep2Regs.QEPCTL.bit.PCRM=00;        // PCRM=00 mode
            EQep2Regs.QPOSMAX=0xffffffff;        // use full 32 bits as reference to measure up and down
            EQep2Regs.QPOSINIT = 0x7fffffff;            // Initial value 0x7fffffff
            EQep2Regs.QEPCTL.bit.QPEN=1;         // QEP enable
            EQep2Regs.QDECCTL.bit.SWAP = 0;        // swap A and B inputs.

            GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 2;    // GPIO20 is EQEP1A
                GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 2;    // GPIO21 is EQEP1B

            GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0;    // pull-up enabled
            GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0;    // pull-up enabled

            EQep2Regs.QEPCTL.bit.SWI = 1;        // Initialize position counter (QPOSCNT=QPOSINIT).
            EQep2Regs.QEPCTL.bit.SWI = 0;
            EDIS;
    }

    void main(void){

    /*Some system inits here*/

    EQEP1_Init();

    EQEP2_Init();


     do{
        =EQep1Regs.QPOSCNT; // counter value
        EQep1Regs.QEPCTL.bit.SWI = 1; //Initialize position counter (QPOSCNT=QPOSINIT).

        =EQep2Regs.QPOSCNT; // counter value
        EQep2Regs.QEPCTL.bit.SWI = 1; //Initialize position counter (QPOSCNT=QPOSINIT).

        udelay(5000);

     }while(1);


    }//end main

    </code>