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 CCS Technical Support

Hello my friends - What is the purpose of timer ?

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



Joined: 02 Oct 2013
Posts: 4

View user's profile Send private message

Hello my friends - What is the purpose of timer ?
PostPosted: Fri Jan 31, 2014 1:39 pm     Reply with quote

Please help me. I am totally confusing with this timer and calculations. I was read a lot of examples. many examples said different calculation for generating pulses.

What is the purpose of timer?
Where it should be used?
How to calculate ?
please explain rtcc,internal rtcc, extra.
What is the synatx for enable and use the timer ?

I am using proteus for simulation. Also 877 is in real time.
_________________
Thanks and Regards
Sureshkumar.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 01, 2014 12:24 am     Reply with quote

Look at the end of this post. It has four links on Timers:
http://www.ccsinfo.com/forum/viewtopic.php?t=46384&start=3
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

Re: Hello my friends - What is the purpose of timer ?
PostPosted: Sun Feb 02, 2014 11:46 am     Reply with quote

sureshkumar wrote:


I am using proteus for simulation. Also 877 is in real time.



Also make sure to read this link:


http://www.ccsinfo.com/forum/viewtopic.php?t=47549
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
palyancodr



Joined: 06 Jan 2014
Posts: 31

View user's profile Send private message

PostPosted: Sun Feb 02, 2014 7:21 pm     Reply with quote

The purpose of timer is as it can be understood from it's name "timing".

Simply with an example, let's say you wanna generate a PWM signal with 1.5ms HIGH cycle and 18.5 LOW cycle in total 20ms which is 50hz.

To do that you need a timer so you can turn state off if 1.5ms passed and turn state on if 18.5ms pass.

It is easy to do that with delay function without using timers:

Code:
output_high(pin_a0);
delay_us(1500); // which is equivalent of 1.5ms MCU waits till 1.5ms passes and do nothing, does not respond to any interrupt
output_low(pin_a0);
delay_us(18500); // which is equivalent of 18.5ms  MCU waits till 1.5ms passes and do nothing does not respond to any interrupt


When you do like above by using delays you actually freeze the MCU, if MCU freezes it does not do anything till the stated time value passes. This is not good because an interrupt can occur that freeze time and mcu can't respond it which we can also call this interval dead time.

Instead of freezing the MCU we use timers. You can imagine timer as a chronometer ticking at background and do your timing stuff and let you know about your time stuff according to your way of modifying it.

So the code at above turns into something like this below:

Code:
output_high(pin_a0);
*let me know if 1500us passes and do what ever you do now you are doing and accept any interrupt and proceed through it *
if(*ok 1500us passed*){

output_low(pin_a0);

}
*let me know if 18500us passes and do what ever you do now you are doing accept any interrupt and proceed through it*
if(*ok 18500us passed*){

output_low(pin_a0);

}

_________________
Hardware-Software Developer
Physics Engineer
Ceo airVision Aerial Video and Photography
Ceo Massive Robotics

ccs c ide version: 4.110
Pic: 16F877
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