Tool/software: Code Composer Studio
hello, I am writing the code for the analog comparator in which potentiometer is used as the external reference and in the handler of comparator I have to read the value of the comparator. please, anyone can help me to solve it out? my code is not going in the interrupt handler.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/gpio.h"
#include "inc/hw_comp.h"
#include "driverlib/comp.h"
#include "driverlib/interrupt.h"
#include "inc/hw_ints.h"
uint32_t comp_value;
void compinthandler(void)
{
comp_value= ComparatorValueGet(COMP_BASE,0);
ComparatorIntClear(COMP_BASE,0);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,GPIO_PIN_1);
SysCtlDelay(5000000);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0);
SysCtlDelay(5000000);
}
int main(void)
{
volatile uint32_t ui32Loop;
uint32_t ui32ADC0Value[4];
//set clock frequency.
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
//enable GPIO PORTF.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//enable ADC0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//enable comparator COMP0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3);
GPIOPinTypeComparator(GPIO_PORTC_BASE, GPIO_PIN_6);
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceEnable(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
ComparatorRefSet(COMP_BASE, COMP_REF_1_65V);
ComparatorConfigure(COMP_BASE, 0,(COMP_TRIG_NONE| COMP_INT_BOTH |COMP_ASRCP_REF| COMP_OUTPUT_NORMAL));
ComparatorIntEnable(COMP_BASE,0);
IntEnable(INT_COMP0);
IntMasterEnable();
while(1)
{
// comp_value= ComparatorValueGet(COMP_BASE,0);
//
// GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,GPIO_PIN_1);
// SysCtlDelay(5000000);
// GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0);
// SysCtlDelay(5000000);
}
}