| View previous topic :: View next topic |
| Author |
Message |
newguy
Joined: 24 Jun 2004 Posts: 1946
|
|
Posted: Tue Feb 21, 2006 9:02 pm |
|
|
Okay.....Not sure about that, though.
You're also missing this at the end of main:
The compiler inserts a hidden sleep() instruction at the end of the program. The while() loop keeps it from hitting it. |
|
 |
uhoh-robbo Guest
|
|
Posted: Thu Feb 23, 2006 6:53 pm |
|
|
yeh I realised I misse dthat just after I posted. I put in a while (1) {} loop and still no joy  |
|
 |
newguy
Joined: 24 Jun 2004 Posts: 1946
|
|
Posted: Thu Feb 23, 2006 8:15 pm |
|
|
| uhoh-robbo wrote: | yeh I realised I misse dthat just after I posted. I put in a while (1) {} loop and still no joy  |
Then, just for kicks, humor me and take out the variable initializations within your ISR. See what happens. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 23, 2006 9:30 pm |
|
|
You're also missing the NOLVP fuse. If you're using a normal
programmer (ICD, ICD2, MachX, Warp-13a, PicStart-Plus, etc.)
then you should have NOLVP in there. Example:
| Quote: | | #fuses HS, NOWDT, NOPROTECT, NOPUT, NOLVP |
|
|
 |
Guest
|
|
Posted: Fri Feb 24, 2006 1:34 pm |
|
|
| Ok I added the NOLVP, but still no joy with the interrupts. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 24, 2006 2:10 pm |
|
|
I took your code, modified it slightly, and ran it on my 18F458 board.
It worked OK. With a 4 MHz crystal, the signal on pin C2 goes high
for about 3.6 seconds and low for 3.6 seconds, continuously.
The board runs at 5v, and I used the PCH vs. 3.242 compiler.
Is it possible that the reason you think its not working is because
the output signal changes so slowly, and you're actually expecting
a high speed signal ?
| Code: |
#include <18F458.h>
#fuses XT, NOWDT, NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#define TIM_TIMER0_RELOAD_VAL 112
#INT_TIMER0
void TIM0_ISR()
{
static unsigned char Second_Ticks = 0;
static int1 OnorOff=0;
/* set the timer to 112 to maintain frequency to 100Hz */
set_timer0(TIM_TIMER0_RELOAD_VAL);
Second_Ticks++;
output_high(PIN_C0);
/* do the following every 1s */
if (100 == Second_Ticks)
{
if(!OnorOff)
{
output_high(PIN_C2);
OnorOff=1;
}
else
{
output_low(PIN_C2);
OnorOff=0;
}
Second_Ticks=0;
}
}
//======================================
void main (void)
{
/* setup timer */
setup_timer_0( RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT );
/* enable timer 0 overflow interrupt */
enable_interrupts ( INT_TIMER0 );
enable_interrupts ( GLOBAL );
while(1);
} |
|
|
 |
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Fri Feb 24, 2006 2:15 pm |
|
|
May be totally unrelated, or a red herring, but ...
Have you got any CAN interrupts enabled. If you have and its connected to a bus with high CAN traffic and no message filtering, other interrupts never get time to be serviced ! _________________ Regards,
Simon. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 24, 2006 2:30 pm |
|
|
Here are the calculations for determining the Pin C2 toggle rate:
I'm using a 4 MHz crystal.
4 MHz / 4 = 1 MHz instruction cycle rate
1 MHz / 256 prescalar = 3906 Hz Timer 0 clock rate
256 - 112 = 144 counts before Timer0 overflows
3906 Hz / 144 = 27 Hz interrupt rate
27 Hz / 100 counts = .27 Hz toggle rate
1 / .27 Hz = 3.7 seconds duration for the high level and the low level.
That roughly matches what I got with my stopwatch. |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Feb 24, 2006 3:56 pm |
|
|
| I would also like to know the compiler version and chip level revision Uhoh-robbo is working with. It might be something in the chip's erratta. |
|
 |
Ttelmah Guest
|
|
Posted: Fri Feb 24, 2006 4:51 pm |
|
|
Also, I do remember a long time ago, having problems if the interrupts were defined after the main. On newer compilers this is not a problem, but at some point, it was. Might apply to the version in use.
Best Wishes |
|
 |
uhoh-robbo Guest
|
|
Posted: Sun Feb 26, 2006 8:19 am |
|
|
Woohooo. Cheers guys for all of your help. Finally got the interrupts working. I think it was a mixture of not having the #use delay at the start and the NOLVP.
Woooohoooooo.
Thanks! |
|
 |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sun Feb 26, 2006 10:22 am |
|
|
| Quote: |
I think it was a mixture of not having the #use delay at the start and the NOLVP.
|
It is like saying that somebody is almost [spam]...
Like repayment of gentilities to which they helped you, (and for us the readers of this thread)
it would be very good for knowing the version code that made the difference.
cheers,
Humberto |
|
 |
uhoh-robbo Guest
|
|
Posted: Sun Feb 26, 2006 11:28 am |
|
|
| It was version 3.227. |
|
 |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sun Feb 26, 2006 4:21 pm |
|
|
Thanks uhoh-robbo.
I am not talking about the compiler version.
"knowing the version code that made the difference" I want to mean what changes you have done
in a code that does not work so that now it works correctly.
You said that NOLVP doesn't make any difference and as a final conclusion you stated that
may be the #use delay directive. It is confusing because the #use delay directive make sense only
if you use the built in delays functions or any other function that is time dependant.
#use delay directive tells the compiler how long last a machine cycle for an additional calculation if it corresponds.
In the piece of code that you posted it doesn't matter if you use it or not, so forget it as a possible cause.
It is a matter of getting the correct conclusion to learn from it.
Humberto |
|
 |
Guest
|
|
Posted: Sun Feb 26, 2006 5:44 pm |
|
|
Ohh ok I see. Well the only changes I made were adding the NOLVP and the use delay.
Sorry I wich I had a better reason.... |
|
 |
|