21 of 307
ZBasic System Library 11 ZX Microcontroller Family For each timer, there exists a built-in variable that indicates when the timer is in use. For example, Register.Timer0Busy is a Boolean value that indicates when Timer0 is in use. Prior to using a timer, the system 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 program may do the same by passing the Register variable as a parameter to the Semaphore() function. I/O Timer Pre-scaler Values Some of the System Library routines that use a timer allow you to modify the frequency used to clock the timer while others use a fixed frequency determined by the requirements of the routine. The routines that do allow frequency modification are divided into two groups, one controlled by the value of Register.TimerSpeed1 and the other controlled by the value of Register.TimerSpeed2. The table below shows the System Library routines that use a timer and, where applicable, the timer speed variable that controls the timer frequency. System Library Routines Using TimerSpeed Values Routine TimerSpeed Value ADCtoCom1() Com1toDAC() CountTransitions() TimerSpeed1¹ FreqOut() Get1Wire() Get1WireByte() Get1WireData() I2CCmd()² TimerSpeed1 I2CGetByte()² TimerSpeed1 I2CPutByte()² TimerSpeed1 InputCapture() TimerSpeed1 InputCaptureEx() TimerSpeed1 OutputCapture() TimerSpeed1 OutputCaptureEx() TimerSpeed1 OpenPWM() RCTime() TimerSpeed2¹ PlaySound() PulseIn() TimerSpeed2¹ PulseOut() TimerSpeed2¹ Put1Wire() Put1WireByte() Put1WireData() PWM() Reset1Wire() ShiftIn() TimerSpeed1 ShiftInEx() TimerSpeed1 ShiftOut() TimerSpeed1 ShiftOutEx() TimerSpeed1 X10Cmd() Notes: 1) The timer frequency is scaled. See below. 2) The timer is used only for channels 1-4. The default value of Register.TimerSpeed1 is 1 and the default value for Register.TimerSpeed2 is 2. The table below shows the correspondence between the allowable values for the TimerSpeed registers and the resulting clock frequency applied to the I/O Timer. The divisor specified is applied to the CPU clock frequency to yield the I/O Timer clock frequency. For compatibility with BasicX (but only for ZX