24 of 318
ZBasic System Library 14 ZX Microcontroller Family On ATmega-based devices, 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. 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 (ATmega) and TimerC1 (ATxmega), respectively, are 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.