dsPIC33F interrupt on pin change

Discussion in 'Embedded Systems and Microcontrollers' started by tom66, Jul 12, 2010.

  1. tom66

    Thread Starter Senior Member

    May 9, 2009
    2,613
    213
    I am trying to get interrupt on change working on my dsPIC33F. Specifically a dsPIC33FJ128GP802.

    I want an interrupt on change event to fire when RB6 or RB7 change.

    Here is my code, for MPLAB C30:

    Code ( (Unknown Language)):
    1.  
    2. void setup_IOC_sync_pins()
    3. {
    4.     SET_CPU_IPL(0);
    5.     TRISBbits.TRISB6 = 1;
    6.     TRISBbits.TRISB7 = 1;
    7.     IFS1bits.CNIF = 0;
    8.     IPC4bits.CNIP = 7;        // high priority interrupt
    9.     IEC1bits.CNIE = 1;
    10.     CNEN2bits.CN22IE = 1;
    11.     CNEN2bits.CN23IE = 1;
    12. }
    13.  
    14. void disable_IOC_sync_pins()
    15. {
    16.     //IEC1bits.CNIE = 0;
    17.     CNEN2bits.CN22IE = 0;
    18.     CNEN2bits.CN23IE = 0;
    19. }
    20.  
    21. void _ISR _CNInterrupt()
    22. {
    23.     disable_IOC_sync_pins();
    24.     // 4 heartbeat pulses
    25.     heartbeat();
    26.     setup_IOC_sync_pins();
    27. }
    28.  
    29. void setup()
    30. {
    31.     PLLFBD = 38;                  // M=40
    32.     CLKDIVbits.PLLPOST = 0;        // N1=2
    33.     CLKDIVbits.PLLPRE = 0;        // N2=2
    34.     setup_IOC_sync_pins();
    35.     TRISBbits.TRISB5 = 1;
    36.     TRISBbits.TRISB6 = 1;
    37.     TRISBbits.TRISB7 = 1;
    38.     TRISBbits.TRISB8 = 1;
    39. }
    40.  
    41. int main()
    42. {
    43.     setup();
    44.     heartbeat();
    45.     heartbeat();
    46.     heartbeat();
    47.     heartbeat();
    48.     heartbeat();
    49.     heartbeat();
    50.     heartbeat();
    51.     heartbeat();
    52.     char l = 0;
    53.     while(1)
    54.     {
    55.     //    char b = PORTBbits.RB6;
    56.     //    if(b != l)
    57.     //        heartbeat_short();
    58.     //    l = b;
    59.     }    
    60.     return 0;
    61. }
    62.  
    I know the pin works because when the code in main is uncommented I get an output on RB15, which has a lot of jitter but shows me the pin input works.

    Any help appreciated!! Thanks.
     
    Last edited: Jul 12, 2010
  2. tom66

    Thread Starter Senior Member

    May 9, 2009
    2,613
    213
    Arrghhhhhhh... I'm so stupid! I had it plugged into the wrong pin. That's three days of my life wasted...

    To anyone that wonders, it works now...
     
Loading...