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 support@ccsinfo.com

Timer2

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



Joined: 19 Mar 2005
Posts: 1

View user's profile Send private message

Timer2
PostPosted: Tue Apr 05, 2005 4:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 05, 2005 5:12 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Apr 05, 2005 8:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 05, 2005 8:26 am     Reply with quote

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. Twisted Evil

Ronald
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Apr 05, 2005 8:46 am     Reply with quote

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 !!! Wink
Now I understand why my screen monitor is becoming concave !!!

Thanks for such a funny comment. Very Happy
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Tue Apr 05, 2005 9:30 am     Reply with quote

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. Twisted Evil

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. Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 05, 2005 11:27 am     Reply with quote

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







PostPosted: Tue Apr 05, 2005 3:02 pm     Reply with quote

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. Twisted Evil

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. Very Happy

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

View user's profile Send private message Send e-mail

PostPosted: Tue Apr 05, 2005 6:18 pm     Reply with quote

How does an autoimmune disorder come from working on PIC's Very Happy 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 Laughing
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