Joined: 11 Mar 2004 Posts: 5 Location: Germany/Ilmenau
How to produce variable frequency sqare Wave on PIC 18
Posted: Tue Aug 03, 2004 3:38 pm
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
Posted: Tue Aug 03, 2004 5:52 pm
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.
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