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);
}