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.

Tiva Analog Comparator does not change status

Other Parts Discussed in Thread: TM4C123GH6PM

I cannot cause the status of the Analog Comparator to change the status with varying input voltage.

COMP_ACSTAT0_R always returns 0x0020

Gone through this 3 times without success , need help from you folks


Tiva launch pad TM4C123G

CCS 5.3 

// ***************************************************************************
//  PF1 = RED led
//  PF2 = BLUE led
//  PF3 = GREEN led
//  PF0 = SW2
//  PF4 = SW1
//  PC6 = Comparator 0 input
//
//              PC6
//               |
//               V
//    3.3V----\/\/\/\-----gnd
//
// ****************************************************************************

#include <stdint.h>
#include "tm4c123gh6pm.h"

#define SYSDIV 2
#define LSB 0
#define red 0x0002
#define blue 0x0004
#define green 0x0008
volatile uint32_t ui32Loop;  //
//*****************************************************************************
//
//
//*****************************************************************************
int
main(void)
{
//*********************************************************************
//  init Clock
//*********************************************************************
    SYSCTL_RCC2_R |= SYSCTL_RCC2_USERCC2;
    SYSCTL_RCC2_R |= SYSCTL_RCC2_BYPASS2;
    SYSCTL_RCC_R &= ~SYSCTL_RCC_XTAL_M;        // clear XTAL field
    SYSCTL_RCC_R += SYSCTL_RCC_XTAL_16MHZ;     // configure for 16 MHz crystal
    SYSCTL_RCC2_R &= ~SYSCTL_RCC2_OSCSRC2_M;   // clear oscillator source field
    SYSCTL_RCC2_R += SYSCTL_RCC2_OSCSRC2_MO;   // configure for main oscillator source
    SYSCTL_RCC2_R &= ~SYSCTL_RCC2_PWRDN2;
    SYSCTL_RCC2_R |= SYSCTL_RCC2_DIV400;
    SYSCTL_RCC2_R &= ~SYSCTL_RCC2_SYSDIV2_M;   // clear system clock divider field
    SYSCTL_RCC2_R &= ~SYSCTL_RCC2_SYSDIV2LSB;  // clear bit SYSDIV2LSB

    SYSCTL_RCC2_R += (SYSDIV<<23)|(LSB<<22);   // divide by (2*SYSDIV+1+LSB)

    while((SYSCTL_RIS_R&SYSCTL_RIS_PLLLRIS)==0){};

    SYSCTL_RCC2_R &= ~SYSCTL_RCC2_BYPASS2;
// ********************************************************************************
//  enable device clocks
// ********************************************************************************
    SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R4 + SYSCTL_RCGCGPIO_R5;// enable GPIO E & F

// Do a dummy read to insert a few cycles after enabling the peripheral.
    ui32Loop = SYSCTL_RCGC2_R;

// *************************************************************************
// Enable the GPIO pin for the LED (PF3).  Set the direction as output, and
// enable the GPIO pin for digital function.
// *************************************************************************
    GPIO_PORTF_DIR_R = 0x0E;
    GPIO_PORTF_DEN_R = 0x0E;
    ui32Loop = SYSCTL_RCGC2_R;
    GPIO_PORTF_DATA_R &= ~(0x0E);

// *************************************************************************
// configure Comparator
//    C0+ 14 PC6 I Analog Analog comparator 0 positive input.
// *************************************************************************
    SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R2; // enable GPIO Clock C
    SYSCTL_RCGCACMP_R = SYSCTL_RCGCACMP_R0; // enable comparator clock
    GPIO_PORTC_AFSEL_R |= GPIO_6;  // assign PC6 as analog
    GPIO_PORTC_AMSEL_R = 0x00;  // *set to analog
    COMP_ACREFCTL_R |= COMP_ACREFCTL_EN + COMP_ACREFCTL_RNG + 0x00000007; // internal voltage reference to 1.65 V
    COMP_ACCTL0_R |= COMP_ACCTL0_ASRCP_REF + COMP_ACCTL0_ISEN_M;  // use the internal voltage reference


    GPIO_PORTF_DATA_R &= ~(red);  //  reset, turn off LEDS
    GPIO_PORTF_DATA_R &= ~(green);
    GPIO_PORTF_DATA_R &= ~(blue);


    while(1)  // loop forever
            {
                if (COMP_ACSTAT0_R == 0x00000000 ) // test if set
                {
                       GPIO_PORTF_DATA_R |= green; //1 VIN- < VIN+ current output value
//  COMP_ACSTAT_R  value remains   0x0020 even though I change the input voltage.
//  what am I missing ???????
                }
                else
                {
                    GPIO_PORTF_DATA_R &= ~(green);
                }

              }
}
// *****************************************************************
//                          end of Main
// *****************************************************************