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

How to work with interrupts in K42 series?

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



Joined: 26 Sep 2020
Posts: 37

View user's profile Send private message

How to work with interrupts in K42 series?
PostPosted: Thu Apr 21, 2022 3:06 am     Reply with quote

I ran into the following difficulties while working with interrupts.
My project uses input impulses from an external source.
If I give input pulse the INT0PPS pin, then the code for this interrupt works correctly.
If I give input pulses through Timer2 and CLC, then the CLC interrupt does not work, the code in the interrupt routine is the same.
Timer2 and CLC work correctly, I observe the desired signal with an oscilloscope.
I changed the code in the interrupt routine to "trial" OutputHIGH-Delay-OutputLOW and it doesn't work either.
After that I added at the end of the subroutine clear_interrupt(INT_CLC3); and the trial code is working!
However, after I returned the necessary code to the subroutine, it still does not work.

As far as I understand, this has something to do with the interrupt priority settings.
Tell me what I need to do. It works correctly only with INT0, it does not work with CLC3 CCP1, I have not tried other interrupts.
Environment Version 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 18065

View user's profile Send private message

PostPosted: Thu Apr 21, 2022 3:54 am     Reply with quote

Almost certainly nothing to do with interrupt priorities.
There are only two priorities on the PIC18, and all interrupts will merrily
work provided you are out of any other interrupt handler.

You need to post how you are setting up the timer, and the CLC, and
the code for the CLC interrupt. You need to select the interrupt edge
to be used with CLC_INT_L_TO_H or CLC_INT_H_TO_L (or both),
otherwise the interrupt bit will not be set.
dmitrboristuk



Joined: 26 Sep 2020
Posts: 37

View user's profile Send private message

PostPosted: Thu Apr 21, 2022 5:22 am     Reply with quote

Ttelmah, Thank you. The code will come later. I made the choice of the interrupt edge for the CLC. I don't understand why the same code doesn't work with different interrupts. And why does the trial code work (flashing LED) ?
Ttelmah



Joined: 11 Mar 2010
Posts: 18065

View user's profile Send private message

PostPosted: Thu Apr 21, 2022 5:37 am     Reply with quote

Interrupt handlers are always different.
Serial interrupt handlers have to read/write data.
Change interrupt handlers have to read the bit that has changed.
Tiny differences, but vital.
Something you are doing in the handler, is causing the problem.
We can't tell 'what' without seeing it.
jeremiah



Joined: 20 Jul 2010
Posts: 1276

View user's profile Send private message

PostPosted: Thu Apr 21, 2022 5:37 pm     Reply with quote

To add to Ttelmah's point, if you misconfigure the CLC settings, the interrupt may not even fire. Just post a small throwaway program that sets up the CLC the way you think it should be, have an ISR, and enable it in the main. Ensure the new program still doesn't work, then post it so we can help you out.
dmitrboristuk



Joined: 26 Sep 2020
Posts: 37

View user's profile Send private message

PostPosted: Fri Apr 22, 2022 1:51 am     Reply with quote

I am currently on a trip, so the code will come later. I repeat that the interrupt from the CLC works, the front is configured, but the interrupt only works for the simplest trial code.
I want to test the work in another version of the IDE. Here on the forum there was already a similar topic, and also for K42 http://www.ccsinfo.com/forum/viewtopic.php?p=218438 it is possible that I have a similar reason, I need to check.
temtronic



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

View user's profile Send private message

PostPosted: Fri Apr 22, 2022 5:46 am     Reply with quote

OK, since the 'simplest trial code' works as it should.. make a SMALL change to it and test. If that works, add more code and test. It sounds ike your 'big' program has the problem 'somewhere' so the easiest way to debug is to start from the 'known to work' small code and build from there.
Be sure to copy the working source code, edit/compile/test the COPY. Yes, you may have 5-10-25 versions of the program BUT you'll be able to go back to known working programs. You can also SEE what changes you did that , ah-ha ! , made it fail.

editting the same source ,over and over and , hides mistakes..... and your eyes will never see them.
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