![]() ZBasic System Library
14
ZBasic Microcontrollers
with BasicX (but only for ZX processors running at 14.7456MHz), some of the routines effectively divide
the timer frequency by 2 so that the time units associated with parameters or return values are preserved.
If you change the timer speed setting, the scale factor is still applied.
TimerSpeed Selector Values
TimerSpeed
Value
Frequency
ATtiny, ATmega
Frequency
ATxmega
0
0
0
1
F_CPU / 1
F_CPU / 1
2
F_CPU / 8
F_CPU / 2
3
F_CPU / 64
F_CPU / 4
4
F_CPU / 256
F_CPU / 8
5
F_CPU / 1024
F_CPU / 64
6
External T1
F_CPU / 256
7
External T2
F_CPU / 1024
8-15
n/a
Event 0-7
The default values of Register.TimerSpeed1 and Register.TimerSpeed2 are shown in the table
below.
Default TimerSpeed Values
CPU Family
TimerSpeed1
TimerSpeed2
ATmega, ATtiny
1
2
ATxmega
2
4
Note that setting the value of either of the timer speed registers other than by direct assignment using an
assignment statement will produce undefined results.
There are several important facts to keep in mind if you modify either of the timer speed values. Firstly,
the timer speed values are initialized by the system when it begins running and they are never modified
by the system thereafter. If you change a timer speed value, that value will be used by all of the related
System Library routines until you change it again. Secondly, the applicable TimerSpeed value is used
during the configuration and setup of each I/O function. If you change the TimerSpeed value after a
particular I/O function is configured, the change will not affect I/O functions configured before that change.
Note, also, that values returned by some of the System Library routines are scaled based on the default
timer speed values. If you change the timer speed setting, youll have to apply an additional scale factor
in order to get the correct results. For example, if you set Register.TimerSpeed2 to 3 on an ATmega-
based device running at 14.7MHz and then call the subroutine PulseIn(), a pulse having a width of
100µS will return the value of approximately 12.5µS since the clock speed that you specified is 1/8 that of
the default. In order to get the correct pulse width, in seconds, you will have to multiply the value returned
by 8. Those return values that are not scaled to seconds represent a number of periods of the timer
frequency. So, for example, if you change Register.TimerSpeed1 to 2 on an ATmega-based device
running at 14.7MHz, the values returned by InputCapture() represent units of 542nS instead of the
default 67.8nS.
The tables below give the set of valid 16-bit PWM channels, the associated timer, and the corresponding
output pin for each channel. See OpenPWM for the details of setting up a 16-bit PWM output.
16-bit PWM Timers, Channels and Pins for ZX Devices
ZX Device
Timer
Chan.
Pin
Chan.
Pin
Chan.
Pin
ZX-24, ZX-24a, ZX-24p, ZX-24n
Timer1
1
26, D.5
2
27, D.4
ZX-24e, ZX-24ae, ZX-24ne,
ZX-24pe, ZX-24nu, ZX-24pu
Timer1
1
15, D.5
2
16, D.4
|