View previous topic :: View next topic |
Author |
Message |
Liv
Joined: 09 May 2012 Posts: 6
|
uncontrollable timer interrupt frequency |
Posted: Wed May 09, 2012 7:29 am |
|
|
Greetings members,
It's my first, so be gentle
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
|
|
Posted: Wed May 09, 2012 7:58 am |
|
|
How are you determining that the IRQ frequency isn't changing? How is that measured? |
|
|
Liv
Joined: 09 May 2012 Posts: 6
|
|
Posted: Wed May 09, 2012 8:09 am |
|
|
From the ISR I toggle a led, and measure it’s contact voltage with an oscilloscope. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1353
|
|
Posted: Wed May 09, 2012 8:33 am |
|
|
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
|
|
Posted: Wed May 09, 2012 10:12 am |
|
|
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
|
|
Posted: Wed May 09, 2012 11:38 am |
|
|
Uhhhmmm.... you mean the code you posted here is not the same as you were testing with???? |
|
|
Liv
Joined: 09 May 2012 Posts: 6
|
|
Posted: Wed May 09, 2012 12:01 pm |
|
|
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
|
|
Posted: Wed May 09, 2012 12:49 pm |
|
|
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
|
|
Posted: Wed May 09, 2012 1:40 pm |
|
|
And that's precisely what I attempted to do.
Appreciate the assistance, as well, as the comments. |
|
|
|