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

PIC 18F45K22 #INT_EXT1 problem

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



Joined: 07 Apr 2017
Posts: 31

View user's profile Send private message

PIC 18F45K22 #INT_EXT1 problem
PostPosted: Fri Apr 07, 2017 11:54 am     Reply with quote

Compiler version: 5.066 and 5.058.
MCU: 18F45K22
FUSES: INTRC_IO, NOWDT, PUT, NOFCMEN, MCLR, NOPLLEN, NOPROTECT, NOPBADEN
CLOCK: Internal 4M


I have a problem with #INT_EXT1 ISR.
If I generate falling edge on RB0 (#INT_EXT) MCU enters only #INT_EXT ISR.
If I generate falling edge on RB1 (#INT_EXT1) MCU enters #INT_EXT and #INT_EXT1 ISRs.
If I generate falling edge on RB2 (#INT_EXT2) MCU enters only #INT_EXT2 ISR.

As you can see, I have a problem on RB1. Every time it enters 2 ISRs (#INT_EXT and #INT_EXT1).

Interrupt flag INT0IF is set every time when the INT1IF is set, even if there was no falling edge on pin RB0.

PCB is checked and there is no short between pins RB0 and RB1.

If anybody is able to test these few lines of code on his/her MCU/devboard, please do it and post the results.

Code:
#byte INTCON = 0xFF2 // INTCON register
#byte INTCON3 = 0xFF0 // INTCON3 register

void mcu_init()
{
   set_tris_a(0xFF);
   set_tris_b(0xFF);
   set_tris_e(0b00000010);
   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT);
   ext_int_edge(0, H_TO_L);
   enable_interrupts(INT_EXT1);
   ext_int_edge(1, H_TO_L);
   enable_interrupts(INT_EXT2);
   ext_int_edge(2, H_TO_L);
   
   setup_vref(VREF_4v096);
   setup_adc_ports(sAN6 | VSS_FVR);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(6);
   delay_ms(10);
   
   MCP7940_init();
}


Code:
#INT_EXT
void META_POGODJENA_isr()
{
   printf("\nUlazak u #INT_EXT\n");
   printf("\n\nINTCON: %X\nINTCON3: %X\n", INTCON, INTCON3);
   printf("\nIzlazak iz #INT_EXT\n");
}

#INT_EXT1
void RESET_isr()
{
   printf("\nUlazak u #INT_EXT1\n");
   printf("\nINTCON: %X\nINTCON3: %X\n", INTCON, INTCON3);
   printf("\nIzlazak iz #INT_EXT1\n");
}

#INT_EXT2
void EXT2_isr()
{
   printf("\nINTCON: %X\nINTCON3: %X\n", INTCON, INTCON3);
}


Last edited by Milentije89 on Sun Apr 09, 2017 8:31 am; edited 1 time in total
temtronic



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

View user's profile Send private message

PostPosted: Fri Apr 07, 2017 12:26 pm     Reply with quote

Quick reply
1) You should not use printf(...) inside any ISR. Just set a flag and exit.
ISRs are supposed to be FAST. In main() print messages based on flags. Be sure to reset the flag though !

2) What is your interrupt source? a Push button switch ? They are noisy, you can get several interrupts from one push. You need 'debouncing'. Use some R-C network as needed, use an oscilloscope to see the actual signal.

3) This... setup_adc(ADC_CLOCK_INTERNAL); , is probably wrong, though not your ISR problem. In the ADC section of the manual there will be a chart of proper choices. Usually 'internal' is for a PIC that goes to sleep and/or running <1MHz

Jay
Milentije89



Joined: 07 Apr 2017
Posts: 31

View user's profile Send private message

PostPosted: Fri Apr 07, 2017 1:47 pm     Reply with quote

Thank you for your answer.

temtronic wrote:
Quick reply
1) You should not use prinf(...) inside any ISR. Just set a flag and exit.
ISRs are supposed to be FAST. In main() print messages based on flags. Be sure to reset the flag though !


Of course I am not using printf function in an ISR. This is just for testing purposes.

temtronic wrote:
2) What is your interrupt source? a Push button switch ? They are noisy, you can get several interrupts from one push. You need 'debouncing'. Use some R-C network as needed, use an oscilloscope to see the actual signal.


It has nothing with noisy source.

temtronic wrote:
3) This... setup_adc(ADC_CLOCK_INTERNAL); , is probably wrong, though not your ISR problem. In the ADC section of the manual there will be a chart of proper choices. Usually 'internal' is for a PIC that goes to sleep and/or running <1MHz


ADC works perfectly.

I am looking for somebody who had same problem. This looks like compiler or silicon bug. I can't find anything related in errata, so I am looking toward compiler.

Also, it might be just me, I am too tired at the moment, so I might be missing something.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Fri Apr 07, 2017 1:58 pm     Reply with quote

The ADC will have significantly degraded accuracy over what it is capable of. Worth fixing....

However I use the 45K22, and all three interrupts (and several others), and do not have any problems.
Honestly, you have a big clue, in that if the interrupt flag is being set, since this is a hardware operation, it says that something in the hardware is triggering it. Question is 'what'.
Obvious things are some significant capacitive coupling between the pins, or a hardware peripheral that is being affected (have you got the ECCP disabled, the timer that uses this as a clock input, the comparator etc., all turned off?
What is pulling the interrupt pins 'up'?. Remember the internal pullup is very weak, and it doesn't take much to pull a signal down if these are what you are using. What happens if you directly pull INT0 'up' with a wire, and then operate INT1?.
Milentije89



Joined: 07 Apr 2017
Posts: 31

View user's profile Send private message

PostPosted: Fri Apr 07, 2017 2:21 pm     Reply with quote

Thank you for the answer.

Ttelmah wrote:
However I use the 45K22, and all three interrupts (and several others), and do not have any problems.
Honestly, you have a big clue, in that if the interrupt flag is being set, since this is a hardware operation, it says that something in the hardware is triggering it. Question is 'what'.


We have a question. Now we just have to find the answer. Very Happy

Quote:
Obvious things are some significant capacitive coupling between the pins, or a hardware peripheral that is being affected (have you got the ECCP disabled, the timer that uses this as a clock input, the comparator etc., all turned off?


Disabling peripherals doesn't make any difference.

Quote:
What is pulling the interrupt pins 'up'?. Remember the internal pullup is very week, and it doesn't take much to pull a signal down if these are what you are using.


I am not using internal pull-ups.

RB0 receives signal from 74HC08D.
RB1 has 10k PU and 100nF to GND. (This is the source of a problem)
RB2 has 10k PU (It's not part of original design, it is there just for testing)

Quote:
What happens if you directly pull INT0 'up' with a wire, and then operate INT1?.


I am not sure I understood this.
temtronic



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

View user's profile Send private message

PostPosted: Fri Apr 07, 2017 3:25 pm     Reply with quote

Quote:
What happens if you directly pull INT0 'up' with a wire, and then operate INT1?.

Means place wire from Vdd to INT0 pin, this keeps it high forever, THEN cause an INT1 to occur.
Milentije89



Joined: 07 Apr 2017
Posts: 31

View user's profile Send private message

PostPosted: Fri Apr 07, 2017 3:58 pm     Reply with quote

Problem solved. Parasitic capacitance between RB0 and RB1.
Wrong selection of RPU and C to GND.

That was my bad.

Thank you both for help and answers.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Sat Apr 08, 2017 10:25 am     Reply with quote

By 'knowing' that the interrupt flag was set, you gave the clue that allowed us to help point you in the right direction.
Nice bit of 'teamwork'. Smile
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