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

How to get correct Pulse Width..??

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



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

How to get correct Pulse Width..??
PostPosted: Wed Sep 22, 2004 7:25 pm     Reply with quote

Hi..We are using 16F877.

I have two problems which are preventing me to produce
correct pulse width.
(1)
We are using Timer1 to produce continuos output pulses
according to Duty Cycle set. And Timer1 is set such a
way that it is interrupted every 0.2mSec.

While Timer1 is running some time we required to use
RTCC timer for 5 Secs. RTCC timer is set such a way that
it is interrupted 72 times per secs.

The problem is, when RTCC timer is ON, it is effected the
output pulses produced by Timer1. What I want that the
Timer1 interrupt should be run at highest proirity and
should be served at the time when ever it is interrupted.

(2)
As I have written some code in side Timer1 interrupt to
control the Duty Cycle of the output pulses. It is effected
the pulse width of the output signal.

It produces 20mSec pulses.
------------------------------------------------------------
#INT_TIMER1
void timer1_isr() {

count++;

if(count<=DCOnDuty)
output_high(PIN_D0);
else
output_low(PIN_D0);

set_timer1(PULSE_TIME); // to overflow every 0.2mSec

if(count>=100)
{
count=0;

// Some code goes here to control the DCOnDuty variable
//used above. It is for controlling duty cycle.
}

}
------------------------------------------------------------

Can anybody guide me with proper solution.

Thanks in advanced....

Regards
Prashant
J_Purbrick



Joined: 16 Sep 2003
Posts: 9

View user's profile Send private message

PostPosted: Thu Sep 23, 2004 8:47 pm     Reply with quote

Hello again.

You're going to have a tough time with 2 interrupts. My suggestion would be to use only one of them, and it should clearly be the one that triggers most frequently, the Timer1 at 5000/sec.

There are some easy ways to produce the other signal. One is to simulate it by counting cycles of the 5000/sec counter; 69 cycles is approximately 1/72 seconds. Just do whatever the RTCC timer would have done, at these intervals.

Is that accurate enough? Maybe not. You could start the RTCC timer but not allow it to trigger an interrupt. Then either in a loop in your main() function, or in the 5000/sec interrupt, check the flag that gets set when RTCC wants to cause an interrupt, T0IF or intcon,2. If it's found to be set, do whatever the interrupt would have done and (important!) clear the flag.

Are you using a 20MHz crystal? Surely at the maximum prescaler value, your interrupt rate for Timer0 would be 5000000/(256*256) times a second, which works out to 76.3Hz--and that's only shown to one decimal place. So you certainly shouldn't object to using 5000/69!
bdavis



Joined: 31 May 2004
Posts: 86
Location: Colorado Springs, CO

View user's profile Send private message

PostPosted: Fri Sep 24, 2004 12:27 am     Reply with quote

You may want to use the #priority directive to tell the CCS compiler to service Timer1 before Timer0(RTCC). I would think that would fix it if your RTCC ISR was very short as to not miss a Timer1 interrupt.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Sep 24, 2004 6:06 am     Reply with quote

Why don't you use the CCP module to generate the pulses?? You would only need an int each time the signal changed states! You would also get a much greater resolution without having to interrupt a zillion times. One trick that I have used in the past to help with interrupt latency is to clear the int flag myself and then insert a goto at the end of the int routine that goes back to the testing of the bits in the int handler. You will have to look at the lst file to figure this address out but it saves on back to back ints. The registers do not have to be restored and then resaved.
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