Search code examples
microcontrollerinterruptpicmicrochipdspic

dsPic33E : How to Implement Input Change Notification on Digital Input Pin?


As the question says, I want to implement ICN (Input Change Notification) for a digital Input Pin.

I am using dsPic33EP512GM604.

I have configured Pin<22> RB1 as an Input Pin.

An IR sensor is connected to the same Pin. I am looking out for a way (other than polling) to get Interrupt whenever Sensor detects an Object (Sends High Signal).

While going through the device Datasheet, I found a feature Input Change Notification (ICN) available.

It says :

"The Input Change Notification function of the I/O ports allows devices to generate interrupt requests to the processor in response to a Change-of-State (COS) on selected input pins. This feature can detect input Change-of-States (COS), even in Sleep mode when the clocks are disabled. Every I/O port pin can be selected (enabled) for generating an interrupt request on a Change-of-State."

I tried to search for more info regarding its implementation, But could not found any info.

Can anyone guide me the way to implement it or share me the link explaining its implementation or related info???


Solution

  • You need the general dspic33e manual (the one with a chapter in a separate file per peripheral).

    Try something like

     CNENBbits.CNIEB1 = 1; // Enable RB1 pin for interrupt detection
     _CNIP=7;       // priority (7 = highest)
     _CNIE = 1; // Enable CN interrupts
     _CNIF = 0; // clear interrupt flag
    

    and define your _CN interrupt routine roughly like this:

    void __attribute__((__interrupt__, no_auto_psv)) _CNInterrupt(void)
    {
         _CNIF = 0; 
    }  
    

    If you enable CN for multiple pins, you have to poll the pins in the interrupt to determine which one activated it.