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.

MSPM0L1303: Comparator appears to always be stuck in one state

Part Number: MSPM0L1303
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

I am trying to configure the comparator to trigger when the positive terminal goes higher than the negative terminal. I want this to generate an interrupt.

I have configured the comparator as follows (using SysConfig):

Operating Mode Fast mode
Enable Channel Inputs Positive
Enable Output False
Positive Terminal Channel Input COMPx_IN0+
Output Polarity Non-inverted
Hysteresis No hysteresis

Reference Source VDDA
Reference operating mode Static
Terminal Ref applied to negative
DAC Control SW-bit controls selection
DAC input DAC 0
DAC code various


I have also enabled the interrupt with level 0 priority.

The issue I am experiencing is the following:

  • If I select the DAC code as 0 the output of the COMP is LOW
  • If I select the DAC code as > 0 the output is always HIGH and I get constant IRQs. 
  • From what I can see the input voltage on the positive terminal has no effect on the output of the comparator.

I have tried various different DAC code values but the behavior is always the same. 

  • Hi Michael,
    Can you share your Sysconfig file? I want to replicate the problem on my side.

    Best Regards,

    Diego Abad

  • Hey, here is the sysconf file: 

    (I was unable to upload the file)

    /**
     * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
     * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
     * @cliArgs --device "MSPM0L130X" --part "Default" --package "VQFN-24(RGE)" --product "mspm0_sdk@1.30.00.03"
     * @v2CliArgs --device "MSPM0L1303" --package "VQFN-24(RGE)" --product "mspm0_sdk@1.30.00.03"
     * @versions {"tool":"1.23.0+4000"}
     */
    
    /**
     * Import the modules used in this configuration.
     */
    const ADC12         = scripting.addModule("/ti/driverlib/ADC12", {}, false);
    const ADC121        = ADC12.addInstance();
    const Board         = scripting.addModule("/ti/driverlib/Board");
    const COMP          = scripting.addModule("/ti/driverlib/COMP", {}, false);
    const COMP1         = COMP.addInstance();
    const GPIO          = scripting.addModule("/ti/driverlib/GPIO", {}, false);
    const GPIO1         = GPIO.addInstance();
    const OPA           = scripting.addModule("/ti/driverlib/OPA", {}, false);
    const OPA1          = OPA.addInstance();
    const OPA2          = OPA.addInstance();
    const PWM           = scripting.addModule("/ti/driverlib/PWM", {}, false);
    const PWM1          = PWM.addInstance();
    const PWM2          = PWM.addInstance();
    const PWM3          = PWM.addInstance();
    const PWM4          = PWM.addInstance();
    const SYSCTL        = scripting.addModule("/ti/driverlib/SYSCTL");
    const UART          = scripting.addModule("/ti/driverlib/UART", {}, false);
    const UART1         = UART.addInstance();
    const VREF          = scripting.addModule("/ti/driverlib/VREF");
    const ProjectConfig = scripting.addModule("/ti/project_config/ProjectConfig");
    
    /**
     * Write custom configuration values to the imported modules.
     */
    ADC121.powerDownMode              = "DL_ADC12_POWER_DOWN_MODE_MANUAL";
    ADC121.sampleTime0                = "125 us";
    ADC121.adcMem0_name               = "VBUS";
    ADC121.$name                      = "ADC";
    ADC121.adcMem1_name               = "Current";
    ADC121.samplingOperationMode      = "sequence";
    ADC121.adcMem1vref                = "VREF";
    ADC121.adcMem0vref                = "VREF";
    ADC121.adcMem2vref                = "VREF";
    ADC121.adcMem3chansel             = "DL_ADC12_INPUT_CHAN_11";
    ADC121.adcMem3vref                = "VREF";
    ADC121.adcMem0chansel             = "DL_ADC12_INPUT_CHAN_3";
    ADC121.adcMem2_name               = "ADC_PD_IN";
    ADC121.adcMem2chansel             = "DL_ADC12_INPUT_CHAN_13";
    ADC121.adcMem1chansel             = "DL_ADC12_INPUT_CHAN_12";
    ADC121.endAdd                     = 1;
    ADC121.enabledInterrupts          = ["DL_ADC12_INTERRUPT_MEM1_RESULT_LOADED","DL_ADC12_INTERRUPT_MEM2_RESULT_LOADED"];
    ADC121.peripheral.$assign         = "ADC0";
    ADC121.peripheral.adcPin3.$assign = "PA24/OPA0.IN0-";
    ADC121.adcPin3Config.$name        = "ti_driverlib_gpio_GPIOPinGeneric1";
    
    Board.unusedDirection             = "INPUT";
    Board.genPeriphPinFile            = true;
    Board.configureUnused             = true;
    Board.peripheral.$assign          = "DEBUGSS";
    Board.peripheral.swclkPin.$assign = "PA20";
    Board.peripheral.swdioPin.$assign = "PA19";
    Board.genFileMod.$name            = "ti_driverlib_BoardPins0";
    
    COMP1.negChannel                            = "DL_COMP_IMSEL_CHANNEL_1";
    COMP1.enabledInterrupts                     = ["DL_COMP_INTERRUPT_OUTPUT_EDGE"];
    COMP1.interruptPriority                     = "0";
    COMP1.vSource                               = "DL_COMP_REF_SOURCE_VDDA_DAC";
    COMP1.terminalSelect                        = "DL_COMP_REF_TERMINAL_SELECT_NEG";
    COMP1.controlSelect                         = "DL_COMP_DAC_CONTROL_SW";
    COMP1.$name                                 = "OCP_COMP";
    COMP1.setDACCode0                           = 0x10;
    COMP1.channelEnable                         = ["POS"];
    COMP1.compPinPos0Config.hideOutputInversion = scripting.forceWrite(false);
    COMP1.compPinPos0Config.$name               = "ti_driverlib_gpio_GPIOPinGeneric10";
    COMP1.peripheral.$assign                    = "COMP0";
    COMP1.peripheral.compPinPos0.$assign        = "PA26";
    
    GPIO1.$name                                       = "GPIO_GRP_0";
    GPIO1.associatedPins.create(3);
    GPIO1.associatedPins[0].$name                     = "CCCV";
    GPIO1.associatedPins[0].pin.$assignAllowConflicts = "PA21";
    GPIO1.associatedPins[1].$name                     = "OCP";
    GPIO1.associatedPins[1].subOutputPolicy           = "TOGGLE";
    GPIO1.associatedPins[1].pin.$assign               = "PA15";
    GPIO1.associatedPins[2].$name                     = "PA0";
    GPIO1.associatedPins[2].direction                 = "INPUT";
    
    OPA1.$name                        = "OPA_PD";
    OPA1.cfg0PSELChannel              = "IN0_POS";
    OPA1.cfg0NSELChannel              = "IN0_NEG";
    OPA1.cfg0OutputPin                = "ENABLED";
    OPA1.cfg0Chop                     = "STANDARD";
    OPA1.advRRI                       = true;
    OPA1.advBW                        = "HIGH";
    OPA1.In0PosPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric7";
    OPA1.In0PosPinConfig.enableConfig = true;
    OPA1.In0NegPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric8";
    OPA1.In0NegPinConfig.enableConfig = true;
    OPA1.peripheral.$assign           = "OPA1";
    OPA1.peripheral.In0PosPin.$assign = "PA18";
    OPA1.peripheral.In0NegPin.$assign = "PA17/OPA1.IN0-";
    OPA1.peripheral.OutPin.$assign    = "PA16";
    OPA1.OutPinConfig.$name           = "ti_driverlib_gpio_GPIOPinGeneric9";
    OPA1.OutPinConfig.enableConfig    = true;
    
    OPA2.$name                                   = "OPA_CC";
    OPA2.cfg0PSELChannel                         = "IN0_POS";
    OPA2.cfg0OutputPin                           = "ENABLED";
    OPA2.cfg0NSELChannel                         = "RTAP";
    OPA2.cfg0MSELChannel                         = "GND";
    OPA2.cfg0Gain                                = "N15_P16";
    OPA2.cfg0Chop                                = "STANDARD";
    OPA2.advRRI                                  = true;
    OPA2.advBW                                   = "HIGH";
    OPA2.In0PosPinConfig.$name                   = "ti_driverlib_gpio_GPIOPinGeneric4";
    OPA2.peripheral.$assign                      = "OPA0";
    OPA2.peripheral.In0PosPin.$assign            = "PA25";
    OPA2.peripheral.OutPin.$assignAllowConflicts = "PA22";
    OPA2.OutPinConfig.$name                      = "ti_driverlib_gpio_GPIOPinGeneric6";
    
    PWM1.$name                              = "SetPoint";
    PWM1.pwmMode                            = "EDGE_ALIGN_UP";
    PWM1.timerStartTimer                    = true;
    PWM1.timerCount                         = 6400;
    PWM1.ccIndex                            = [0];
    PWM1.interrupts                         = ["ZERO_EVENT"];
    PWM1.interruptPriority                  = "3";
    PWM1.PWM_CHANNEL_0.$name                = "ti_driverlib_pwm_PWMTimerCC0";
    PWM1.PWM_CHANNEL_0.dutyCycle            = 99;
    PWM1.ccp0PinConfig.direction            = scripting.forceWrite("OUTPUT");
    PWM1.ccp0PinConfig.hideOutputInversion  = scripting.forceWrite(false);
    PWM1.ccp0PinConfig.onlyInternalResistor = scripting.forceWrite(false);
    PWM1.ccp0PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
    PWM1.ccp0PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric0";
    
    PWM2.$name                              = "PWM_CH2";
    PWM2.pwmMode                            = "CENTER_ALIGN";
    PWM2.subscriberChannel                  = 1;
    PWM2.timerStartTimer                    = true;
    PWM2.crossTriggerEn                     = true;
    PWM2.clockPrescale                      = 2;
    PWM2.timerCount                         = 16000;
    PWM2.peripheral.$assign                 = "TIMG4";
    PWM2.peripheral.ccp0Pin.$assign         = "PA10";
    PWM2.peripheral.ccp1Pin.$assign         = "PA11";
    PWM2.PWM_CHANNEL_0.$name                = "ti_driverlib_pwm_PWMTimerCC1";
    PWM2.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC2";
    PWM2.PWM_CHANNEL_1.invert               = true;
    PWM2.PWM_CHANNEL_1.initVal              = "HIGH";
    PWM2.ccp0PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric3";
    PWM2.ccp0PinConfig.direction            = scripting.forceWrite("OUTPUT");
    PWM2.ccp0PinConfig.hideOutputInversion  = scripting.forceWrite(false);
    PWM2.ccp0PinConfig.onlyInternalResistor = scripting.forceWrite(false);
    PWM2.ccp0PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
    PWM2.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
    PWM2.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
    PWM2.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
    PWM2.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
    PWM2.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric5";
    
    PWM3.$name                              = "PWM_CH1";
    PWM3.pwmMode                            = "CENTER_ALIGN";
    PWM3.crossTriggerEn                     = true;
    PWM3.timerStartTimer                    = true;
    PWM3.clockPrescale                      = 2;
    PWM3.timerCount                         = 16000;
    PWM3.peripheral.ccp0Pin.$assign         = "PA3";
    PWM3.peripheral.ccp1Pin.$assign         = "PA4";
    PWM3.PWM_CHANNEL_0.$name                = "ti_driverlib_pwm_PWMTimerCC5";
    PWM3.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC6";
    PWM3.PWM_CHANNEL_1.invert               = true;
    PWM3.PWM_CHANNEL_1.initVal              = "HIGH";
    PWM3.ccp0PinConfig.direction            = scripting.forceWrite("OUTPUT");
    PWM3.ccp0PinConfig.hideOutputInversion  = scripting.forceWrite(false);
    PWM3.ccp0PinConfig.onlyInternalResistor = scripting.forceWrite(false);
    PWM3.ccp0PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
    PWM3.ccp0PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric12";
    PWM3.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
    PWM3.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
    PWM3.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
    PWM3.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
    PWM3.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric14";
    
    PWM4.timerCount                         = 2133;
    PWM4.ccIndex                            = [1];
    PWM4.$name                              = "PWM_Clamp";
    PWM4.timerStartTimer                    = true;
    PWM4.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
    PWM4.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
    PWM4.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
    PWM4.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
    PWM4.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric13";
    PWM4.peripheral.$assign                 = "TIMG1";
    PWM4.peripheral.ccp1Pin.$assign         = "PA1";
    PWM4.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC3";
    PWM4.PWM_CHANNEL_1.initVal              = "HIGH";
    
    SYSCTL.VDD         = 1.8;
    SYSCTL.clockTreeEn = true;
    
    UART1.$name              = "UART_0";
    UART1.direction          = "RX";
    UART1.txFifoThreshold    = "DL_UART_TX_FIFO_LEVEL_EMPTY";
    UART1.targetBaudRate     = 1200;
    UART1.enabledInterrupts  = ["RX"];
    UART1.parity             = "EVEN";
    UART1.analogGlitchFilter = "DL_UART_PULSE_WIDTH_10_NS";
    UART1.rxPinConfig.$name  = "ti_driverlib_gpio_GPIOPinGeneric2";
    UART1.peripheral.$assign = "UART0";
    
    VREF.checkVREFReady       = true;
    VREF.advClkSrc            = "DL_VREF_CLOCK_BUSCLK";
    VREF.advClockConfigEnable = true;
    
    ProjectConfig.deviceSpin    = "MSPM0L1303";
    ProjectConfig.genLibDrivers = true;
    scripting.suppress("Migrating requires going through the Switch Board or Device menu in the Device View section\\.", ProjectConfig, "deviceSpin");
    
    /**
     * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future
     * version of the tool will not impact the pinmux you originally saw.  These lines can be completely deleted in order to
     * re-solve from scratch.
     */
    GPIO1.associatedPins[2].pin.$suggestSolution = "PA2";
    PWM1.peripheral.$suggestSolution             = "TIMG0";
    PWM1.peripheral.ccp0Pin.$suggestSolution     = "PA23";
    PWM3.peripheral.$suggestSolution             = "TIMG2";
    UART1.peripheral.rxPin.$suggestSolution      = "PA9";
    VREF.peripheral.$suggestSolution             = "VREF";

  • Hi Michael,

    Thanks for sharing it. I'll start testing this out today, and I should have a response by Friday EOD.

    Best Regards,

    Diego Abad

  • Hi Michael,
    I tried your SYSCONFIG file, and used the example main code from the comp_hs_dac_vref_external example from the SDK. When I run it, whenever I apply a voltage of 3.3v to the pin, it turn an LED (PA0.) Otherwise, the interrupt doesn't happen. I'll share the main file I used. Let me know if this makes the issue go away.

    Best Regards,

    Diego Abad

    #include "ti_msp_dl_config.h"
    
    /*
     * DAC8 Reference Voltage in mV
     *  Adjust this value according to the external VREF voltage.
     */
    #define COMP_INST_REF_VOLTAGE_mV (3000)
    /*
     * DAC8 static output voltage in mV.
     *  Adjust output as needed.
     */
    #define COMP_INST_DAC8_OUTPUT_VOLTAGE_mV (1500)
    
    int main(void)
    {
        uint32_t dacValue;
    
        SYSCFG_DL_init();
    
        /*
         * Set output voltage:
         *  DAC value (8-bits) = DesiredOutputVoltage x 255
         *                          -----------------------
         *                              ReferenceVoltage
         */
        dacValue =
            (COMP_INST_DAC8_OUTPUT_VOLTAGE_mV * 255) / COMP_INST_REF_VOLTAGE_mV;
    
        DL_COMP_setDACCode0(COMP_INST, dacValue);
        DL_COMP_enable(COMP_INST);
    
        NVIC_EnableIRQ(COMP_INST_INT_IRQN);
    
        DL_SYSCTL_enableSleepOnExit();
    
        while (1) {
            __WFI();
        }
    }
    
    void GROUP1_IRQHandler(void)
    {
        switch (DL_COMP_getPendingInterrupt(COMP_INST)) {
            case DL_COMP_IIDX_OUTPUT_EDGE:
                DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
                break;
            case DL_COMP_IIDX_OUTPUT_EDGE_INV:
                DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
                break;
            default:
                break;
        }
    }