View previous topic :: View next topic |
Author |
Message |
jg Guest
|
18f6525 timer3 interrupt problem |
Posted: Wed Feb 01, 2006 2:31 pm |
|
|
Using PCH v 3.230.
Code below.
Explanation: Timer 2 provides the period (1Khz)for the software PWM. I need two seperate duty cycles. Timer 4 provides one and timer 3 provides the other one. Timer 4 is adjustable (30-99% of 1Khz) depending on a setting, this part works flawlessly. My problem is with timer 3, I'm wanting a fixed 50% duty cylce of the 1Khz. Using the o-scope on a pin it works "most of the time", but a lot of the time it is a 2% duty cylce instead of the set 50%.
I'm not using either compare or capture, what else could cause the timer1 to interrupt before it rolls over?
void timer2_int(void)
{
set_timer4(0);
PIR3 &= 0xF7; // clear interrupt for Timer
enable_interrupts(int_timer4);
if(PWM_dutyflag)
output_high(regulator);
else
output_low(regulator);
//PMW for dump valve
output_high(SOLSTART);
set_timer3(64900);
enable_interrupts(int_timer3);
}
#int_timer4
void timer4_int(void)
{
disable_interrupts(int_timer4);
output_low(regulator);
}
#INT_TIMER3
void timer3_int(void)
{
disable_interrupts(int_timer3);
if(!(input(compsw)))
output_low(SOLSTART);
}
Thanks for the time. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 01, 2006 3:03 pm |
|
|
Quote: | I'm not using either compare or capture, what else could cause the timer1 to interrupt before it rolls over? |
In your post you refer to Timers 2, 3, and 4, and you have code for
them, but then in your question you ask about Timer 1.
Can you explain this ? |
|
|
jg Guest
|
|
Posted: Wed Feb 01, 2006 3:18 pm |
|
|
timer1 was a typo, should read timer3 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 01, 2006 4:10 pm |
|
|
I noticed two things:
1. You clear the interrupt flag for Timer4 before you enable it,
but you don't do this for Timer3.
2. You read a switch inside the Timer3 isr. Switches can bounce. |
|
|
jg Guest
|
|
Posted: Wed Feb 01, 2006 4:21 pm |
|
|
not a switch, but either way wouldn't cause what I am seeing.
I'll try clearing timer 3.
Thanks for the time. |
|
|
|