$CRYSTAL
(Created page with "= <span class="f_Header">Action</span><br/> = Instruct the compiler to override the crystal frequency options setting. <span style="font-family: 'Arial'; color: #000000">&n...") |
|||
Line 16: | Line 16: | ||
= <span class="f_Header">Remarks</span><br/> = | = <span class="f_Header">Remarks</span><br/> = | ||
− | <div style="text-align: left; | + | <div style="text-align: left; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 4px"> |
− | {| style="border: solid 2px #000000; | + | {| style="border: solid 2px #000000; border-spacing:0px; border-collapse: collapse" border="1" cellpadding="1" cellspacing="0" width="604" |
− | |- style="text-align:left; | + | |- style="text-align:left; vertical-align:top" |
− | | style="width:13%; | + | | style="width:13%; border: solid 1px #000000" valign="top" width="13%" | |
var | var | ||
− | | style="width:100%; | + | | style="width:100%; border: solid 1px #000000" valign="top" width="100%" | |
A numeric constant with the Frequency of the crystal. | A numeric constant with the Frequency of the crystal. | ||
|} | |} | ||
</div> | </div> | ||
− | <span style="font-family: 'Arial'; | + | <span style="font-family: 'Arial'; color: #000000"> </span> |
The frequency is selectable from the [[Options Compiler Communication]]. It is stored in a configuration file. The $CRYSTAL directive overrides this setting. | The frequency is selectable from the [[Options Compiler Communication]]. It is stored in a configuration file. The $CRYSTAL directive overrides this setting. | ||
Line 33: | Line 33: | ||
It is best to use the $CRYSTAL directive as the used crystal frequency is visible in your program that way. | It is best to use the $CRYSTAL directive as the used crystal frequency is visible in your program that way. | ||
− | <span style="font-family: 'Arial'; | + | <span style="font-family: 'Arial'; color: #000000"> </span> |
[[File:Notice.jpg|left|Notice.jpg]] The $CRYSTAL directive only informs the compiler about the used frequency. It does not set any fuse bit. The frequency must be know by the compiler for a number of reasons. First when you use serial communications, and you specify [[$BAUD]], the compiler can calculate the proper settings for the UBR register. And second there are a number of routines like [[WAITMS]], that use the execution time of a loop to generate a delay. When you specify $CRYSTAL = 1000000 (1 MHz) but in reality, connect a 4 MHz XTAL, you will see that everything will work 4 times as quick. | [[File:Notice.jpg|left|Notice.jpg]] The $CRYSTAL directive only informs the compiler about the used frequency. It does not set any fuse bit. The frequency must be know by the compiler for a number of reasons. First when you use serial communications, and you specify [[$BAUD]], the compiler can calculate the proper settings for the UBR register. And second there are a number of routines like [[WAITMS]], that use the execution time of a loop to generate a delay. When you specify $CRYSTAL = 1000000 (1 MHz) but in reality, connect a 4 MHz XTAL, you will see that everything will work 4 times as quick. | ||
− | <span style="font-family: 'Arial'; | + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | Most new AVR chips have an internal oscillator that is enabled by default. Check the data sheet for the default value. | + | [[File:Notice.jpg]]Most new AVR chips have an internal oscillator that is enabled by default. Check the data sheet for the default value. |
− | + | Most new AVR chips have an option to divide the oscillator frequency by a number of values. If these options are used you need to take this into account. | |
− | <span style="font-family: 'Arial'; | + | For example, you connect a 16 MHz crystal and select the external oscillator fuse byte, this would result in a 16 MHz clock for most old processors. |
+ | |||
+ | Most new processors have an internal divider which can be enabled. This is an 8-divider in most cases. So in such a case, the resulting frequency would be 2 MHz. $crystal should have a value of 2 MHz in that case. | ||
+ | |||
+ | Instead of changing the divider fusebyte you can also use the CONFIG CLOCKDIV command to select the division factor. | ||
+ | |||
+ | In case you have a crystal with 16 MHz and you code has code like : CONFIG CLOCKDIV=4 , you would use $CRYSTAL=4000000 | ||
+ | |||
+ | Thus $crystal is the clock value used to clock the processor. | ||
+ | |||
+ | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
+ | |||
+ | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
= <span class="f_Header">See also</span><br/> = | = <span class="f_Header">See also</span><br/> = |
Latest revision as of 15:13, 4 February 2014
Contents |
Action
Instruct the compiler to override the crystal frequency options setting.
Syntax
$CRYSTAL = var
Remarks
var |
A numeric constant with the Frequency of the crystal. |
The frequency is selectable from the Options Compiler Communication. It is stored in a configuration file. The $CRYSTAL directive overrides this setting.
It is best to use the $CRYSTAL directive as the used crystal frequency is visible in your program that way.
The $CRYSTAL directive only informs the compiler about the used frequency. It does not set any fuse bit. The frequency must be know by the compiler for a number of reasons. First when you use serial communications, and you specify $BAUD, the compiler can calculate the proper settings for the UBR register. And second there are a number of routines like WAITMS, that use the execution time of a loop to generate a delay. When you specify $CRYSTAL = 1000000 (1 MHz) but in reality, connect a 4 MHz XTAL, you will see that everything will work 4 times as quick.
Most new AVR chips have an internal oscillator that is enabled by default. Check the data sheet for the default value.
Most new AVR chips have an option to divide the oscillator frequency by a number of values. If these options are used you need to take this into account.
For example, you connect a 16 MHz crystal and select the external oscillator fuse byte, this would result in a 16 MHz clock for most old processors.
Most new processors have an internal divider which can be enabled. This is an 8-divider in most cases. So in such a case, the resulting frequency would be 2 MHz. $crystal should have a value of 2 MHz in that case.
Instead of changing the divider fusebyte you can also use the CONFIG CLOCKDIV command to select the division factor.
In case you have a crystal with 16 MHz and you code has code like : CONFIG CLOCKDIV=4 , you would use $CRYSTAL=4000000
Thus $crystal is the clock value used to clock the processor.
See also
$BAUD , BAUD , CONFIG CLOCKDIV
Example
$regfile = "m48def.dat" $crystal = 4000000 $baud = 19200 Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Print "Hello world" End
Languages | English • Deutsch |
---|