Changing oscillator configuration (was Two-speed start-up)
Posted: 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.
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.