This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

LPCOMP won't fire interrupt

Hi,

I wrote a very simple program which compare the analog reference input 0 (P0.00) with AIN0 (P0.26) and generate an interrupt on cross using Low Power comparator on nRF51822.

I watched the signals on the both P0.00 and P0.26, the P0.00 is stable at 1.6v and P0.26 is a sinusoidal wave form with average voltage of 1.6v and pick voltage of 1.7, i believe i have correct situation for getting cross interrupt and i assume in this case there is no problem with the hardware setup.

the program that i wrote is in the below

#include "boards.h"
#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"


void LPCOMP_init(void)
{	
	/* Enable interrupt on LPCOMP CROSS event */		
	NRF_LPCOMP->INTENSET = LPCOMP_INTENSET_CROSS_Msk;
	NVIC_EnableIRQ(LPCOMP_IRQn);	
	
	/* Configure LPCOMP -  P0.00*/
	NRF_LPCOMP->REFSEL = (LPCOMP_REFSEL_REFSEL_ARef << LPCOMP_REFSEL_REFSEL_Pos);
	NRF_LPCOMP->EXTREFSEL = (LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference0 << LPCOMP_EXTREFSEL_EXTREFSEL_Pos);
	
	/* Configure LPCOMP - set reference input source to AIN pin 0, i.e. P0.26 */
	NRF_LPCOMP->PSEL = (LPCOMP_PSEL_PSEL_AnalogInput0 << LPCOMP_PSEL_PSEL_Pos);
	
	/* Enable and start the low power comparator */
	NRF_LPCOMP->POWER =  LPCOMP_POWER_POWER_Enabled;
	NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Enabled;	
	NRF_LPCOMP->TASKS_START = 1;
	
}

/* Interrupt handler for LPCOMP */
void LPCOMP_IRQHandler(void)
{
	// Clear event
	NRF_LPCOMP->EVENTS_CROSS = 0;
	
	// Sample the LPCOMP stores its state in the RESULT register. 
	// RESULT==0 means lower than reference voltage, 
	// RESULT==1 means higher than reference voltage
	NRF_LPCOMP->TASKS_SAMPLE = 1;
	
	// Toggle pin to indicate triggering of event
	
}



int main(void)
{


nrf_gpio_cfg_input(0,NRF_GPIO_PIN_NOPULL);
		nrf_gpio_cfg_input(26,NRF_GPIO_PIN_NOPULL);

		LPCOMP_init();
		
		while(true)
		{
		
						//Put CPU to sleep while waiting for interrupt to save power
						//__WFI();
		}

}

I place a breakpoint in the interrupt handler but it never go into the interrupt function.

Please give me some suggestions.

Related