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.

TM4C129DNCPDT comparator setting problem



Hi all,

My device connect to comparator 2, there are some problem:

1.I can't get correct output value and C2o(PD2) didn't output signal

2.Set interrupt for comparator 2 always cause system crash, but set com 0 is ok

below is my code , please give me advise if there are anything I missed, thanks.

 

//
SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP2);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);


// Enable pin PP0 for COMP2 C2+
//
//MAP_GPIOPinConfigure(GPIO_PP0_C2+);
GPIOPinTypeComparator(GPIO_PORTP_BASE, GPIO_PIN_0);

// Enable pin PP1 for COMP2 C2-
//
// MAP_GPIOPinConfigure(GPIO_PP1_C2-);
GPIOPinTypeComparator(GPIO_PORTP_BASE, GPIO_PIN_1);
//
// Enable pin PD2 for COMP2 C2O
//
GPIOPinConfigure(GPIO_PD2_C2O);
GPIOPinTypeComparator(GPIO_PORTD_BASE, GPIO_PIN_2);

// Configure the internal voltage reference.
//
ComparatorRefSet(COMP_BASE, COMP_REF_1_65V);

ComparatorConfigure(COMP_BASE, 2,
(COMP_TRIG_NONE| COMP_INT_FALL|
COMP_ASRCP_REF| COMP_OUTPUT_NORMAL));

while(1)
{

UartOsPrintf("Comparator out=%d\n\r",ComparatorValueGet(COMP_BASE, 2));

}

// a loop to get value and change the C2+ C2- at the same time

  • Hello Light,

    1. The PD2 is a digital output which should not be using

    GPIOPinTypeComparator(GPIO_PORTD_BASE, GPIO_PIN_2);

    as that will configure it in Analog Mode. Instead

    GPIOPinConfigure(GPIO_PD2_C2O);
    GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_DIR_MODE_HW);
    GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);

    should be used

    2. Regarding the crash. Can you please elaborate where the crash is happening in the code?

    Regards

    Amit

  • Hi Amit,

    I called related functions

    ComparatorIntRegister or ComparatorIntEnable after ComparatorRefSet

    It's normal when setting comparator 0, but crash at setting comparator 2.

    Best Regards,

    Light

  • Hello Light,

    Is the issue resolved or is it still open (I see verified)

    Regards

    Amit

  • Hi Amit,

    C2o ouput issue is resolved.

    But I see C+>C- =>Low,C+<C-=>High,when setting COMP_OUTPUT_NORMAL.

    Is it correct?

    Best Regards,

    Light

  • Hello Light,

    Can you please attach the updated (do not paste) code?

    Regards

    Amit

  • Hi Amit,

    Please see the attach

    Best Regards,

    Light

    {
    	uint32_t ui32Value,capa;
    	uint32_t uiFactor = 10;
    
    	SysTickPeriodSet(80000/uiFactor); // 80000 ->1ms
    
    	// Delay for some time...
    	SystemTickWait(200*uiFactor);
    
    	//Initial comparator
        //
        // Enable Peripheral Clocks 
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP1);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP2);
    
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
    
    
        // Enable pin PP0 for COMP2 C2+
        //
        //MAP_GPIOPinConfigure(GPIO_PP0_C2+);
        GPIOPinTypeComparator(GPIO_PORTP_BASE, GPIO_PIN_0);
    
        // Enable pin PP1 for COMP2 C2-
        //
        // MAP_GPIOPinConfigure(GPIO_PP1_C2-);
        GPIOPinTypeComparator(GPIO_PORTP_BASE, GPIO_PIN_1);
        //
        // Enable pin PD2 for COMP2 C2O
        //
        GPIOPinConfigure(GPIO_PD2_C2O);
        //GPIOPinTypeComparator(GPIO_PORTD_BASE, GPIO_PIN_2);
        GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_DIR_MODE_HW);
    	GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
    
        //
        // Enable pin PM7 for GPIOInput
        //
        GPIOPinTypeGPIOInput(GPIO_PORTM_BASE, GPIO_PIN_7);
    	
    
    	UartOsPrintf("1\n\r");
    	// Configure the internal voltage reference.
    	//
    	ComparatorRefSet(COMP_BASE, COMP_REF_1_925V);
    	//
    	// Configure comparator 0.
    	//
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);
    	GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_6);
    	GPIOPinWrite( GPIO_PORTQ_BASE, GPIO_PIN_6, 0);
    
    	UartOsPrintf("2\n\r");
    
    	ComparatorConfigure(COMP_BASE, 2,
    	(COMP_TRIG_NONE| COMP_INT_BOTH|
    	COMP_ASRCP_PIN| COMP_OUTPUT_NORMAL));
    	//ComparatorIntEnable(COMP_BASE,2);
        //IntEnable(INT_COMP2);
        //IntMasterEnable();
    	//
    	// Delay for some time...
    	//
    	UartOsPrintf("3\n\r");
    	
    	SystemTickWait(2000*uiFactor);
    	
    	UartOsPrintf("Comparator out=%d\n\r",ComparatorValueGet(COMP_BASE, 2));
    		//PQ6_CHG_4V1_OFF
    	UartOsPrintf("Monitor Set C charge start  \n");
    	
    	GPIOPinWrite( GPIO_PORTQ_BASE, GPIO_PIN_6, GPIO_PIN_6);
    	ComStart = SystemTickGet();
    	UartOsPrintf("Comparator out=%d\n\r",ComparatorValueGet(COMP_BASE, 2));
    	
    	while(ComparatorValueGet(COMP_BASE, 2)==0)
    	{
    	//UartOsPrintf("w\n\r");
    	//ComStop= SystemTickGet();
    	}
    	ComStop= SystemTickGet();
    	UartOsPrintf("Comparator out=%d\n\r",ComparatorValueGet(COMP_BASE, 2));
    	UartOsPrintf("Monitor Set C charge stop  \n");
    	//
    	// Read the comparator output value.
    
    	ComValue=ComStop - ComStart;
    	UartOsPrintf("4 Com=%d\n\r",ComValue);
    	capa = (ComValue*10000)/15249;
    	UartOsPrintf("Capacity=%d.%d\n\r",(capa/100),(capa%100));
    	UartOsPrintf("Comparator out=%d\n\r",ComparatorValueGet(COMP_BASE, 2));
    	SystemTickWait(1000*uiFactor);
    	UartOsPrintf("Comparator out=%d\n\r",ComparatorValueGet(COMP_BASE, 2));
    	UartOsPrintf("5\n\r");
    	SysTickPeriodSet(80000);
    
    	
    #endif
    }

  • Hello Light,

    Let me check the same as well. In the meantime can you use the INV option so that you can continue using the setup.

    Regards

    Amit