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 CCS Technical Support

PIC18F46K20 and INT_EXT1_L2H / INT_EXT1_H2L

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



Joined: 29 Jun 2007
Posts: 62
Location: Raleigh, NC

View user's profile Send private message Visit poster's website

PIC18F46K20 and INT_EXT1_L2H / INT_EXT1_H2L
PostPosted: Fri Dec 21, 2012 12:40 pm     Reply with quote

I'm writing code for a PIC18F46K20.

The datasheet indicates that I have hardware interrupt pins for INT0, INT1, and INT2. To set the edge polarity of these interrupts, there are INTEDGx bits in the INTCON2 register. These and several other interrupts are all handled through one interrupt vector at address 0x0008.

When I look at the list of interrupt constants in the CCS PIC18F46K20.h file, there are 3 for each hardware interrupt. For example, for INT_EXT1, there are:
INT_EXT1
INT_EXT1_L2H
INT_EXT1_H2L

Also listed are the constants for use with ext_int_edge():
L_TO_H
H_TO_L

Can someone explain to me what the INT_EXT1_L2H and INT_EXT1_H2L constants are for? Has CCS added a few lines of code to their interrupt handler to check the setting of the edge bit? In my opinion, this seems like an excessive level of abstraction -- it's easy to write a statement for this when required. Of course, I can simply use INT_EXT1, I guess.

Thank you for your help,
Jim
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 2:00 pm     Reply with quote

comment...
It boils down to flexabilty....some 'circuitry' might like to be clocked on the up going (low-to high) edge of a signal, others on the downgoing.
Some don't care , some want BOTH edges(btdt)!
uchip has the silicon designed for it, CCS has cut code for it.
Sure you 'could' cut your own code ,but these days, it's rare to see a true 'low level bit manipulator'....
today's chips have tons of onboard 'options' and I lay odds 90% of the stuff is never used.
soundscu



Joined: 29 Jun 2007
Posts: 62
Location: Raleigh, NC

View user's profile Send private message Visit poster's website

PostPosted: Fri Dec 21, 2012 2:40 pm     Reply with quote

I need to respond to interrupts very fast (as close to realtime as possible) for both polarities. It's likely that I will bypass CCS's interrupt handling entirely, and write the whole thing in ASM.

But today I'm experimenting with what I can achieve using CCS functions. When I try using INT_EXT1_L2H and INT_EXT1_H2L as I would use any interrupt name, I get a compiler error. The plain old INT_EXT1 works as expected (where I have to handle polarity myself).

As far as I can tell, constants _L2H and _H2L don't do anything. Or are they intended for some other purpose?

Thank you,
Jim
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 2:50 pm     Reply with quote

Compile a test program and look at the .LST file. You will see that the
newer method simply combines two source code statements into one.
The generated ASM code is the same for either method:
Code:

.................... enable_interrupts(INT_EXT1); 
0002A:  BSF    INTCON3.INT1IE
.................... ext_int_edge(1, L_TO_H ); 
0002C:  BSF    INTCON2.INTEDG1
.................... 
.................... enable_interrupts(INT_EXT1_L2H);
0002E:  BSF    INTCON3.INT1IE
00030:  BSF    INTCON2.INTEDG1
.................... 
.................... //-----------------------------------
.................... enable_interrupts(INT_EXT1); 
00032:  BSF    INTCON3.INT1IE
.................... ext_int_edge(1, H_TO_L ); 
00034:  BCF    INTCON2.INTEDG1
.................... 
.................... enable_interrupts(INT_EXT1_H2L); 
00036:  BSF    INTCON3.INT1IE
00038:  BCF    INTCON2.INTEDG1

Test program:
Code:

#include <18F46K20.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)

//======================================
void main(void)
{
enable_interrupts(INT_EXT1);
ext_int_edge(1, L_TO_H );

enable_interrupts(INT_EXT1_L2H);

//-----------------------------------
enable_interrupts(INT_EXT1);
ext_int_edge(1, H_TO_L );

enable_interrupts(INT_EXT1_H2L);

while(1);
}
 
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 4:12 pm     Reply with quote

Some comments:
1) If it doesn't work for you, probably compiler version. CCS have a habit of introducing things, then taking a few versions to actually get these to work. It does work on the current compilers.
2) It has partially been done for compatibility, with some of the newer chips actually supporting separate handlers for both edges.
3) It is documented in the readme.txt that comes with the compiler. Quote:

"Interrupts have been defined in the device header file to also define
the edge on interrupts that allow it. This saves a separate call to set_int_edge().
For example:
enable_interrupts( INT_EXT_H2L );"

Best Wishes
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