Other Parts Discussed in Thread: MSP430F2370
Hi there,
I am trying to use tm41294NCPDT Internal analogue Comparator
I am trying to implement Low Power NFC/RFID Card detection Algorithm
what it does i charge the RC circuit which then discharges and through NFC antenna i read the voltage as soon as it goes down below threshold which in my case i am using 1.65 V (TEST CASE) comparator should generate interrupt
i want to generate following output from Comparator0 using C0+ pin
1:- but the problem is that it triggers interrupt at rising as well as falling edge moreover sometimes it generates interrupt once as soon as the interrupts are configured
2:- I was watching the registers during debugging in IAR and i noticed that instead of comparator 0 register comparator 1 registers are also updating(COMPACSTAT1) but i haven't configured comparator 1
3:- But my main priority is to generate the out put first as shown in figure then trigger an interrupt when comparator output goes back to 1 means interrupt on rising edge
Code is attached below :
Thanks
#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" #include <string.h> #include "driverlib/uart.h" #include "utils/uartstdio.h" #include "driverlib/rom.h" #include "inc/hw_ints.h" #include "driverlib/rom_map.h" uint32_t g_ui32SysClock=120000000; #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) { } #endif int x=0; int status=0; bool int_status=0; bool int_status1=0; int32_t Comp_out = 0; void COMP_BASE_Interrupt(void) { int Comp_out; Comp_out = ComparatorValueGet(COMP_BASE, 0); // ComparatorIntClear(COMP_BASE,0); // // bool ulStatus; // ulStatus =ComparatorIntStatus(COMP_BASE, 0, true); ComparatorIntClear(COMP_BASE, 0); // ComparatorIntDisable(COMP_BASE,0); x++; // if (status==0) // { // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x1); // status=1; // } // // // if (status==1) // { // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0); // status=0; // } } int main(void) { g_ui32SysClock= SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); int counter=20; SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); while ((!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF))&&(counter==0)) { counter--; } GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4 ); IntMasterDisable(); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); //enable port C for negative input int counter1=20; while ((!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOC))&&(counter1==0)) { counter1--; } SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //enable port D For Output int counter2=20; while ((!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD))&&(counter2==0)) { counter2--; } GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_6 ); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 ); // GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,1); // SysCtlDelay(100); // GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,0); SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0); // enable comparator 1 int counter3=20; while ((!SysCtlPeripheralReady(SYSCTL_PERIPH_COMP0))&&(counter3==0)) { counter3--; } // assign pin type //GPIOPinTypeComparator(GPIO_PORTC_BASE, GPIO_PIN_7); //Analog comparator 1 negative input. GPIOPinTypeComparator(GPIO_PORTC_BASE, GPIO_PIN_6); //Analog comparator 1 positive input. //GPIOPinTypeComparator(GPIO_PORTD_BASE, GPIO_PIN_0); //Analog comparator 1 output. //GPIOPinConfigure(GPIO_PIN_4); // pin configure //GPIOPinConfigure(GPIO_PIN_5); //No Need because default function is analogue in GPIOPinConfigure(GPIO_PD0_C0O); ComparatorConfigure(COMP_BASE, 0, COMP_TRIG_NONE|COMP_ASRCP_REF |COMP_INT_FALL | COMP_OUTPUT_NORMAL); // comparator configure SysCtlDelay(100); // set internal reference voltage ComparatorRefSet(COMP_BASE, COMP_REF_1_65V ); //IntDisable(COMP_BASE); ComparatorIntRegister(COMP_BASE,0, COMP_BASE_Interrupt); ComparatorIntEnable(COMP_BASE,0); //ComparatorIntRegister(COMP_BASE, INT_COMP0); //IntEnable(INT_COMP0); IntMasterEnable(); //SysCtlDelay(g_ui32SysClock / 96); // delay ; while(1) { Comp_out = ComparatorValueGet(COMP_BASE, 0); // read comparator output // // int_status=ComparatorIntStatus(COMP_BASE, 0,true); // // if (Comp_out==0) // { // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0x0); // status=1; // SysCtlDelay(1000000); // } // // // if (Comp_out==1) // { // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0x1); // status=0; // SysCtlDelay(1000000); // } GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0x1); SysCtlDelay(1000); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0x0); SysCtlDelay(1000); } }