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.

Analog comparator TM4c123gh6pm

Genius 3300 points

1. While configuring for analog comparator pin how to configure analog pin. I have used Pinmux utility to generate code. It generated code "GPIOPinConfigure(GPIO_PC7_C0-);" , byt code gives error that GPIO_PC7_C0- is not defined.

2. Page 1217, showed comp+ input pin has three pins: +ve input,+ve input (alternate),reference input. 

What is +ve input (alternate)  here. is it same as +ve input?

3. While using comparator, is it necessary to put to it output also? I dont want to consume external pin, just want to generate interrupt.

4. Below is my code, is below sequence is correct for configuring it.

void comp0_isr(void)
{
/* clear comparator int */    
    ComparatorIntClear(COMP_BASE , 0U);
    
/* toggle led */    
    RED_LED_INVERT();
    
}    




void configure_uart(void) 
{             
    uint32_t ready_count;
    
/* enable comp0 */    
    SysCtlPeripheralDisable(SYSCTL_PERIPH_COMP0);
    SysCtlPeripheralReset(SYSCTL_PERIPH_COMP0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0);
    
    ready_count = 2000U;
    while( (!(SysCtlPeripheralReady(SYSCTL_PERIPH_COMP0)))  &&  (--ready_count));
    if(0U == ready_count)   /* if periph not ready take action */
    {
    }
    
/* configure pins co-  */    
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOC);    
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    
    ready_count = 2000U;
    while( (!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOC)))  &&  (--ready_count));
    if(0U == ready_count)   /* if periph not ready take action */
    {
    }    
//    GPIOPinConfigure(GPIO_PC7_C0-);
    GPIOPinTypeComparator(GPIO_PORTC_AHB_BASE, GPIO_PIN_7);

/* disable comparator int  */    
    ComparatorIntDisable(COMP_BASE , 0U);
    ComparatorIntClear(COMP_BASE , 0U);
    
/* set ref & configure comparator */    
    ComparatorRefSet(COMP_BASE , COMP_REF_2_371875V);
    ComparatorConfigure(COMP_BASE , 0U , COMP_TRIG_NONE | COMP_INT_RISE | COMP_ASRCP_REF | COMP_OUTPUT_NORMAL);
    
/* wait for 10us delay as mentioned in datasheet after configuring comprator */    
    wait_delay_us(10U);
    
/* register & enable interrupt */    
    ComparatorIntRegister(COMP_BASE , 0U , comp0_isr);
    ComparatorIntEnable(COMP_BASE , 0U);
    
    while(1);      
    
} 

  • Hello VT

    1.If you are using TM4C Pin Mux then it will generate a faulty code. The TM4C Pin Mux has been replaced by TI Pin Mux tool which generates the correct code. The link for the tool in the "Diagnosing..." forum post.

    2. Alternate input and +ve inputs are selectable

    3. It is not required to have the output pin.

    Regards
    Amit
  • 1. What is the difference +ve input & +ve input (alternate)?
    2. Is sequence to configure comparator is ok as in above code? I have checked code & its working
  • In response to your item (1) - you may select either pin marked as, "+ve" to serve as the analog comparator's + input. Your set-up code achieves that selection.

    There IS a significant weakness in your desire to "not consume" that comparator output pin. In so doing - you are subject to "chatter" as the input signal approaches & moves thru the "trip point."   Classically - when the output pin is exposed (i.e. consumed) simple resistive feedback produces "hysteresis" which reduces and/or eliminates that output (or interrupt) "chatter."   (this is independent of your delay - we suggest that you "consume" the pin to avoid grief downstream!)

  • Hello VT,

    If the sequence is working as expected, then what is that you want to check in the code?

    Regards
    Amit