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.

Code for QEP interfacing with F2812 DSP

Hi I want to measure speed and position of Induction motor using QEP encoder but unable to get output at T2CMP of GP Timer2. Looking for DSP F2812 code for both main as well as Encoder.

With regards,

  • For the future generations:

    //###########################################################################
    //
    // FILE:    Example_281xEvTimerPeriod.c (MODIFIED)
    //
    //
    //###########################################################################
    // $TI Release: DSP281x C/C++ Header Files V1.20 $
    // $Release Date: July 27, 2009 $
    //###########################################################################
     
     
    #include "DSP281x_Device.h"     // DSP281x Headerfile Include File
    #include "DSP281x_Examples.h"   // DSP281x Examples Include File
     
     
    void main(void)
    {
     
     
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP281x_SysCtrl.c file.
       InitSysCtrl();
     
    // Step 2. Initalize GPIO:
    // This example function is found in the DSP281x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    // InitGpio();  // Skipped for this example 
     
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
       DINT;
     
    // Initialize PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared. 
    // This function is found in the DSP281x_PieCtrl.c file.
       InitPieCtrl();
      
    // Disable CPU interrupts and clear all CPU interrupt flags:
       IER = 0x0000;
       IFR = 0x0000;
     
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR). 
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in DSP281x_DefaultIsr.c.
    // This function is found in DSP281x_PieVect.c.
       InitPieVectTable();
     
       // set up the GPIO poins
          EALLOW;
          GpioMuxRegs.GPAMUX.bit.CAP1Q1_GPIOA8      = 1;
          GpioMuxRegs.GPAMUX.bit.CAP2Q2_GPIOA9      = 1;
          GpioMuxRegs.GPAMUX.bit.CAP3QI1_GPIOA10    = 1;
          EDIS;
     
          // configure Timer
          EvaRegs.T2PR                        = 32; // assume small encoder
     
          EvaRegs.T2CON.bit.FREE        = 1; // Stop after current timer period is complete on emulation suspend
          EvaRegs.T2CON.bit.SOFT        = 0; // ^
          EvaRegs.T2CON.bit.TMODE       = 3; // Directional-Up/-Down Count Mode
          EvaRegs.T2CON.bit.TPS         = 0; // Input clock prescaler x1
          EvaRegs.T2CON.bit.T2SWT1      = 0; // Use own TENABLE bit
          EvaRegs.T2CON.bit.TENABLE     = 1; // Enable timer operations
          EvaRegs.T2CON.bit.TCLKS10     = 3; // Clock source: QEP circuit
          EvaRegs.T2CON.bit.TCLD10      = 0; // Timer compare register reload condition When counter is 0
          EvaRegs.T2CON.bit.TECMPR      = 0; // Disable timer compare operation
          EvaRegs.T2CON.bit.SET1PR      = 0; // Use own period register
     
       EvaRegs.EXTCONA.bit.QEPIE = 1; // 1 Enables CAP3_QPII as index input. Either a zero-to-one transition on
                                                           // CAP3_QEPI1 alone (when EXTCONA[1] = 0), or a zero-to-one transition
                                                           // plus CAP1_QEP1 and CAP2_QEP2 are both high (when
                                                           // EXTCON[1] = 1), causes the timer configured as QEP counter to reset
                                                           // to zero.
     
     
        // Enable global Interrupts and higher priority real-time debug events:
        EINT;   // Enable Global interrupt INTM
        ERTM;   // Enable Global realtime interrupt DBGM
     
        // Step 6. IDLE loop. Just sit and loop forever:
        // Observe EvaRegs.T2CNT
        for(;;);
     
    }
     
    //===========================================================================
    // No more.
    //===========================================================================