CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC24EP512 - Interrupt-on-change [Solved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
benoitstjean



Joined: 30 Oct 2007
Posts: 546
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PIC24EP512 - Interrupt-on-change [Solved]
PostPosted: Sun Jan 28, 2024 4:07 pm     Reply with quote

Device: PIC24EP512GP806
Compiler: 5.026

Hi guys,

Quick question: I'm going through the docs and its been a little while but on my device (see above), I'm trying to find in the docs which pins are allowed to be configured as an INT_CNI. So far I have RE5, RG6, RG7, RG8, RB5 and RB4 set as INT_CNI and only RG6 and RG8 trigger.

Thanks,

Ben


Last edited by benoitstjean on Mon Feb 05, 2024 12:55 pm; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19231

View user's profile Send private message

PostPosted: Mon Jan 29, 2024 12:12 am     Reply with quote

Every input pin can be set to give an interrupt on change.
Post how you are setting this up, and trying to use this.
I also note you have a very old compiler. I'll have to check and see
if yours works correctly for this.
Ttelmah



Joined: 11 Mar 2010
Posts: 19231

View user's profile Send private message

PostPosted: Mon Jan 29, 2024 4:33 am     Reply with quote

OK.
I did a quick test program, that works, then tried to compile it with 5.026.
Glaring problem. Your compiler does not have the set_analog_pins function.
Now on a lot of the later chips there are separate registers (as distinct from
the ADC setup registers), to configure pins for analog or digital I/O. The
set_analog_pins function controls the bits in these. The setup_adc_ports
function does turn these off, so are you using this?.
This functions, compiled with your compiler works.
Code:

#include <maincni.h>

//select pins to use
#DEFINE CHANGE0 PIN_E5
#DEFINE CHANGE1 PIN_G6
#DEFINE CHANGE2 PIN_G7
#DEFINE CHANGE3 PIN_G8
#DEFINE CHANGE4 PIN_B5
#DEFINE CHANGE5 PIN_B4

int1 PINstate[6], OLDstate[6];

//Now since variable I/O is very inefficient, using macros instead
#define CAT(a) CHANGE##a
#define TEST_PIN(num) PINstate[num]=input(cat(num)); //test if pin changed
#define CLEAR_PIN(num) OLDstate[num]=PINstate[num]; //reset change
#define SETUP(num) set_pullup(TRUE, cat(num)); \
   PINstate[num]=input(cat(num)); \
   enable_interrupts(INTR_CN_PIN | cat(num));  //setup interrupt on a pin

#INT_CNI
void change_interrupt(void)
{
   //Now we need to read each pin for change
   TEST_PIN(0)
   {
       CLEAR_PIN(0);
      //Code for this pin here
   } 
   TEST_PIN(1)
   {
       CLEAR_PIN(1);
      //Code for this pin here
   }
   TEST_PIN(2)
   {
       CLEAR_PIN(2);       
      //Code for this pin here
   }   
   TEST_PIN(3)
   {
       CLEAR_PIN(3);       
      //Code for this pin here
   }   
   TEST_PIN(4)
   {
       CLEAR_PIN(4);       
      //Code for this pin here
   }   
   TEST_PIN(5)
   {
       CLEAR_PIN(5);       
      //Code for this pin here
   }     
}

void main()
{
   //First need to ensure analog features are disabled.
   setup_adc_ports(NO_ANALOGS); //ensure ANSEL is set off
   //Now on boot need to read the current states, and then enable
   SETUP(0);
   SETUP(1);
   SETUP(2);
   SETUP(3);
   SETUP(4);
   SETUP(5);   
   //Now the global interrupt
   enable_interrupts(GLOBAL);
   
   while(TRUE)
   {
      //Whatever you want.
      delay_us(10);
   }
}
benoitstjean



Joined: 30 Oct 2007
Posts: 546
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Jan 29, 2024 8:29 am     Reply with quote

Thanks for the details info.

I guess I didn't hit "submit" yesterday but I finally got it to work after enabling the set_pullup() for each pin.

And yes, I know for sure that my compiler is old but it does what I need it to do and I'm used to it. I have to check what the new version does... when I have a moment.

Thanks for all your help!

Ben
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group