Jump to content
Sign in to follow this  
d2squared

Interrupt Too Transparent

Recommended Posts

Hi everyone.

 

I hope this finds you well. This is my first project with BoostC so please be gentle with me … my comfort zone has always been assembly language, when it comes to PIC … all right, let me explain what I'm trying to do … first of all, the PIC I'm using for this project is the PIC16F877A. to drive 2 stepper motors I am using the compare module in conjunction with the TMR0; due to the 19.66 MHz crystal oscillator I have to use, TMR0 must overflow 4x times to get a 40ms period. meanwhile, the compare module will clear RC1 and RC2 when TMR1 reaches the value store in CCPRxH:CCPRxL. I have implemented something similar in assembly language and it worked so it should work, right?

anyway, the problem I have is that, for some reason, the interrupt never happens! I've checked flags and enable bits and it looks all good but I must have missed something. I'll be really grateful if you can spot that. I have enclosed here the source code. for testing purpose I've plugged in an LED on PORTA.0 and turn it ON within the Interrupt Service Routine (ISR) but it remains OFF thus the interrupt for TMR0 overflow never happens.

 

thank you for your time!

test.c

Share this post


Link to post
Share on other sites

Hi

 

Your problem is in the "ISR" routine.

Boost C doesn't recognize it as an interrupt handler.

 

As stated at the BoostC manual at page 68 under "Special Functions", the correct declaration for the ISR is..

void interrupt(void)

This special function name will identify it for the compiler and linker as an ISR.

 

 

You also need to review the inetrrupt control.

Besides, and before, setting the GIE flag, you have to set individual interrupt enable flags and, if necessary, the PEIE flag.

To enable TIMER0 overflow interrupt you have to setup "intcon.TMR0IE".

To enable CCPx inerrupts you have to enable the CCPx specific IE flag (in one of the PIEx registers) and also the intcon.PEIE flag.

 

The GIE flag is the "master switch" so its the last thing to enable after all the remaining interrupts configurations are already in place.

 

 

EDIT:

As you are going to review your code, give it an extra minute to decide if you want a "while(1){};" loop or a "do{}while(1);" loop at the end of main.

 

 

Best regards

Jorge

Edited by JorgeF

Share this post


Link to post
Share on other sites

Jorge nailed it. As soon as I built your sample, and examined the list... there was nothing built for your isr() handler. Second clue: when trying to simulate, it was impossible to place a breakpoint inside isr().

 

I'm not so good at interrupts, but I used the sourceboost project wizard to produce a starting point with all the correctly named functions and setups, then studied that. I also use the simulator and breakpoints as much as possible to confirm the operation of my code.

Edited by kenn

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...