View previous topic :: View next topic |
Author |
Message |
leaveme
Joined: 24 Nov 2010 Posts: 19
|
Need some info for Timer INT |
Posted: Sun Jul 07, 2013 8:08 am |
|
|
I need following steps for a project. But I have some confusion regarding enabling and disabling the timer. Also I would like to know whether it can be done using one INT routine or I need two.
1. On external interrupt set the timer value and enable the timer
- set_timer1(xyz)?
2. On the timer interrupt - change the state for A1 (i.e. off <> on)
- not an issue.
3. Set the NEXT timer value and set a flag to mark NEXT timer interrupt
- here is the problem. do I need a 2nd INT (i.e. Timer0/2) or I have to just reload the Timer1 for next trigger?
4. On the NEXT timer interrupt - change the state for A2
- it depends on #3.
5. Reset the flag and disable the timer
- setup_timer_1(T1_DISABLED)? or set_timer1(0)?
6. Repeat step 1
- if the the Timer1 disabled in step-5 then how can it be enabled in setp-1?
Thanks in advance for your help. |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Jul 07, 2013 9:43 am |
|
|
suggestion:
write some code
and see what happens. |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Jul 07, 2013 9:52 am |
|
|
Seconded.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
leaveme
Joined: 24 Nov 2010 Posts: 19
|
|
Posted: Sun Jul 07, 2013 10:10 am |
|
|
Actually I would like to know if a timer can be enabled/disabled in a INT ISR call-
setup_timer_1(T1_DISABLED) |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Jul 07, 2013 10:36 am |
|
|
leaveme wrote: | Actually I would like to know if a timer can be enabled/disabled in a INT ISR call-
setup_timer_1(T1_DISABLED) |
Yes, you can, but that's not what you asked initially.
The regulars here want to see some sign of effort from posters.
That's why we asked to see some code.
It gives us a better idea of what you're trying to do, and how to help.
We also then get some indication of your ability and experience.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
leaveme
Joined: 24 Nov 2010 Posts: 19
|
|
Posted: Sun Jul 07, 2013 11:55 am |
|
|
Thanks Mike.
Code: |
#include <16F767.h>
#fuses HS
#FUSES NOMCLR
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#use delay(int=8000000) //Use 8MHz Internal OSC
int16 value1=61035;
int16 value2=46514;
int1 step=0;
#int_EXT
void EXT_isr(void)
{
step=1;
//Timer1 need to be enabled here
//since it is disabled.
//Can't find the correct function
set_timer1(value1); //Reload Timer1 for 1st step
}
#int_TIMER1
void TIMER1_isr(void)
{
if(step==1) {
output_toggle(PIN_B2);
set_timer1(value2); //Reload Timer1 for 2nd step
step=0;
} else {
output_toggle(PIN_B3);
step=1;
setup_timer_1(T1_DISABLED);
}
}
void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
clear_interrupt(INT_EXT);
ext_int_edge(H_TO_L); //set the falling edge
enable_interrupts(INT_EXT); //EXT INT
enable_interrupts(INT_TIMER1); //TIMER1 INT
enable_interrupts(GLOBAL);
while(TRUE)
{
}
}
|
I need exactly what I pointed in 1st post. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Sun Jul 07, 2013 1:22 pm |
|
|
Comments inline:
Code: |
#include <16F767.h>
//#fuses HS This enables the _external_ oscillator
#FUSES NOMCLR
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
//Only one oscillator fuse should ever be selected....
#use delay(int=8000000) //Use 8MHz Internal OSC
int16 value1=61035;
int16 value2=46514;
int1 step=0;
#int_EXT
void EXT_isr(void)
{
step=1;
set_timer1(value1); //Reload Timer1 for 1st step
clear_interrupts(INT_TIMER1); //must clear since it may be set
enable_interrupts(INT_TIMER1); //enable
}
#int_TIMER1
void TIMER1_isr(void)
{
if(step==1) {
output_toggle(PIN_B2);
set_timer1(value2); //Reload Timer1 for 2nd step
step=0;
} else {
output_toggle(PIN_B3);
step=1;
disable_interrupts(INT_TIMER1); //disable
}
}
void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
ext_int_edge(H_TO_L); //set the falling edge
clear_interrupt(INT_EXT); //This needs to be _after_ changing the edge
enable_interrupts(INT_EXT); //EXT INT
//enable_interrupts(INT_TIMER1); //TIMER1 INT - you don't want
//this enabled - yet
enable_interrupts(GLOBAL);
while(TRUE)
{
}
}
|
Note where I clear the interrupts. After the edge is set (read the data sheet), and after setting the timeout value, since it may have already triggered with the interrupt disabled.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|