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.

CCS/TM4C1230H6PM: analog comparator 0

Part Number: TM4C1230H6PM
Other Parts Discussed in Thread: EK-TM4C123GXL

Tool/software: Code Composer Studio

Hi all,

could you pls have a short look at my analog comparator 0 configuration?

It does not work.

Short:

- int ref on input + (internal)

- analog value between 0...3,3V on negative input (PC7)

- comp output on PF0

and here is my code snippet:

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/comp.h"

void init ()
{
uint32_t g_ui32SysClock; // System clock rate in Hz.

SysCtlClockSet (SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

g_ui32SysClock = SysCtlClockGet ();

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); // Enable the GPIO ports
GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); // Enable the GPIO pins for the LEDs (PN0 & PN1)


IntMasterEnable(); // Enable processor interrupts

SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0); // Enable Comparator 0

while(!SysCtlPeripheralReady(SYSCTL_PERIPH_COMP0)) // Wait for the COMP module to be ready
{
}
ComparatorRefSet(COMP_BASE, COMP_REF_0_275V); // Configure the internal voltage reference

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // Enable Port C
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable Port F

GPIOPinConfigure(GPIO_PF0_C0O);
//GPIOPinConfigure(GPIO_PC7_C0-);

GPIOPinTypeComparator(GPIO_PORTC_BASE, GPIO_PIN_7); // Comparator Input
GPIOPinTypeComparatorOutput(GPIO_PORTF_BASE, GPIO_PIN_0); // Comparator Output
ComparatorConfigure(COMP_BASE, 0, (COMP_TRIG_NONE | COMP_INT_BOTH | COMP_ASRCP_REF | COMP_OUTPUT_NORMAL)); // Configure comparator 0

ComparatorValueGet(COMP_BASE, 0);

}

  • I can look at it when I get back in the office on Monday. I have an example that works for the TM4C129, but of course the pins are different. It might help.
    ... // // Enable the COMP module. // SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0); // // Wait for the COMP module to be ready. // while(!SysCtlPeripheralReady(SYSCTL_PERIPH_COMP0)) { } // // Configure the internal voltage reference. // ComparatorRefSet(COMP_BASE, COMP_REF_1_65V); // // Configure comparator 2. // ComparatorConfigure(COMP_BASE, 2, (COMP_TRIG_NONE | COMP_ASRCP_REF | COMP_OUTPUT_NORMAL)); // // Enable and wait for the port to be ready for access // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // For C2o SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); // For C2- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)) { } // Configure the GPIO port for the LED operation. GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, (USER_LED1|USER_LED2)); // Configure the GPIO port for the comparator 2 output GPIOPinTypeComparatorOutput(GPIO_PORTD_BASE, GPIO_PIN_2); // PD2 is C2o GPIOPinConfigure(GPIO_PD2_C2O); GPIOPinTypeComparator(GPIO_PORTP_BASE, GPIO_PIN_1); // PP1 is C2- // // Loop Forever // while(1) { // Read the comparator output value. // if(ComparatorValueGet(COMP_BASE, 2) == true) { leds = USER_LED1|USER_LED2; // blink both if input is low } else { leds = USER_LED1; // blink one if input is high } // // Turn on the LED // GPIOPinWrite(GPIO_PORTN_BASE, (USER_LED1|USER_LED2), leds); // // Delay for a bit // SysCtlDelay(ui32SysClock/6); // // Turn off the LED // GPIOPinWrite(GPIO_PORTN_BASE, (USER_LED1|USER_LED2), 0); // // Delay for a bit // SysCtlDelay(ui32SysClock/6); } }

  • Here is some code that works on the EK-TM4C123GXL launchpad.

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/timer.h"
    #include "driverlib/comp.h"
    
    #define RED   GPIO_PIN_1
    #define BLUE  GPIO_PIN_2
    #define GREEN GPIO_PIN_3
    
    void main()
    {
        uint32_t g_ui32SysClock; // System clock rate in Hz.
    
        SysCtlClockSet (SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    
        g_ui32SysClock = SysCtlClockGet ();
    
    
    
        IntMasterEnable(); // Enable processor interrupts
    
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // Enable Port C
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable Port F
        SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0); // Enable Comparator 0
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_COMP0)) // Wait for the COMP module to be ready
        {
        }
    
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED | BLUE | GREEN); // Enable the GPIO pins for the LEDs (PF1-red, PF2-blue, PF3-green)
    
        ComparatorRefSet(COMP_BASE, COMP_REF_0_275V); // Configure the internal voltage reference
        GPIOPinConfigure(GPIO_PF0_C0O);
        GPIOPinTypeComparator(GPIO_PORTC_BASE, GPIO_PIN_7); // Comparator Input
        GPIOPinTypeComparatorOutput(GPIO_PORTF_BASE, GPIO_PIN_0); // Comparator Output
    
        ComparatorConfigure(COMP_BASE, 0, (COMP_TRIG_NONE | COMP_INT_BOTH | COMP_ASRCP_REF | COMP_OUTPUT_NORMAL)); // Configure comparator 0
    
        while(1)
        {
            if(ComparatorValueGet(COMP_BASE, 0) == true)
            {
                GPIOPinWrite(GPIO_PORTF_BASE,  RED | BLUE | GREEN, GREEN); // < 0.275V
            }
            else
            {
                GPIOPinWrite(GPIO_PORTF_BASE,  RED | BLUE | GREEN, RED); // > 0.275V
            }
    
        }
    }
    

  • Hi Bob,

    thanks for the reply.

    I was out for a business trip - will check immediately.

    best regards Gunter