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.

How to Call interrupt() function multiple times?

Other Parts Discussed in Thread: TMS320F2808

Hii,

Board: TMS320F2808

I am using eCAP module. when printing storage data of [CAPx] Register bit, that should be inside interrupt service routine (ISR) function. That's why calling interrupt() function from main() function multiple times.

Calling multiple time means, Measuring & Printing duty cycle of input signal continuously on Console window of CCS.

  • Hi Asim,

    Asim Kumar Dey said:
    That's why calling interrupt() function from main() function multiple times.

    What do you mean by above statement? ISR happens wrt its trigger & how do you plan to call it from main?

    Regards,

    Gautam

  • [[[ Kindly request to Gautam Layer, if you really help to me, then tell me why this code not Printed Measured value of Duty cycle?????
    Gautam you had not solved my last problem similar to this, that's why i am creating another new Post similar to older one..... /c2000/f/171/t/523108. Here if you are involving, you most solved this problem. This is Kind request to you. ]]]


    I have connected the output pulse of a Function Generator to GPIO24 of my F2808 experimental DSP kit to measure
    Duty cycle of output pulse.

    I initialize the ECap1 module with this code:

    #include "stdlib.h"
    #include "stdio.h"
    #include "DSP280x_Device.h"
    #include "DSP280x_Examples.h"

    __interrupt void ecap1_isr(void); // eCAP interrupt service routine (ISR)
    void init_ecap1(void); // initializing eCAP module
    void init_Sys(void); // initializing System Control, GPIO, Vector table, PIE control Register, Device peripheral


    void main(void)
    {
    init_Sys();

    for( i = 0 ; i < 10; i++ )
    {
    ecap1_isr(); // calling interrupt() function from main() function multiple times
    }
    }


    void init_Sys(void)
    {
    // Step 1. Initialize System Control:
    EALLOW;
    SysCtrlRegs.WDKEY = 0x0055;
    SysCtrlRegs.WDKEY = 0x00AA;
    SysCtrlRegs.PLLSTS.bit.MCLKSTS = 0; 
    SysCtrlRegs.PLLSTS.bit.MCLKOFF = 1; 
    SysCtrlRegs.PLLSTS.bit.PLLLOCKS = 0; 
    SysCtrlRegs.HISPCP.bit.HSPCLK = 0; // HSPCLK=SYSCLKOUT
    SysCtrlRegs.LOSPCP.bit.LSPCLK = 0; // LSPCLK=SYSCLKOUT

    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Enable clock for all Peripheral
    SysCtrlRegs.PCLKCR1.bit.ECAP1ENCLK = 1; // Enable clock for ECap1
    EDIS;

    // Step 2. Initialize eCAP1 GPIO:
    EALLOW;
    GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 1; // GPIO 24 = CAP1
    GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 0; // Synch to SYSCLKOUT GPIO 24
    GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; // Enable pull-up on GPIO 24
    EDIS;

    // Step 3. Clear all interrupts and initialize PIE vector table:
    EALLOW;
    PieVectTable.ECAP1_INT = &ecap1_isr; // initialize PIE Vector Table
    EDIS;

    // Step 4. Initialize all the Device Peripherals:

    init_ecap1();

    // Step 5. enable interrupts:
    PieCtrlRegs.PIEIER4.bit.INTx1 = 1;

    IER |= M_INT4;

    EINT;
    ERTM;
    }


    void init_ecap1()
    {
    ECap1Regs.ECEINT.all = 0x0000; // Disable all capture interrupts
    ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags
    ECap1Regs.ECCTL1.bit.CAPLDEN = 0; // Disable CAP1-CAP4 register loads
    ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped

    // Configure peripheral registers
    ECap1Regs.ECCTL2.bit.CAP_APWM = 0; // EC_CAP_MODE
    ECap1Regs.ECCTL2.bit.CONT_ONESHT = 1; // One-shot
    ECap1Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
    ECap1Regs.ECCTL1.bit.CAP1POL = 1; // Falling edge
    ECap1Regs.ECCTL1.bit.CAP2POL = 0;   // Rising edge
    ECap1Regs.ECCTL1.bit.CAP3POL = 1; // Falling edge
    ECap1Regs.ECCTL1.bit.CAP4POL = 0; // Rising edge
    ECap1Regs.ECCTL1.bit.CTRRST1 = 1; // Difference operation
    ECap1Regs.ECCTL1.bit.CTRRST2 = 1; // Difference operation
    ECap1Regs.ECCTL1.bit.CTRRST3 = 1; // Difference operation
    ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation
    ECap1Regs.ECCTL2.bit.SYNCI_EN = 1; // Enable sync in
    ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0; // Pass through
    ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable capture units

    ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter
    ECap1Regs.ECCTL2.bit.REARM = 1; // arm one-shot
    ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
    ECap1Regs.ECEINT.bit.CEVT1 = 1;
    ECap1Regs.ECEINT.bit.CEVT2 = 1;
    ECap1Regs.ECEINT.bit.CEVT3 = 1;
    ECap1Regs.ECEINT.bit.CEVT4 = 1; // 4 events = interrupt
    }

    __interrupt void ecap1_isr(void)
    {
    double cap1, cap2;

    cap1 = ECap1Regs.CAP1;
    cap2 = ECap1Regs.CAP2;

    printf("cap1= %lf \n", cap1);
    printf("cap2= %lf \n", cap2);

    ECap1Regs.ECCLR.bit.CEVT4 = 1;
    ECap1Regs.ECCLR.bit.INT = 1;
    ECap1Regs.ECCTL2.bit.REARM = 1;

    PieCtrlRegs.PIEACK.all = PIEACK_GROUP4; // Acknowledge this interrupt to receive more interrupts from group 4
    }

    And finally during the debug session, i am unable to print on console window the Measured value of Duty cycle pulse?

  • Asim Kumar Dey said:
    [[[ Kindly request to Gautam Layer, if you really help to me, then tell me why this code not Printed Measured value of Duty cycle?????
    Gautam you had not solved my last problem similar to this, that's why i am creating another new Post similar to older one..... /c2000/f/171/t/523108. Here if you are involving, you most solved this problem. This is Kind request to you. ]]]

    Lol :) I'll keep that in mind!

    Asim Kumar Dey said:
    And finally during the debug session, i am unable to print on console window the Measured value of Duty cycle pulse?

    Are you able to observe the cap counts atleast in cap1 and cap2? If yes & if you're having issue only with printf command you can check this wiki link:


    Regards,

    Gautam

  • --------------------------------------------------------------------------------------------------------------------------------------------------------

    Are you able to observe the cap counts atleast in cap1 and cap2?

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

    No.

    My point of view, i am facing problem in Writing the way of ISR interrupt & its execution. This may be the major problem in the above code.

    Another point is, way of writing printf command is right, i had checked it.

    Basically problem in the way of writing ISR interrupt & calling ISR interrupt???????

  • I did my project. Here is my final code to resolved all the above problem.

    Test_eCap_on_off_period.c
    // DESCRIPTION:
    // Input to eCAP GPIO pin is 30Khz pulse train signal
    // eCAP peripheral measures On-time, OFF-time, PERIOD & Frequency of Pulse train signal.
    
    
    
    #include "stdio.h"
    #include "stdlib.h"
    #include "DSP280x_Device.h"
    #include "DSP280x_Examples.h"
    
    // Prototype
    void init_system(void);
    void init_ecap1(void);
    __interrupt void ecap1_isr(void);
    
    
    void main(void)
    {
    	init_system();
    		
    	ecap1_isr();
    }
    
    
    void init_system(void)
    {
    //Step1: Initialize System Control Peripheral Clock:
     	    EALLOW;
    	    SysCtrlRegs.WDKEY = 0x0055;
    	    SysCtrlRegs.WDKEY = 0x00AA;
    	    SysCtrlRegs.PLLSTS.bit.MCLKSTS = 0;			// Normal condition (Device not in limp mode) (missing OSCCLK clock not been detected)
    //	    SysCtrlRegs.PLLSTS.bit.CLKINDIV = 0;		// CLKIN divide by 2 is enabled
    	    SysCtrlRegs.PLLSTS.bit.MCLKOFF = 1;			// Osicillator fail-detect logic is disabled (PLL not issue limp-mode clock)
    	    SysCtrlRegs.PLLSTS.bit.PLLLOCKS = 0;		// PLL is lock & CPU is clocked by OSCCLK/2
    	    SysCtrlRegs.HISPCP.bit.HSPCLK = 0;			// HSPCLK=SYSCLKOUT
    	    SysCtrlRegs.LOSPCP.bit.LSPCLK = 0;			// LSPCLK=SYSCLKOUT
    
    	    SysCtrlRegs.PCLKCR1.bit.ECAP1ENCLK = 1; 	// Enable clock for ECap1
    	    EDIS;
    //Step2: Initalize ECap GPIO Pins:
    	    EALLOW;
    	    GpioCtrlRegs.GPACTRL.bit.QUALPRD3 = 255;		// Specifing Sapling Period for pins GPIO24
    	    GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 0;		// Synch to SYSCLKOUT GPIO24
    	    GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 1;		// GPIO 24 = CAP1 [PIN 33]
    	    GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0;			// Enable pull-up on GPIO 24
    	    EDIS;
    
    //Step3: Clear all interrupts and initialize PIE vector table:
    		IER = 0x0000;		// Disable CPU interrupts
    		IFR = 0x0000;		// clear all CPU interrupt flags
    
    		EALLOW;
    		PieVectTable.ECAP1_INT = &ecap1_isr;	// initialize PIE Vector Table
    		EDIS;
    
    //Step4: Initialize all the Device Peripherals:
    		init_ecap1();
    
    
    //Step5: User specific code, enable interrupts:
    		// Initalize PIE Control Register:
    	    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;			// Enable PIE (peripheral interrupt expansion)
    	    PieCtrlRegs.PIEIER4.bit.INTx1 = 1;			// Enable Interrupt enable register
    
    	    IER |= M_INT4;					// enable CPU interrupt
    
    	    EINT;	// Enable Global interrupt INTM
    	    ERTM;	// Enable Global realtime interrupt DBGM
    }
    
    void init_ecap1(void)
    {
    // Capture Configuration:
    	   ECap1Regs.ECEINT.all = 0x0000;             // Disable all capture interrupts
    	   ECap1Regs.ECCLR.all = 0xFFFF;              // Clear all CAP interrupt flags
    	   ECap1Regs.ECCTL1.bit.CAPLDEN = 0;          // Disable CAP1-CAP4 register loads
    	   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;        // Make sure the counter is stopped
    
    	   ECap1Regs.ECCTL1.bit.CAP1POL = 0;		// Rising edge
    	   ECap1Regs.ECCTL1.bit.CAP2POL = 1;		// Falling edge
    	   ECap1Regs.ECCTL1.bit.CAP3POL = 0;		// Rising
    	   ECap1Regs.ECCTL1.bit.CAP4POL = 1;		// Falling
    	   ECap1Regs.ECCTL1.bit.CTRRST1 = 0;		// abs mode
    	   ECap1Regs.ECCTL1.bit.CTRRST2 = 0;		// abs ode
    	   ECap1Regs.ECCTL1.bit.CTRRST3 = 0;		// abs mode
    	   ECap1Regs.ECCTL1.bit.CTRRST4 = 0;		// abs ode
    
    	   ECap1Regs.ECCTL1.bit.CAPLDEN = 1;        // Enable capture units
    	   ECap1Regs.ECCTL1.bit.PRESCALE = 0;
    	   ECap1Regs.ECCTL2.bit.CAP_APWM = 0;		// EC_CAP_MODE
    	   ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0;	// EC_CONTINUOUS MODE
    //	   ECap1Regs.ECCTL2.bit.STOP_WRAP = 3;        // Stop at 4 events
    
    	   ECap1Regs.ECCTL2.bit.REARM = 1; 			// Re-Arm enable
    	   ECap1Regs.ECCTL2.bit.SYNCI_EN = 0;       // Disable sync-in
    	   ECap1Regs.ECCTL2.bit.SYNCO_SEL = 2;      // Disable Sync-out Signal
    	   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;		// TSCTR Running
    	   ECap1Regs.ECCTL1.bit.CAPLDEN = 1;        // Enable capture units
    	   ECap1Regs.ECCLR.bit.CEVT4 = 1;			// 4 events = interrupt
    
    //	   ECap1Regs.ECEINT.bit.CEVT4 = 1;
    }
    
    __interrupt void ecap1_isr(void)
    {
    	float	cap1, cap2, cap3, cap4, period, on, off;
    
    	cap1 = ECap1Regs.CAP1;
    	cap2 = ECap1Regs.CAP2;
    	cap3 = ECap1Regs.CAP3;
    	cap4 = ECap1Regs.CAP4;
    
    	period = cap3-cap1;
    	on = cap2-cap1;
    	off = cap3-cap2;
    
    	printf(" capture: period= %f on= %f off= %f \n", period, on, off);
    
    	ECap1Regs.ECCLR.bit.CEVT4 = 1;
    	ECap1Regs.ECCTL2.bit.REARM = 1;
    	ECap1Regs.ECCLR.bit.INT = 1;
    	ECap1Regs.ECCTL2.bit.REARM = 1;
    
    	// Acknowledge this interrupt to receive more interrupts from group 4
    	PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
    
    	return;
    }