View previous topic :: View next topic |
Author |
Message |
PrinceNai
Joined: 31 Oct 2016 Posts: 527 Location: Montenegro
|
INT_EXT on 18f46k22 |
Posted: Wed Feb 05, 2025 6:06 am |
|
|
Hi all,
I have an oddity with external interrupt on 18f46k22. I have the following code:
Code: |
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8); // 65.535us, resolution 1us
ext_int_edge(H_TO_L);
ext_int_edge(L_TO_H);
ext_int_edge(1,H_TO_L);
ext_int_edge(1,L_TO_H);
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
clear_interrupt(INT_EXT1);
enable_interrupts(INT_EXT1);
|
I needed to change the active edge for external interrupt, which ext_int_edge should do. But it didn't work as expected, so I checked the .lst file and added the code for ext1. It seems that the function ext_int_edge(H_TO_L); sets the bit in a wrong register, FE9,6 (FSR0L) instead of FF1,6. EXT1 looks fine. Am I missing something obvious here?
.................... {
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8); // 65.535us, resolution 1us
004B2: MOVLW 82
004B4: MOVWF FD5
....................
.................... ext_int_edge(H_TO_L);
004B6: BCF FF1.6
....................
.................... ext_int_edge(L_TO_H);
004B8: BSF FE9.6
....................
.................... ext_int_edge(1,H_TO_L);
004BA: BCF FF1.5
....................
.................... ext_int_edge(1,L_TO_H);
004BC: BSF FF1.5
....................
.................... clear_interrupt(INT_EXT);
004BE: BCF FF2.1
Compiler version is 5.101
Regards |
|
 |
bulut_01
Joined: 24 Feb 2024 Posts: 206
|
|
Posted: Wed Feb 05, 2025 6:35 am |
|
|
Access the registry settings and do it directly from there |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 527 Location: Montenegro
|
|
Posted: Wed Feb 05, 2025 6:48 am |
|
|
Thanks. That is not a problem, I'm doing it. But it adds potential difficulties with portability of the code, because the bit in question isn't in the same register on every PIC. For 18f46k22 this works:
#bit INTDEG = getenv("BIT:INTCON2.INTEDG0")
but for instance on your PIC you'd need to change it to whatever register INTDEG is located in. |
|
 |
jeremiah
Joined: 20 Jul 2010 Posts: 1371
|
|
Posted: Wed Feb 05, 2025 8:09 am |
|
|
First thing I would suggest is to report the bug to CCS support (this is a user forum, so they don't often check here). That way it can get fixed.
I'm using v5.113 of the compiler and if you supply the INT number to the function it appears to work for me:
Code: |
#case
#include <18f46k22.h>
void main(){
ext_int_edge(0,H_TO_L);
ext_int_edge(0,L_TO_H);
while(TRUE);
}
|
Code: |
.................... ext_int_edge(0,H_TO_L);
0001A: BCF FF1.6
....................
.................... ext_int_edge(0,L_TO_H);
0001C: BSF FF1.6
|
So it is probably a bug in their default logic. It would be good to let them know via the support contacts. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19730
|
|
Posted: Wed Feb 05, 2025 8:33 am |
|
|
Er. Why are you not telling the command which interrupt to use.....
Code: |
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8); // 65.535us, resolution 1us
ext_int_edge(0,H_TO_L); //Note the 0 here......
ext_int_edge(0,L_TO_H); //and here
ext_int_edge(1,H_TO_L);
ext_int_edge(1,L_TO_H);
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
clear_interrupt(INT_EXT1);
enable_interrupts(INT_EXT1);
|
If you look at the declaration for ext_int_edge, it says:
ext_int_edge(int8 source, int8 edge);
_source_.........
What is wrong is that it should be giving you a warning that you are not
specifying the source.
It is actually taking the H_TO_L and L_TO_H constants as the destination,
and therefore selecting the wrong register.. |
|
 |
jeremiah
Joined: 20 Jul 2010 Posts: 1371
|
|
Posted: Wed Feb 05, 2025 8:51 am |
|
|
Ttelmah wrote: | Er. Why are you not telling the command which interrupt to use.....
<snipped>
If you look at the declaration for ext_int_edge, it says:
ext_int_edge(int8 source, int8 edge);
_source_.........
What is wrong is that it should be giving you a warning that you are not
specifying the source.
It is actually taking the H_TO_L and L_TO_H constants as the destination,
and therefore selecting the wrong register.. |
For me the document says that source is optional and will default to 0 if not supplied, so for some versions of the compiler it probably should work without the number
EDIT: I'm running 5.113 currently and it says this for me:
Quote: |
Parameters:
source is a constant 0,1 or 2 for the PIC18XXX and 0 otherwise.
Source is optional and defaults to 0.
edge is a constant H_TO_L or L_TO_H representing "high to low" and "low to high"
|
Last edited by jeremiah on Wed Feb 05, 2025 8:55 am; edited 2 times in total |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 527 Location: Montenegro
|
|
Posted: Wed Feb 05, 2025 8:54 am |
|
|
From help file:
Quote: |
ext_int_edge( )
Syntax:
ext_int_edge (source, edge)
Parameters:
source is a constant 0,1 or 2 for the PIC18XXX and 0 otherwise.
Source is optional and defaults to 0.
edge is a constant H_TO_L or L_TO_H representing "high to low" and "low to high"
|
So much for trusting the defaults :-). And I actually tried with source set, but I put one there instead of 0, for the first external interrupt :-). Anyway, thanks. With the correct source set it works as expected. |
|
 |
jeremiah
Joined: 20 Jul 2010 Posts: 1371
|
|
Posted: Wed Feb 05, 2025 8:56 am |
|
|
PrinceNai wrote: | From help file:
So much for trusting the defaults :-). And I actually tried with source set, but I put one there instead of 0, for the first external interrupt :-). Anyway, thanks. With the correct source set it works as expected. |
Definitely report it to CCS support as well so they can fix it. Glad it is working for you. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9425 Location: Greensville,Ontario
|
|
Posted: Wed Feb 05, 2025 9:19 am |
|
|
re: So much for trusting the defaults :-)
'defaults' are some other guys idea of what worked form HIM, and NEVER ever what YOU need !!!  |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 527 Location: Montenegro
|
|
Posted: Wed Feb 05, 2025 9:38 am |
|
|
Quote: |
'defaults' are some other guys idea of what worked form HIM, and NEVER ever what YOU need !!! |
True. You wrote those exact words many times here and it was the first thing that came to my mind when I saw a reply :-) |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9425 Location: Greensville,Ontario
|
|
Posted: Wed Feb 05, 2025 9:53 am |
|
|
dang I HAVE to be getting senile, I keep repeating myself !  |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19730
|
|
Posted: Wed Feb 05, 2025 10:50 am |
|
|
Yes. I'm a believer in always looking at what the header says. It is interesting
that the header does not have the optional version overload, so you would
actually get an error in MPLAB without the port number.
If you look at the register it selects, it is selecting the peripheral to use
based on the constant, so the overload is not actually functioning on this
chip correctly. Reporting this is definitely the way to go.
I must admit, I would tend to always use the explicit syntax when working
with chips with more than one port, and know that worked for me in the
past.
At least you now have a solution. |
|
 |
|