d2squared 0 Posted December 8, 2012 Report Share Posted December 8, 2012 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 Quote Link to post Share on other sites
JorgeF 0 Posted December 9, 2012 Report Share Posted December 9, 2012 (edited) 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 December 9, 2012 by JorgeF Quote Link to post Share on other sites
kenn 0 Posted December 10, 2012 Report Share Posted December 10, 2012 (edited) 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 December 10, 2012 by kenn Quote Link to post Share on other sites
Recommended Posts
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.