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

Newbie Help w/ TMR0

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



Joined: 04 Sep 2011
Posts: 9

View user's profile Send private message

Newbie Help w/ TMR0
PostPosted: Sun Dec 11, 2011 12:51 pm     Reply with quote

Using an 18F4620 with PICKIT 2 programmer. Trying to flash LED on port c0 as part of an interrupt routine. Have scoured microchip and CCS manuals and cannot figure out why this does not run. In debug, the timer never starts and the interrupt routine is never called. I have added a "flag" variable (j) to let me know if the interrupt gets called. I look at these in the "watch" window in mplab. I have added 'm" to see if the timer ever starts and it never does. I have preloaded TMR0 with 50. HELP!! why does TMR0 never start?

#include <18F4620.H>
#use delay (clock = 10MHz)

int i = 0;
int j = 0;

#INT_TIMER0 //format for rtcc isr - defined by compiler
clock_isr()

{
j = j++;
if (i==0)
{
output_high(pin_c0);
i = 1;
}
else
{
output_low(pin_c0);
i = 0;
}
}

void main(void)
{
while (1==1)
{
long m = 0;
setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_128);
enable_interrupts (int_timer0);
enable_interrupts (GLOBAL);
set_timer0(50);
m = get_timer0();
}
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 1:21 pm     Reply with quote

What is your compiler version number?

Have you configured #fuses? If no, then that is your problem. If yes, then please post them.

Next time, use the 'code' buttons when posting code. This ensures the formatting is preserved and makes for easier reading.

In situations like this make the code easier until the PIC is working again. The last step before making it working again will be your problem. For example, have you tried running your code without an interrupt?

Something completely different, but the code:
Code:
if (i==0)
{
output_high(pin_c0);
i = 1;
}
else
{
output_low(pin_c0);
i = 0;
}
can be simplified to:
Code:
output_toggle(PIN_C0);
doggitz



Joined: 04 Sep 2011
Posts: 9

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 3:37 pm     Reply with quote

I have not set fuses. I will look to see what I might have missed.Compiler is version 4.124
adi1133



Joined: 30 Dec 2010
Posts: 6

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 5:17 pm     Reply with quote

An interrupt is triggered when timer0 overflows (after 255).
You dont allow it to rise to 255 because you set it to 50 each time in the while loop.

Remove "set_timer0(50);" from the loop.
Also there is no reason to set up timer0 each time you execute the loop.

Here is an simplified example of the code
Code:

#include <18F4620.H>
#use delay (clock = 10MHz)


#INT_TIMER0
void clock_isr(void)

{
   output_toggle(PIN_C0); //toggle pin C0
}

void main(void)
{
   setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_128); //timers and interrupts need to be set only once
   enable_interrupts (int_timer0);
   enable_interrupts (GLOBAL);


   while(1); //a loop to keep the chip active
}
doggitz



Joined: 04 Sep 2011
Posts: 9

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 11:13 pm     Reply with quote

That worked- thanks
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