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

Synchronized clock frequency

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








Synchronized clock frequency
PostPosted: Mon Aug 28, 2006 6:21 am     Reply with quote

Hi,

I have to read an ADC that work at 4Mhz max.
My problem is that my PIC (18F452) is working at 40 mhz and it must be synchronous with ADC.
how can i get a frequency of 4Mhz synchronized and derived from the main clock?
I thought to use SETUP_POWER_PWM, but I dont understand it.
Can anoyone help me ?

Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 28, 2006 4:01 pm     Reply with quote

The 18F452 doesn't have a Power PWM module. It only has a normal
PWM module.

Here is a thread which discusses using the PWM output as a clock source:
http://www.ccsinfo.com/forum/viewtopic.php?t=27712

If you take the code shown in that thread, and use an 8 MHz crystal
in 4x PLL mode (so it runs at 32 MHz), then you can get a 4 MHz clock
signal from the CCP1 pin. I tested this and it works.

You can't do it when running at 40 MHz (with a 10 MHz crystal) because
the Timer2 is clocked at Fosc/4, which is 10 MHz. To get a 4 MHz PWM
output, you would need to divide by 2.5, and you can't do that.
That's why you must run it at 32 MHz (with an 8 MHz crystal).

Example:
Code:

#include <18F452.h>
#fuses H4,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=32000000) 

//================================

void main()
{
setup_timer_2(T2_DIV_BY_1, 1, 1);

setup_ccp1(CCP_PWM);

set_pwm1_duty(4L);

while(1);
}
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