View previous topic :: View next topic |
Author |
Message |
iso9001
Joined: 02 Dec 2003 Posts: 262
|
Using PWM to drive osc of another mcu, recommended ? |
Posted: Mon Jul 24, 2006 1:50 pm |
|
|
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
|
Re: Using PWM to drive osc of another mcu, recommended ? |
Posted: Mon Jul 24, 2006 4:22 pm |
|
|
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
|
|
Posted: Mon Jul 24, 2006 5:44 pm |
|
|
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
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
|
|
Posted: Mon Jul 24, 2006 8:24 pm |
|
|
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
|
|
Posted: Mon Jul 24, 2006 8:42 pm |
|
|
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
|
|
Posted: Mon Jul 24, 2006 9:22 pm |
|
|
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
|
|
Posted: Mon Jul 24, 2006 10:10 pm |
|
|
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
|
|
Posted: Tue Jul 25, 2006 10:54 am |
|
|
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
|
|
Posted: Tue Jul 25, 2006 5:29 pm |
|
|
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
|
|
Posted: Wed Jul 26, 2006 7:15 am |
|
|
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
|
|
Posted: Wed Jul 26, 2006 10:54 am |
|
|
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
|
|
Posted: Thu Jul 27, 2006 2:47 am |
|
|
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 |
|
|
|