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.

TMS320F28027 Comparator

Other Parts Discussed in Thread: TMS320F28027

Hi,

   I want to use the comparator modules in TMS320F28027 microcontroller. I want to take few actions based on the comparator output. How do I initialize it ( is it same as ADC initialization)? How do I get the comparator output? Will there be any interrupt like ADC for comparator, once the output is high? Please clarify. If any of you having the working C/C++ instruction set for comparator module, Please share.

Regards,

Mahesh K.R. 

  • Hi Mahesh,

    I would like you to refer this comparator doc:

    5808.ADC and Comparator.pdf

    Regards,

    Gautam

  • Hi Gautam,

    I referred the "spruge5f.pdf", Since I am writing all the codes in C/C++, I don't know, how do I initialize the comparator  registers bit wise. There I struck. Is it possible to mix and use C/C++ and register initialization bit by bit. Please let me know.

    Regards,

    Mahesh K.R.

  • Hi Mahesh,

    You can surely configure comparator registers bit wise using C in  CCS. By using the auto-complete feature you access comparator registers and initialize them.

    Regards,

    Gautam

  • Hi Gautam,

      Can you please explain more about " auto-complete feature"? How do I access? Where do I get it? etc.

    Regards,

    Mahesh K.R.

  • Mahesh, here are the two files that would help you configure your comparator in an easier way:

    Using Autocomplete feature:

    // TI File $Revision: /main/3 $
    // Checkin $Date: September 22, 2009   10:53:23 $
    //###########################################################################
    //
    // FILE:    DSP2802x_Comp.c
    //
    // TITLE:   DSP2802x Comparator Initialization & Support Functions.
    //
    //###########################################################################
    // $TI Release: f2802x Support Library v210 $
    // $Release Date: Mon Sep 17 09:13:31 CDT 2012 $
    //###########################################################################
    
    #include "F2802x_Device.h"     // Headerfile Include File
    #include "f2802x_common/include/F2802x_Examples.h"   // Examples Include File
    
    //---------------------------------------------------------------------------
    // InitComp:
    //---------------------------------------------------------------------------
    // This function initializes the Comp to a known state.
    //
    void InitComp(void)
    {
        // Initialize Comp:
    
        //tbd...
    }
    
    //---------------------------------------------------------------------------
    // Example: InitCompGpio:
    //---------------------------------------------------------------------------
    // This function initializes GPIO pins to function as Comp pins
    //
    // Each GPIO pin can be configured as a GPIO pin or up to 3 different
    // peripheral functional pins. By default all pins come up as GPIO
    // inputs after reset.
    //
    // Caution:
    // Only one GPIO pin should be enabled for CMP1OUT operation.
    // Only one GPIO pin shoudl be enabled for CMP2OUT operation.
    // Comment out other unwanted lines.
    
    void InitCompGpio()
    {
        InitComp1Gpio();
        #if DSP28_COMP2
            InitComp2Gpio();
        #endif
    
    }
    
    void InitComp1Gpio()
    {
    
       EALLOW;
    
    /* Disable internal pull-up for the selected output pins
       to reduce power consumption */
    // Pull-ups can be enabled or disabled disabled by the user.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;    // Disable pull-up for GPIO1 (CMP1OUT)
    
    /* Configure Comp pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be Comp functional pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 3;   // Configure GPIO1 for CMP1OUT operation
    
        GpioCtrlRegs.AIOMUX1.bit.AIO2 = 2;    // Configure AIO2 for CMP1A (analog input) operation
        GpioCtrlRegs.AIOMUX1.bit.AIO10 = 2;   // Configure AIO10 for CMP1B (analog input) operation
    
        EDIS;
    }
    
    #if DSP28_COMP2
    void InitComp2Gpio()
    {
    
       EALLOW;
    
    /* Disable internal pull-up for the selected output pins
       to reduce power consumption */
    // Pull-ups can be enabled or disabled disabled by the user.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1;    // Disable pull-up for GPIO3 (CMP2OUT)
    //  GpioCtrlRegs.GPBPUD.bit.GPIO34 = 1;   // Disable pull-up for GPIO34 (CMP2OUT)
    
    /* Configure Comp pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be Comp functional pins.
    // Comment out other unwanted lines.
    
        GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 3;   // Configure GPIO3 for CMP2OUT operation
    //  GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 1;  // Configure GPIO34 for CMP2OUT operation
    
        GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2;    // Configure AIO4 for CMP2A (analog input) operation
        GpioCtrlRegs.AIOMUX1.bit.AIO12 = 2;   // Configure AIO12 for CMP2B (analog input) operation
    
        EDIS;
    }
    
    #endif //end DSP28_COMP2
    
    //===========================================================================
    // End of file.
    //===========================================================================
    

    Without AC feature:

    //#############################################################################
    //
    //! \file   f2802x_common/source/comp.c
    //!
    //! \brief  Contains the various functions related to the comparator 
    //!         (COMP) object
    //
    //  Group:          C2000
    //  Target Device:  TMS320F2802x
    //
    //  (C) Copyright 2012, Texas Instruments, Inc.
    //#############################################################################
    // $TI Release: f2802x Support Library v210 $
    // $Release Date: Mon Sep 17 09:13:31 CDT 2012 $
    //#############################################################################
    
    // **************************************************************************
    // the includes
    #include "DSP28x_Project.h"
    #include "f2802x_common/include/comp.h"
    
    
    // assembly file
    extern void usDelay(unsigned long Count);
    
    
    // **************************************************************************
    // the defines
    
    
    // **************************************************************************
    // the globals
    
    
    // **************************************************************************
    // the functions
    
    
    void COMP_disable(COMP_Handle compHandle)
    {
        COMP_Obj *comp = (COMP_Obj *)compHandle;
    
        ENABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        // clear the bits
        comp->COMPCTL &= ~COMP_COMPCTL_COMPDACE_BITS;
    
        DISABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        return;
    } // end of COMP_disable() function
    
    
    void COMP_disableDac(COMP_Handle compHandle)
    {
        COMP_Obj *comp = (COMP_Obj *)compHandle;
    
        ENABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        // set the bits
        comp->COMPCTL |= COMP_COMPCTL_COMPSOURCE_BITS;
    
        DISABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        return;
    } // end of COMP_disableDac() function
    
    
    void COMP_enable(COMP_Handle compHandle)
    {
        COMP_Obj *comp = (COMP_Obj *)compHandle;
    
        ENABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        // set the bits
        comp->COMPCTL |= COMP_COMPCTL_COMPDACE_BITS;
    
        DISABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        return;
    } // end of COMP_enable() function
    
    
    void COMP_enableDac(COMP_Handle compHandle)
    {
        COMP_Obj *comp = (COMP_Obj *)compHandle;
    
        ENABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        // set the bits
        comp->COMPCTL &= ~COMP_COMPCTL_COMPSOURCE_BITS;
    
        DISABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        return;
    } // end of COMP_enableDac() function
    
    
    COMP_Handle COMP_init(void *pMemory, const size_t numBytes)
    {
        COMP_Handle compHandle;
    
        if(numBytes < sizeof(COMP_Obj))
        return((COMP_Handle)NULL);
    
        // assign the handle
        compHandle = (COMP_Handle)pMemory;
    
        return(compHandle);
    } // end of COMP_init() function
    
    
    
    
    
    
    
    // end of file
    

    Regards,

    Gautam

  • Hi Gautam,

      Thanks for that. How do I get the comparator output value? I want to do an action based on the out put is high or low. Not controlling the PWM or sending to GPIO. I have to set a value. This will be used in my program. Please let me know.

    Regards,

    Mahesh K.R.

  • How do I get the comparator output value? I want to do an action based on the out put is high or low.

    Also, you can simply use 2 ADC channels for this purpose.

    Regards,

    Gautam

  • Hi Gautam,

                   one of my project require frequency measurement . i am using tms320f28027  i planed to use enhanced capture to measure frequency is this one is right way? and how to initialize and use the capture please give some ideas for me

    Regards

    Ramesh rahi