Hi all,
I am trying to configure analog comparator 1 on tiva launchpad. Neither I am able to read the output of comparator not I am seeing any output on pin PF1, which is output of comparator 1 on launch pad. I have set internal reference voltage to 1.65 V. and I am giving input on pin PC4.
Below is my code:
#include "inc/tm4c123gh6pm.h"
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/adc.h"
#include "driverlib/interrupt.h"
#include "driverlib/comp.h"
#ifdef DEBUG
void__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
int32_t Comp_out = 0 ;
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // enable port C
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // '' '' F
SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP1); // enable comparator 1
GPIOPinTypeComparator(GPIO_PORTC_BASE, GPIO_PIN_5); // assign pin type
GPIOPinTypeComparator(GPIO_PORTC_BASE, GPIO_PIN_4);
GPIOPinTypeComparator(GPIO_PORTF_BASE, GPIO_PIN_1);
GPIOPinConfigure(GPIO_PC4_WT0CCP0); // pin configure
GPIOPinConfigure(GPIO_PC5_WT0CCP1);
GPIOPinConfigure(GPIO_PF1_C1O);
ComparatorConfigure(COMP_BASE, 1, COMP_TRIG_NONE|COMP_ASRCP_REF|COMP_INT_HIGH| COMP_OUTPUT_NORMAL); // comparator configure
ComparatorRefSet(COMP_BASE, COMP_REF_1_65V); // set internal reference voltage
SysCtlDelay(SysCtlClockGet() / 96); // delay
while(1)
{
SysCtlDelay(2000);
Comp_out = ComparatorValueGet(COMP_BASE, 1); // read comparator output
SysCtlDelay(2000);
}
}
Please let me know what is missing in the code. and what do I need to get output on pin PF1.
Regards,
Ishan