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

Triggering an interrupt in firmware

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



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

Triggering an interrupt in firmware
PostPosted: Sat May 10, 2014 12:24 pm     Reply with quote

Hi guys,

I feel silly asking this, but I'm spinning my wheels trying to figure out how to do it, and my searches have been fruitless. How do you trigger an interrupt in the code itself?

I'm thinking it is the opposite of the clear_interrupt() function.

Basically, I have a button that I press that triggers an external interrupt, and I'd like to be able to trigger it in code as well.

Thx
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Sat May 10, 2014 1:42 pm     Reply with quote

You'll need to confirm in your data sheet if the interrupt flags you wish to access are writable. Assuming they are, you could map to the desired special function register.

However, why?

Are you saying that you'd like an external interrupt, and a branch of software to execute the same code? Seems like this is just a flow control issue.
temtronic



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

View user's profile Send private message

PostPosted: Sat May 10, 2014 1:44 pm     Reply with quote

off the top of my head....if your program sets the appropriate interrupt flag bit of it's interrupt control register, that 'should' work....
I recall those bits are R-W types ....

I can't test though as I'm working on the D-14 tractor(higher priority interrupt !!)

hth
jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat May 10, 2014 2:23 pm     Reply with quote

I just checked a random PIC data sheet.

Confirms Jay's suspicion, xxxIF's are R/W.

You will, of course, have to check the flag you want to use is indeed R/W.

Though you are not telling us why you should want/need to do it.

Mike
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat May 10, 2014 6:20 pm     Reply with quote

I think you can do it, bearing in mind the previous comments and considerations stated.
Talking seriously, I can not imagine: for what reasons you have to do such test?

regards,
_________________
Humber
picj1984



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

PostPosted: Sat May 10, 2014 7:11 pm     Reply with quote

Now that I've actually thought it through... it doesn't make sense for me to do it this way. I appreciate the responses though!
temtronic



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

View user's profile Send private message

PostPosted: Sat May 10, 2014 9:46 pm     Reply with quote

One reason to do it, is part of a device 'self-calibration' routine where the 'external event' is needed to trigger the 'calibration routine'. Done this way the overall timing would be the same as 'real life'.
'event happens'
ISR is entered...
stuff done...
ISR is exited...
'calibration completed'.

hth
jay
Battery David



Joined: 01 Feb 2010
Posts: 25

View user's profile Send private message

PostPosted: Mon May 12, 2014 12:32 pm     Reply with quote

This is something I have been wondering. I have a customer who wants tests for every possible thing and I have ISRs for things like oscillator failure. How do you test for something like that? I'll just force the interrupt and trust that the hardware will set the bit automatically in case the oscillator actually does fail.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon May 12, 2014 1:23 pm     Reply with quote

Quote:

oscillator failure.


simple...
make a SHORT test program that toggles an LED , say 4x /second.

with your complete PIC fuse setup, using an external plug in crystal
or oscillator can.

then force the osc int failure by pulling out the crystal and watch to see the LED flash rate..

very crude - but a purely "hacker" way to see if it works -
but is just what i'd do Very Happy Very Happy Very Happy
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Mon May 12, 2014 4:18 pm     Reply with quote

Battery David wrote:
This is something I have been wondering. I have a customer who wants tests for every possible thing and I have ISRs for things like oscillator failure. How do you test for something like that?


If your crystal is in a through hole package, I've found that simply touching the leads where they protrude on the bottom of the board is enough to cause the oscillator to fail. I'd imagine that touching the OSC pins on the processor would accomplish the same thing.
Battery David



Joined: 01 Feb 2010
Posts: 25

View user's profile Send private message

PostPosted: Tue May 13, 2014 10:21 am     Reply with quote

Sadly, I'm using the internal oscillator.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue May 13, 2014 10:25 am     Reply with quote

Battery David wrote:
Sadly, I'm using the internal oscillator.


Then the PIC is dead in the water if it fails. No clock = no processing. Doesn't matter if it interrupts, it can't do anything.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Tue May 13, 2014 11:13 am     Reply with quote

Yes.

You need to understand that the PIC needs a clock to run. Can't do anything if the clock is not running. What it has is a circuit to detect if an external oscillator is running, and if it isn't, if 'fail safe clock monitoring' is enabled, it switches to the internal oscillator, and sets the oscillator failure flag. Running on the internal oscillator there is no such fallback.

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Tue May 13, 2014 7:51 pm     Reply with quote

One possible 'dead PIC' detector/display is to have the PIC trigger a 'retriggerable' one shot( 74123 ) every so often. If it fails to do so within the time allowed the oneshot turns on an LED. This does require an I/O pin,74123 and LED but does visually confirm the PIC has stopped.

Another 'philosophy' might be the POST(Power On Self Test) that PCs have had since day one.Before a 'test' is made a number is sent to say the LCD or LED unit. When it passes the test, the number is incremented and carries on...
if the unit fails a test, the number tells you which test failed.

depending on the PICs memory anything/everything could be tested...

just food for thought
hth
jay
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