Changing oscillator configuration (was Two-speed start-up)

Post Reply
Bernard Leak
Posts: 18
Joined: Fri Aug 15, 2008 3:42 pm
Location: Armitage, Staffordshire, England

Changing oscillator configuration (was Two-speed start-up)

Post by Bernard Leak » Thu Sep 25, 2008 1:20 pm

Thank you for the new block-set (0.98fe)!

I have found no bugs, but there is still a problem of a different kind.
For the code to run at all, I must give the model an oscillator
configuration with which it can start stably. However,
none of the timers or peripheral modules are enabled until
I have already changed the oscillator configuration - and then
they are configured for the wrong CPU frequency!

I end up configuring the model *as though* starting at once
with the modified oscillator settings: I then have to modify the
<modelname>_main.c file in several ways:
(a) The argument to _FOSCSEL() contains a FNOSC_* macro which I must change
(b) The argument to _FOSC() contains a FCKSM_CS?CM? macro which I once had
to change
(c) The settings of CLKDIV and PLLFBD need to be changed or removed.

The effect of your latest change is that (b) is now unnecessary,
but that's all!

I suggest an addition to the Master mask dialogue. This is a
parameter field with the prompt
"Desired Instructions per Second for Configuring Peripherals"
When clock-switching is enabled, this should be enabled too. The initial
configuration macros and the PLLFBD and CLKDIV settings should still be
found as usual, from the settings explicitly given, but the value of "fcy"
used for configuring the peripheral modules should come from the extra
parameter. For extra credit, when clock-switching is enabled, the
existing prompt "Desired Instructions per Second" can be re-worded
more explicitly as "Desired Instructions per Second at power-on".

This single change would make it possible to build everything from RTW
without having to modify anything externally. The intention is that the
clock-setting can be handled by adjoining a custom source (or object) file,
and injecting a call to it early in the <modelname>_Initialize()
routine, using the Custom Code blocks from Real-time Workshop.

Bernard Leak.

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: Changing oscillator configuration (was Two-speed start-up)

Post by LubinKerhuel » Thu Sep 25, 2008 6:37 pm

Bernard,

I understand the problem since I was already thinking about it while adding the option you requested.

The problem you described seems to be very specific (Does any others dsPIC users encounter a similar problem?)

Anyway, thanks for proposing clear solutions.

I will be out for 3 days from now (be back on Sunday). Thus, I will look at it next week.
The idea is to find a solution that does not make the overall system too complicated for "new users"...

Lubin

Bernard Leak
Posts: 18
Joined: Fri Aug 15, 2008 3:42 pm
Location: Armitage, Staffordshire, England

Re: Changing oscillator configuration

Post by Bernard Leak » Fri Sep 26, 2008 10:35 am

Dear List,
The problem arises whenever the input frequency to the PLL is
not in the range 4MHz to 8MHz. The FRC is near the top of this range, at
7.37MHz. This means that HS + PLL is only possible with clock-switching.
We are using 10MHz oscillators on several of our boards:
hence the problem.

The difficulty is with the initial states of the PLL control registers, before we get
a chance to modify them. These initial states are as follows:

PLLPRE is 0 (i.e., prescale factor is 1/2),
The initial frequency must be in the range 1.6MHz t 16.0MHz anyway, and
after dividing by 2 it is in the range 0.8MHz to 8MHz, which is exactly the
range permitted after using the pre-scaler.

PLLPOST is 1 (i.e., postscale factor is 1/4)
The final frequency will clearly be VCO frequency / 4, and in the range
25MHz to 50MHz, which is all right.

PLLDIV is 48 (i.e., PLL divider is 50)
The input to the PLL must be in the range
100MHz / (PLLDIV + 2) to 200MHz / (PLLDIV + 2),
that is (initially) 2MHz to 4MHz. This corresponds
to prescaler input of 4MHz to 8MHz.

Bernard Leak.

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests