205 of 286
191 PWM Type Subroutine Invocation PWM(channel, dutyCycle) Parameter Method Type Description channel ByVal Byte The channel to use for PWM generation. dutyCycle ByVal Single or integral The desired duty cycle. Discussion This subroutine begins or modifies the generation of a PWM signal on the specified channel. The channel must have been previously prepared for PWM generation by calling OpenPWM(). PWM generation is performed using one of the CPU’s 16-bit timers, the number of which varies depending on the ZX model. For ZX models based on the mega32, mega644 and mega644P CPUs, there is one 16-bit timer that jointly supports two PWM channels, numbered 1 and 2. For ZX models based on the mega128 and mega1281 CPUs, there are two 16-bit timers and each jointly supports three PWM channels, numbered 1 through 3 and 4 through 6 respectively. For ZX models based on the mega1280 CPU, there are four 16-bit timers and each jointly supports three PWM channels. The table below indicates the output pin for each PWM supported channel. Output Pins for PWM Channel Numbers ZX Models 1 2 3 4 5 6 ZX-24, ZX-24a, ZX-24p, ZX-24n 26, D.5 27, D.4 - - - - ZX-40, ZX-40a, ZX-40p, ZX-40n 19, D.5 18, D.4 - - - - ZX-44, ZX-44a, ZX-44p, ZX-44n 14, D.5 13, D.4 - - - - ZX-24e, ZX-24ae, ZX-24pe, ZX-24ne 15, D.5 16, D.4 - - - - ZX-1281, ZX-1281n 15, B.5 16, B.6 17, B.7 5, E.3 6, E.4 7, E.5 ZX-1280, ZX-1280n 24, B.5 25, B.6 26, B.7 5, E.3 6, E.4 7, E.5 ZX-128e, ZX-128ne, ZX-1281e, ZX-1281ne 23, B.5 22, B.6 21, B.7 17, E.3 16, E.4 15, E.5 ZX Models 7 8 9 10 11 12 ZX-1280, ZX-1280n 38, L.3 39, L.4 40, L.5 16, H.4 17, H.5 18, H.6 The dutyCycle parameter specifies the desired duty cycle of the generated signal, expressing the percentage of time that the PWM signal will be at the logic 1 state. If the supplied parameter is of type Single, the value is in percent with a resolution of 0.01%. If the supplied parameter is integral, the units are percent, i.e., the value 100 means 100%. Specifying a Single value that is negative or any value greater than 100 will have an undefined effect. If this subroutine is called without a preceding call to OpenPWM() to prepare the timer, the call will have no effect. This subroutine may be called multiple times to effect changes to the PWM signal’s duty cycle while the signal is being generated. The change in duty cycle is synchronized so that it takes effect at the beginning of the next PWM pulse. Example Call OpenPWM(2, 50.0, zxFastPWM) ' prepare for 50Hz Fast PWM using channel 2 Call PWM(2, 7.5) ' generate PWM with 7.5% duty cycle (1.5mS) Call Delay(1.0) Call PWM(2, 6.25) ' generate PWM with 6.25% duty cycle (1.25mS)