![]() ZBasic System Library
12
ZBasic Microcontrollers
TimerE0
TimerE0
TimerE0
xmega64a3, xmega128a3, xmega256a3,
xmega256a3b
TimerC1
TimerE1 TimerD1
-
TimerC0
TimerD0
TimerD1
TimerE0
TimerE1
TimerF0
TimerC0 TimerC0
TimerD0 TimerD0
TimerD1 TimerD1
TimerE0
TimerE1
TimerF0
TimerE0
TimerE1
TimerF0
xmega64d3, xmega128d3, xmega192d3,
xmega256d3
TimerC1
TimerF0 TimerD0
-
TimerC0
TimerD0
TimerE0
TimerF0
TimerC0 TimerC0
TimerD0 TimerD0
TimerE0
TimerF0
TimerE0
TimerF0
xmega64a1, xmega128a1
TimerC1
TimerF1 TimerD1
-
TimerC0
TimerD0
TimerD1
TimerE0
TimerE1
TimerF0
TimerF1
TimerC0 TimerC0
TimerD0 TimerD0
TimerD1 TimerD1
TimerE0
TimerE1
TimerF0
TimerF1
TimerE0
TimerE1
TimerF0
TimerF1
When used, the RTC Timer is configured to generate an interrupt that is used to update the RTC and to
trigger task switching. Because its role is so central, the RTC Timer (if enabled) cannot be used for any
other purpose. The I/O Timer is used by several I/O related routines as explained in more detail below.
The Serial Timer is used to generate interrupts to implement the timing required for serial channels Com3
to Com6. If none of the channels 3-6 are open, the Serial Port Timer can be used for other purposes in
your program. Timers are also used for some specialized I/O functions as indicated in the table above.
On ATtiny and ATmega targets, the Serial timer is also used for 8-bit PWM generation. Consequently,
use of 8-bit PWM and use of Com3 to Com6 are mutually exclusive. On some target devices, the same
timer is indicated for both the RTC and the Serial/8-bit PWM functions. For these devices, the application
can employ the RTC or the Serial/8-bit PWM functions but not both.
For each timer, there exists a built-in variable that indicates when the timer is in use. For example,
Register.Timer0Busy and Register.TimerC1Busy are Boolean values that indicate when Timer0
(ATtiny, ATmega) and TimerC1 (ATxmega), respectively, are in use. Prior to using a timer, the ZBasic
System Library code checks the value of this variable to see if it is already being used. If it is not in use,
the system sets the flag to True and then proceeds to use the timer. When it is finished using the timer,
the system sets the busy flag to False.
Your appplication may do the same by passing the Register variable as a parameter to the Semaphore()
function in order to get exclusive access to the timer. Of course, you must set timer busy flag to False
when your code is finished with the timer to indicate that the timer is no longer in use. Likewise, you may
want to acquire a semaphore on a timer busy flag for the I/O Timer before calling a System Library routine
that uses I/O Timer. If you succeed in setting the semaphore youll know that the timer is not already in
use. An example of code for this purpose (for ZBasic devices that use Timer1 for the I/O Timer) is shown
below.
' wait until the timer is available
Do While (Not Semaphore(Register.Timer1Busy))
Call Sleep(0.5)
Loop
' use the timer
Call LockTask()
Register.Timer1Busy = False
Call ShiftOut(12, 13, 8, &H55)
Call UnlockTask()
|