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

Using PWM to drive osc of another mcu, recommended ?

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



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

Using PWM to drive osc of another mcu, recommended ?
PostPosted: Mon Jul 24, 2006 1:50 pm     Reply with quote

Hi,

I've got a circuit that I'm working on that has a PIC and a 2515 spi can controller. The pic gets a 10Mhz crystal and PLL, the 2515 needs at least 5Mhz.

I was kicking around the idea of someone posted to use 1 crystal, the pic hooked up as normal and then split OSC2 from the pic and tie it to OSC1 of the 2515. Lowering the cap on that line a little to make up for the 2515's capactiance.

But then I got to thinking that I have an open PWM pin. Would it be better to drive the 2515 from that ? Can I get a 5-10Mhz signal from ECCP thats clean enough to drive a something ? Maybe with some wave shaping or a non-50% duty cycle ?

Any done this ? I have the option to use CCP or ECCP on an 18F
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Using PWM to drive osc of another mcu, recommended ?
PostPosted: Mon Jul 24, 2006 4:22 pm     Reply with quote

iso9001 wrote:
I was kicking around the idea of someone posted to use 1 crystal, the pic hooked up as normal and then split OSC2 from the pic and tie it to OSC1 of the 2515. Lowering the cap on that line a little to make up for the 2515's capactiance.

In the past I have ran 2 devices: the PIC and the FTDI USB chip of the same 6MHz oscillator. Worked like a charm.

I�m just curious, what will you gain from using a PWM as a clock? You would sacrifice an I/O pin and a timer.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Mon Jul 24, 2006 5:44 pm     Reply with quote

Did you adjust (lower) the cap value on the OSC2 line ?

I don't sacrifice pwm and a timer cause I don't use them anyway Smile

I'd rather use a PWM and timer2 to drive then risk an unstable clock over the entire temp range.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Mon Jul 24, 2006 8:24 pm     Reply with quote

iso9001 wrote:
Did you adjust (lower) the cap value on the OSC2 line ?

I just used an IC oscillator, not a crystall with caps.
If I remember it correctly, crystals tend to become unstable, when there's too little capacitance. In some of my previous designs, excessive capacitance was not causing instability - a crystal specified to operate with 18pF caps was working stably with 30pF caps.
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Mon Jul 24, 2006 8:42 pm     Reply with quote

kender wrote:
iso9001 wrote:
Did you adjust (lower) the cap value on the OSC2 line ?

I just used an IC oscillator, not a crystall with caps.
If I remember it correctly, crystals tend to become unstable, when there's too little capacitance. In some of my previous designs, excessive capacitance was not causing instability - a crystal specified to operate with 18pF caps was working stably with 30pF caps.


Just be careful you don't use too much capacitance. Small capacitance = less stable, but tends to start oscillating easier. High capacitance = more stable, but at the expense of more difficulties establishing oscillation in the first place.
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

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

PostPosted: Mon Jul 24, 2006 9:22 pm     Reply with quote

Pardon me if this has been mentioned in one of the earlier replies, but...

Isn't CLKOUT on the PIC meant to be used to drive another device that requires a clock?
Guest








PostPosted: Mon Jul 24, 2006 10:10 pm     Reply with quote

First, clockout is clock/4 so not aways what you want... Second, it�s only available when you�re using an external oscillator, not a cristal... so it�s not available in most projects.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Tue Jul 25, 2006 10:54 am     Reply with quote

Right,

I already looked into CLKOUT. It would work, if I were using an external osc, not a crystal.

If I use a PWM, I don't need to worry about jitter correct ? I mean, to the controller being driven it should aprear as a very stable clock no ?

I shut the 2515 and some other components down just before I goto sleep with the pic because a lot of my components don't have standby modes, so they need to be shut down. When this occurs I'll have an unbalanced clock (just breifly before I sleep) so I'm not sure what will happen then, and when I goto wake back up.

So.... I think I'll give pwm a try.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Tue Jul 25, 2006 5:29 pm     Reply with quote

PWM is cut. I put it on a scope and its pretty obvious its not going to work. At 40Mhz I could not got a 5Mhz PWM. I got 2.5Mhz but way way too much overshoot and ringing. I could filter it but I can only get it to 2.5Mhz anyway so whats the point.

I'll take my chances with 1 xtal and different value caps.

I do power down the 2515 an instant before I turn the osc off (which does infact clamp the voltage on osc1 line of the 2515 to VDD, wasting a bunch of power) but its really only an instant so it'll probably be fine over its lifetime.

Oh well. That was fun.
Ttelmah
Guest







PostPosted: Wed Jul 26, 2006 7:15 am     Reply with quote

First comment. If there was ringing and spiking on the PWM, then blame the load/layout you have put on the line, not the output. The PWM, is quite capable of giving a clean square wave out, but requires a well laid out track at these sorts of frequencies.
Second comment. The PWM, with a 40MHz clock, can go to 10MHz out. You setup timer2, with:
setup_timer_2(T2_DIV_BY_1,0,1);

and set the pwm period, with:

set_pwm1_duty(2L);

The 'L', is _critical_ or this will not work. Without the 'L', you only access the eight most significant bits of the PWM counter, and will not be able to get an output beyond 2.5MHz.

Best Wishes
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Wed Jul 26, 2006 10:54 am     Reply with quote

Ttelmah,

I first tried the PWM but it was not hooked to anything (except the scope)... I could imagine that it might need a load placed on it to function cleaner.

You're right, the L makes a huge difference. I tested on a scope and found that with setup_timer_2(T2_DIV_BY_1,1,1); and duty(4L) I got a solid 5Mhz signal w/ a 50% duty. (yay)

But... setup_timer_2(T2_DIV_BY_1,0,1); does not work. There are no settings you can put into duty to make a wave. I tested about every setting I could think of. Can't do it.

So maybe I will use PWM for now since all I need is 5Mhz, but eventually I'll have to add a 2nd oscillator if I want to go higher.
Ttelmah
Guest







PostPosted: Thu Jul 27, 2006 2:47 am     Reply with quote

The second value in the 'timer2' setup line, should be the number put into the PR2 register. According to the data sheet, the PWM period, should then be:
[PR2+1]*4*Tosc*prescale

I have used it years ago, 'flat out' on an older PIC, using assembler, and it did work, but you would need to look at a series of different things to find out why it is not working now. First, what CCS actually puts into the register with this value selected. Second the errata sheets, and see if there is a known issue with the '0' value.
It should work, provided the value for 'duty', is not either zero, or divided by four, is not greater than the value in PR2.
Anyway, it sounds as if 5MHz ought to do.

Best Wishes
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