'{$STAMP BS2} '{$PBASIC 2.5} ' 2008 mlab.taik.fi/paja ' Experiencing with PWM command ' ---[ I/O Definitions ]--- pLED PIN 15 ' ---[ Variables ]--- bDuty VAR BYTE ' ' ---[ Constants ]--- cBS2 CON $100 ' x 1.0, cycle adjustment (for ms) cCycle CON 50 'Required Charge time (Cycle equation) = 5 * Resistance * Capacity 'Charge time = 5 * 10KR(10000R) * 1µF(1/1000000F) = 0.05 seconds = 50ms ' ---[ Initialization ]--- DEBUG CLS, "Illuminating LED with PWM", CR ' ---[ Main Code ]--- Main: DO bDuty = bDuty + 1 ' Pulse-width modulation (PWM) ' PWM Pin, Duty, Cycles ' Pin: Pin number (0-15) ' Duty: Specifies the analog output level (0-5v) ' Cycles: Specifies the duration of the PWM signal PWM pLED, bDuty, cCycle*/cBS2 'PWM Pin(0-15), Duty(0-255), Cycles(0-255)ms 'Average Voltage = (Duty / 255) * 5 volts. LOOP END