Hi, I'm trying to implement a very simple Analog Comparator using the comp.h file in the drivers library.
Currently, my code only has the setup and configuration of the comparator and the turning on and off of an LED after that. However, when running the program gets stuck in the configuration part. Commenting out the ComparatorRefSet() and ComparatorConfigure() functions results in the blinking of the LED as normal.
Can someone help me with this problem? Thanks.
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/adc.h"
#include "driverlib/comp.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "utils/uartstdio.h"
//*****************************************************************************
//
// Define pin to LED color mapping.
//
//*****************************************************************************
#define BLUE_LED GPIO_PIN_2
#define GREEN_LED GPIO_PIN_3
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
int main(void)
{
//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPULazyStackingEnable();
//
// Set the clocking to run directly from the crystal, 16MHz.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// Enable the GPIO port that is used for the on-board LED.
// Enable the GPIO pins for the LEDs.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, BLUE_LED|GREEN_LED);
//
// Enable the GPIO port C that is used for Analog Comparator 1.
// Set GPIO7 (-ve input) as analog comparator input.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeComparator(GPIO_PORTC_BASE, GPIO_PIN_4);
//
// Enable Analog Comparator 1
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP1);
//
// Set internal voltage reference for comparator
//
ComparatorRefSet(COMP_BASE, COMP_REF_1_65V);
//
// Configure comparator
//
ComparatorConfigure(COMP_BASE, 1 , (COMP_TRIG_NONE | COMP_ASRCP_REF | COMP_OUTPUT_NONE));
//
// Delay for some time
//
SysCtlDelay(SysCtlClockGet() / 96);
//
// Turn on Blue LED
//
GPIOPinWrite(GPIO_PORTF_BASE, BLUE_LED|GREEN_LED, BLUE_LED);
SysCtlDelay(4000000);
//
// Turn off Blue LED
//
GPIOPinWrite(GPIO_PORTF_BASE, BLUE_LED|GREEN_LED, BLUE_LED & GREEN_LED);
//
// Loop forever while the timers run.
//
while(1)
{
}
}