interrupt on change notification

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

interrupt on change notification

#1 Post by jpc » 16 Sep 2006 12:03

I am trying to get an interrupt on change and somehow do not succeed
This is my testprogram , i am using here 30F3012 chip on Easydspic2 .
What is missing / wrong as it never interrupt's

Code: Select all

Program Cnint1;
// Input Change Notification Interrupt

Procedure Cn_interrupt; Org $32;
Var Dum : Word;
Begin
  latd := 1;      // should turn LED on at first interrupt occurring
  Dum := PORTb;
  //IFS0.15 := 0; // Clear Flag

End;

Procedure Init;
Var Dum : Word;
Begin
  TRISB := $ffff; // All Inputs
  PORTD := $0;
  TRISD := 0;
  TRISC := 0;
  CNEN1 := %0000000000000100;  // Allow Interrrupts On  Cn2 Input which is RB0 also

  IPC3.14 := 1;  //
  IPC3.13 := 1;  // Give High Priority
  IPC3.12 := 1;  //

  IFS0.15 := 0;  // Clear Cn-interrupt Flag
  IEC0.15 := 1;  // Allow Cn-interrupts

End;

Begin
delay_ms(100);
  Init;
  While True Do
  Begin
    Delay_ms(300);
    PORTc.15 := PORTc.15 Xor 1;  // flashing LED to have some sign of life
  End;
End.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: interrupt on change notification

#2 Post by zristic » 16 Sep 2006 13:08

You should try to turn off ADC on PORTB. I did not check the datasheet, but as far as I remember you should set the ADPCFG register, to 0xFFFF I think.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#3 Post by jpc » 16 Sep 2006 16:21

Right you are , i overlooked something in the datasheet :
Note: In order to use PORTB pins for digital I/O, the corresponding bits in the ADPCFG
register must be set to ‘1’, even if the A/D module is turned off.
now it starts working the way i wanted , Thanks Zoran!

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

#4 Post by zristic » 16 Sep 2006 16:41

jpc wrote:Thanks Zoran!
Anytime.

steve42lawson
Posts: 183
Joined: 06 Mar 2008 17:35
Location: St. George, UT
Contact:

...and for all you Mikro-C users...

#5 Post by steve42lawson » 11 Sep 2008 17:45

I was having the same problem with a PIC24FJ32GA002. I had set the appropriate CNEN1bits, but what I overlooked was the need to set the CNIE bit:

Code: Select all

IEC1bits.CNIE = 1;
Or, if you're into bit fiddling:

Code: Select all

IEC1 = IEC1 | 0x0008;
Also, make sure the interrupt priorities are correctly set (IPC4bits.CNIP0-2). The CN interrupt priority needs to be higher (larger number) than the CPU priority. The CPU priority is set to zero on reset, so unless you changed that, you should be good to go "out of the box" (so to speak :wink: )

BTW: I'm not sure about this, but if you have more than one interrupt going and if any of them have the same priority level as the CN interrupt, then the state of the INTCON1bits.NSTDIS bit may be important.

Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 General”