184 of 318
ZBasic System Library 174 ZX Microcontroller Family OpenPWM Type Subroutine Invocation OpenPWM(channel, frequency, mode) OpenPWM(channel, frequency, mode, stat) Parameter Method Type Description channel ByVal Byte The channel to use for PWM generation. frequency ByVal Single The desired PWM frequency. mode ByVal Byte The desired PWM mode (see discussion below). stat ByRef Boolean The variable to receive the status code. Discussion This subroutine prepares a PWM channel for generating a pulse width modulated (PWM) signal. PWM generation is performed using one of the CPU’s 16-bit timers, the number of which varies depending on the ZX model. The table below indicates the available channels and the corresponding timer used. See the description of PWM() for additional details on the PWM channels. Supported 16-bit PWM Channels ZX Models Timer Channels ZX-24, ZX-24a, ZX-24p, ZX-24n, ZX-40, ZX-40a, ZX-40p, ZX-40n, ZX-44, ZX-44a, ZX-44p, ZX-44n, ZX-328n, ZX-328l, ZX-32n, ZX-32l, ZX-24e, ZX-24ae, ZX-24ne, ZX-24pe, ZX-24nu, ZX-24pu, ZX-328nu Timer1 1, 2 ZX-24r, ZX-24s, ZX-40r, ZX-40s, ZX-44r, ZX-44s Timer1 Timer3 1, 2 3, 4 ZX-1281, ZX-1281n, ZX-128e, ZX-128ne, ZX-1281e, ZX-1281ne Timer1 Timer3 1, 2, 3 4, 5, 6 ZX-1280, ZX-1280n Timer1 Timer3 Timer4 Timer5 1, 2, 3 4, 5, 6 7, 8, 9 10, 11, 12 ZX-24x, ZX-32a4 TimerD0 TimerD1 TimerC0 TimerE0 1, 2 3, 4 5, 6, 7, 8 9, 10, 11, 12 ZX-128a1 TimerD0 TimerD1 TimerC0 TimerE0 TimerE1 TimerF0 TimerF1 1, 2 3, 4 5, 6, 7, 8 9, 10, 11, 12 13, 14 15, 16, 17, 18 19, 20 The frequency parameter specifies the PWM base frequency in Hertz. Since the same frequency and generation mode will be used for all PWM channels based on the same timer, it is only necessary to call OpenPWM() once to prepare the timer for all of the PWM channels that are based on a given timer. The mode parameter specifies the PWM generation mode. Two modes are supported: Fast PWM mode and Phase/Frequency Correct mode. The constants zxFastPWM and zxCorrectPWM, having the values 0 and 1 respectively, may be used to specify the mode. The Fast PWM mode has a maximum frequency of one-half of the CPU clock frequency and is intended for fixed-frequency applications. The Phase/Frequency Correct PWM mode has a maximum frequency of one-quarter of the CPU clock