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

How to produce variable frequency sqare Wave on PIC 18

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



Joined: 11 Mar 2004
Posts: 5
Location: Germany/Ilmenau

View user's profile Send private message ICQ Number

How to produce variable frequency sqare Wave on PIC 18
PostPosted: Tue Aug 03, 2004 3:38 pm     Reply with quote

I want to use a PIC18F242 to produce a square wave with variable frequency between 50Hz an 3khz. On the datasheet I found that I can use CCP1 module for doing this. Toggle the CCP1 Pin on matching Timer1 an reset Timer 1 over the Special event Triger.

My problem is now, how to do this in C
I can't use interrupts for this, because I want to make a tone with this sqare wave and have to do some RS232 actions wich last more than a time between switching for a 3khz signal.

The Pic is running on 20mhz
Timer is is dived by 2
But with
Code:
setup_ccp1(CCP_COMPARE_INT_AND_TOGGLE);

it seemed that it doesn't reset Timer1

After another study of the datesheet I think there ist no chance to produce such a variable frequency with this pic.

Is there a chance to to this with any kind of pic?

I thought this is a standart problem to generate a variable frequency with a pic, without changing a pin manualy or rest a timer after an interrupt...

Thx for help
Mark



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

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

PostPosted: Tue Aug 03, 2004 5:52 pm     Reply with quote

Piece of cake to do the frequency. And yes you can do it with interrupts and still have RS232. The PIC has a hardware UART so it doesn't require any of the processor resources except to load or read a register. The overhead for the square wave should be very small. Set the CCP to toggle the pin and just keep adding the period value to the CCP register. This will cancel out any latency.
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