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

18F452 Timer

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



Joined: 04 Apr 2006
Posts: 1

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

18F452 Timer
PostPosted: Tue Apr 04, 2006 4:09 pm     Reply with quote

Smile
I am trying to program a 40 Khz squarewave output on port B bit 2. I am using the timer interupt and timer1. The problem is that I can not get a frequence higher then around 31 KHz even when setting the 16 bit counter to start counting up from 0XFFE0. There seams to be around 16 us of overhead . I am using a 20 MHz clock and the timer should be incremented ever 200 ns. The code is listed below. Would be thankfull for any feed back.



#include <18f452.h>

#device *=16 adc=10 //icd=true
#use delay (clock=20000000)
#fuses HS,PUT,NOPROTECT,NOBROWNOUT,NOWDT,CCP2B3,NOSTVREN,NOLVP



int8 z=0;

// This interrupt is used to Drive LED at 40 KHz
// is automatically called ever 25us.
#INT_TIMER1
void wave_timer() {
int i;

set_timer1(0xFFF0);


if(z){
output_low(PIN_B2);
z=0;
}

else {
output_high(PIN_B2);
z=1;
}

}



main() {

setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);

while(true){
}

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 04, 2006 4:32 pm     Reply with quote

Quote:
I am using the timer interupt and timer1. There seems to be around 16 us of overhead .

The CCS interrupt dispatcher is responsible for most of the overhead.
Instead of using the Timer1 interrupt, I recommend that you use the
PWM module to generate your square wave.

This thread has a PWM example:
http://www.ccsinfo.com/forum/viewtopic.php?t=18259
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