View previous topic :: View next topic |
Author |
Message |
Doc
Joined: 19 Mar 2005 Posts: 1
|
Timer2 |
Posted: Tue Apr 05, 2005 4:57 am |
|
|
How do I the initialization for the timer2
void main(void)
{
// Do initialization
// setup timer2 to int every milisecond
// Start counting
miliseconds = 0
// wait until the 1 second is up
while (miliseconds < 1000);
do_function();
// wait until the 10 seconds are up
while (miliseconds < 10000);
while(1)
{
}
..will this work??
useing a PIC 16F870
4Mhz
Thx a lot |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Apr 05, 2005 5:12 am |
|
|
The great thing about an interupt based timer is that you can do other things while the timers is counting in the background. The disadvantage is that the code is harder to write than a simple while-loop.
In your pseudo code program there are no simultaneous actions, so why do you want to use an interrupt based timer? Just a simple delay_ms() will do the job. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Apr 05, 2005 8:14 am |
|
|
ckielstra wrote: | The great thing about an interupt based timer is that you can do other things while the timers is counting in the background. The disadvantage is that the code is harder to write than a simple while-loop.
In your pseudo code program there are no simultaneous actions, so why do you want to use an interrupt based timer? Just a simple delay_ms() will do the job. |
I can tell you why, it is because he wanted to do some calculations during the 10 seconds. See his orginal post
http://www.ccsinfo.com/forum/viewtopic.php?t=22430
He should have continued with his other post. Why he didn't I can only guess that he is too lazy. He repeatily posts in the Code forum asking for advice. Each time, other members tell him not to but he still does. I am not sure what is up with this guy but setting up a timer is pretty easy and there are plenty of examples posted and the manual explains how to do it. I would make him try it out. When it doesn't work, then he can post his code and we can tell him where he went wrong. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Apr 05, 2005 8:26 am |
|
|
First, read the documentation that you received with the compiler.
Second, search this forum for a whole BUNCH of examples that have been posted.
Third, write a few sample programs to experiment with. Try to figure out why they don't work by tweeking different settings.
Then, and only then, come back here and post your problem and some of your sample program. We will be more than glad to help you at that time.
If you're not willing to put in the effort to try this then you might as well turn off your computer and pick up the TV remote and resume watching re-runs of Gilligan's Island.
We aren't here to do your work for you. You need to put some of your own effort in first. Most of us have flat screen monitors not simply because we purchased them that way, we just reshaped them by banging our foreheads against them so many times while trying to figure out what we did wrong inside our code.
Ronald |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Apr 05, 2005 8:46 am |
|
|
Quote: |
Most of us have flat screen monitors not simply because we purchased them that way, we just reshaped them by banging our foreheads against them so many times while trying to figure out what we did wrong inside our code.
|
Yes Ronald, you are right !!!
Now I understand why my screen monitor is becoming concave !!!
Thanks for such a funny comment. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Tue Apr 05, 2005 9:30 am |
|
|
rnielsen wrote: | We aren't here to do your work for you. You need to put some of your own effort in first. Most of us have flat screen monitors not simply because we purchased them that way, we just reshaped them by banging our foreheads against them so many times while trying to figure out what we did wrong inside our code.
Ronald |
Amen to that.
And you forgot to mention all the hair that is stuck in our keyboards because we've pulled it all out. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 05, 2005 11:27 am |
|
|
Here is code to setup Timer2 to interrupt every 1 ms. This program
puts out a 10 us pulse on pin B1 every 1 ms.
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#int_timer2
void timer2_isr(void)
{
output_high(PIN_B1);
delay_us(10);
output_low(PIN_B1);
}
void main()
{
setup_timer_2(T2_DIV_BY_4, 249, 1);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
while(1);
} |
|
|
|
Ttelmah Guest
|
|
Posted: Tue Apr 05, 2005 3:02 pm |
|
|
newguy wrote: | rnielsen wrote: | We aren't here to do your work for you. You need to put some of your own effort in first. Most of us have flat screen monitors not simply because we purchased them that way, we just reshaped them by banging our foreheads against them so many times while trying to figure out what we did wrong inside our code.
Ronald |
Amen to that.
And you forgot to mention all the hair that is stuck in our keyboards because we've pulled it all out. |
I refer often, to 'wall, head, impact technology testing'. This was especially true some time ago, when trying to move a project from the 16F family to the early 18F chips, with their bugs, and the compiler ones too. The incidence of grey hairs, alopecia, and flat foreheads, all rose.
Best Wishes |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Apr 05, 2005 6:18 pm |
|
|
How does an autoimmune disorder come from working on PIC's I have alopecia barbae which affects the beard. Looks really funny since I get a 5 o'clock shadow before mid-morning. I'll be glad when it quits or my whole beard is gone, I could live without shaving |
|
|
|