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

Problem with timers of 18F67K22

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



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Problem with timers of 18F67K22
PostPosted: Sat Aug 29, 2015 7:33 am     Reply with quote

Greetings! I want to use a few timers of 18F67K22, but I can activate the interrupt only of timer 0. Here is my code for timer3:
Code:

void SetUpTimer3()
{
   setup_timer_3(T3_INTERNAL|T3_DIV_BY_8);
   enable_interrupts(INT_TIMER3);
   enable_interrupts(GLOBAL);
   set_timer3(100);
}

#INT_TIMER3
void Timer3()
{   
   clear_interrupt(INT_TIMER3);
   set_timer3(5);
}


I can't trigger the interrupt! I tried with other timers -> same result!
Can you tell me what I'm doing wrong?!
Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 29, 2015 4:24 pm     Reply with quote

Quote:
I can activate the interrupt only of timer 0.

It could be something like this thread, where the lack of an #int_tbe
interrupt handler causes the program to interrupt continuously, and
does very little except for that:
http://www.ccsinfo.com/forum/viewtopic.php?t=54209&start=5
We can't know for sure until you post a full test program, with #fuses,
main(), etc.

Also post your compiler version.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sun Aug 30, 2015 12:21 am     Reply with quote

Full test program:
Code:

#include <18F67K22.h>
#fuses HSH,NOWDT
#use delay(clock=40M)

#INT_TIMER3
void Timer3()
{   
   clear_interrupt(INT_TIMER3);
   set_timer3(5);
}

void SetUpTimer3()
{
   setup_timer_3(T3_INTERNAL|T3_DIV_BY_8);
   enable_interrupts(INT_TIMER3);
   enable_interrupts(GLOBAL);
   set_timer3(100);
}

void main()
{
   delay_ms(100);
   SetUpTimer3();
   while(1)
   {
   }
}



I`m using MPLab v8.91 and CCS v5.025.
Best regards!
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Aug 30, 2015 2:00 am     Reply with quote

First thing is your clock is not legal.....

HSH, supports crystals _up to 25MHz_. Not 40Mhz. The only way to get 40Mhz, is to use an external oscillator module, or the PLL. The chip won't actually run (or run at the wrong rate), with the settings shown...

Get rid of the clear_interrupt call. The compiler automatically clears interrupts for you, unless you specify the interrupt handler with 'NOCLEAR'. Clearing it as well is just a waste.

Then, the question is 'how are you testing this'?. From the illegal clock, suggests, it suggests in the simulator?. If so, there were problems with this and timers on these chips. If you switch the settings to use an external clock, and then toggle RB5, you will merrily find the timer counting. With the internal clock, you will find that the timer is not actually counting at all....

The compiler correctly configures the internal instruction clock/8 selection (0x37 into T3CON, and 0 into T3GCON), but the simulator does not handle it.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sun Aug 30, 2015 11:17 am     Reply with quote

Sorry for the mistake in the fuses. Yes, I`m using simulator because I want to adjust the timer to count 10us. Does that mean I have to use only calculation without verifying it with the simulator?!
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Aug 30, 2015 11:20 am     Reply with quote

Test on a real chip. Only takes a few seconds to modify the interrupt code to toggle a pin. If it works you know where the problem is, and also can verify the speed you are getting.
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