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

Help with Interrupts 18F248
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
newguy



Joined: 24 Jun 2004
Posts: 1946

View user's profile Send private message

PostPosted: Tue Feb 21, 2006 9:02 pm     Reply with quote

Okay.....Not sure about that, though.

You're also missing this at the end of main:

Code:
while (TRUE) {}


The compiler inserts a hidden sleep() instruction at the end of the program. The while() loop keeps it from hitting it.
uhoh-robbo
Guest







PostPosted: Thu Feb 23, 2006 6:53 pm     Reply with quote

yeh I realised I misse dthat just after I posted. I put in a while (1) {} loop and still no joy Crying or Very sad
newguy



Joined: 24 Jun 2004
Posts: 1946

View user's profile Send private message

PostPosted: Thu Feb 23, 2006 8:15 pm     Reply with quote

uhoh-robbo wrote:
yeh I realised I misse dthat just after I posted. I put in a while (1) {} loop and still no joy Crying or Very sad


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

View user's profile Send private message

PostPosted: Thu Feb 23, 2006 9:30 pm     Reply with quote

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








PostPosted: Fri Feb 24, 2006 1:34 pm     Reply with quote

Ok I added the NOLVP, but still no joy with the interrupts.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 24, 2006 2:10 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Feb 24, 2006 2:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 24, 2006 2:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 24, 2006 3:56 pm     Reply with quote

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







PostPosted: Fri Feb 24, 2006 4:51 pm     Reply with quote

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







PostPosted: Sun Feb 26, 2006 8:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 26, 2006 10:22 am     Reply with quote

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]... Very Happy

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







PostPosted: Sun Feb 26, 2006 11:28 am     Reply with quote

It was version 3.227.
Humberto



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

View user's profile Send private message

PostPosted: Sun Feb 26, 2006 4:21 pm     Reply with quote

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








PostPosted: Sun Feb 26, 2006 5:44 pm     Reply with quote

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....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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