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

uncontrollable timer interrupt frequency

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



Joined: 09 May 2012
Posts: 6

View user's profile Send private message

uncontrollable timer interrupt frequency
PostPosted: Wed May 09, 2012 7:29 am     Reply with quote

Greetings members,

It's my first, so be gentle Smile
The following code generates a clock interrupt.
The problem is that the it's frequency is uncontrollable...
To my understanding beyond the setup, what control the frequency is the value set by: set_timer1() in the ISR.
But what ever value I set, the IRQ frequency does not change. Although the value that get_timer1() returns is changing accordingly(!).

Thank you in advance,
Liv.

Code:

#include <18F6527.h>

#fuses HS, PUT, NOLVP, MCLR, NOPROTECT
#FUSES WDT8192         //Watch Dog Timer uses 1:128 Postscale
#FUSES BROWNOUT        //Reset when brownout detected
#FUSES BORV27          //Brownout reset at 2.5V //was BORV25
#FUSES NOCPD           //No EE protection
#FUSES STVREN          //Stack full/underflow will cause reset
#FUSES NOWRT           //Program memory not write protected
#FUSES NOWRTD          //Data EEPROM not write protected
#FUSES NOIESO          //Internal External Switch Over mode enabled
#FUSES NOFCMEN         //Fail-safe clock monitor enabled
#FUSES NOWRTC          //configuration not registers write protected
#FUSES NOWRTB          //Boot block not write protected
#FUSES NOEBTRB         //Boot block not protected from table reads
#FUSES NOLPT1OSC       //Timer1 configured for low-power operation
#use delay(clock=22118400)

unsigned int16 lStatus = 0x0000;
#INT_TIMER1       
void clock_isr()
{
   set_timer1(0x2800);      //   10 mS
   lStatus = get_timer1();
}

void main()
{
   setup_timer_1(T1_INTERNAL);
   set_timer1(0);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
   
   while(true)
   {
      //dummy operation
   }
}
jeremiah



Joined: 20 Jul 2010
Posts: 1353

View user's profile Send private message

PostPosted: Wed May 09, 2012 7:58 am     Reply with quote

How are you determining that the IRQ frequency isn't changing? How is that measured?
Liv



Joined: 09 May 2012
Posts: 6

View user's profile Send private message

PostPosted: Wed May 09, 2012 8:09 am     Reply with quote

From the ISR I toggle a led, and measure it’s contact voltage with an oscilloscope.
jeremiah



Joined: 20 Jul 2010
Posts: 1353

View user's profile Send private message

PostPosted: Wed May 09, 2012 8:33 am     Reply with quote

Have you verified that your oscillator is running at the values you have set? I.E. have you run:

Code:

void main(){
   while(TRUE){
      delay_us(500);
      output_toggle(DEBUG_PIN);
   }

}


And what did the frequency measure at?

Also, what frequency do you measure for the ISR frequency?

If you change

set_timer1(0x2800);

to

set_timer1(0xEA66);

are there any changes in that value?
Liv



Joined: 09 May 2012
Posts: 6

View user's profile Send private message

PostPosted: Wed May 09, 2012 10:12 am     Reply with quote

Mystery solved! location, location, location...

The clock definition was in the module that includes the main and initialization functions. The ISR is in different module. I copied the clock definition to just before the ISR and miracle of miracles, the ISR frequency is controllable! (Changing the set_timer1() value change the frequency).

Thanks guys, I learned something new.
ckielstra



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

View user's profile Send private message

PostPosted: Wed May 09, 2012 11:38 am     Reply with quote

Uhhhmmm.... you mean the code you posted here is not the same as you were testing with???? Rolling Eyes
Liv



Joined: 09 May 2012
Posts: 6

View user's profile Send private message

PostPosted: Wed May 09, 2012 12:01 pm     Reply with quote

The code is more them 18000 lines in 13 files…
The posted code is a collection of two isolated parts that I considered relevant.
Sorry for any confusion… and I hope that others can benefit too from this post.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed May 09, 2012 12:49 pm     Reply with quote

Maybe next time you follow CCS forum guide, i.e. post complete compilable code so we can test to help sort out your problem.

Mike
Liv



Joined: 09 May 2012
Posts: 6

View user's profile Send private message

PostPosted: Wed May 09, 2012 1:40 pm     Reply with quote

And that's precisely what I attempted to do.
Appreciate the assistance, as well, as the comments.
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