11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PICBASIC</strong> <strong>PLUS</strong> Compiler5.53. PWMSyntax :Overview :Operators :Notes :PWM Pin , Duty , CyclesOutput pulse-width-modulation on a pin, then return the pin to inputstate.Pin is a Port.Pin constant that specifies the I/O pin to use.Duty is a variable, constant (0–255), or expression, which specifiesthe analogue level desired (0–5 volts).Cycles is a variable or constant (0–255) which specifies the numberof cycles to output. Larger capacitors require multiple cycles to fullycharge. Cycle time is dependant on Xtal frequency. If a 4MHz crystalis used, then cycle takes approx 5 ms. If a 20MHz crystal is used,then cycle takes approx 1 ms.PWM can be used to generate analogue voltages (0-5V) through apin connected to a resistor and capacitor to ground; the resistorcapacitorjunction is the analogue output (see circuit). Since the capacitorgradually discharges, PWM should be executed periodically torefresh the analogue voltage.PWM emits a burst of 1s and 0s whose ratiois proportional to the duty value you specify. Ifduty is 0, then the pin is continuously low (0);if duty is 255, then the pin is continuouslyhigh. For values in between, the proportion isduty/255. For example, if duty is 100, the ratioof 1s to 0s is 100/255 = 0.392, approximately39 percent.ToI/O Pin10uF10kAnalogueVoltageOutputWhen such a burst is used to charge a capacitor arranged, the voltageacross the capacitor is equal to:-(duty/ 255) * 5.So if duty is 100, the capacitor voltage is(100/255) * 5 = 1.96 volts.This voltage will drop as the capacitor discharges through whateverload it is driving. The rate of discharge is proportional to the currentdrawn by the load; more current = faster discharge. You can reducethis effect in software by refreshing the capacitor’s charge with frequentuse of the PWM command. You can also buffer the output usingan op-amp to greatly reduce the need for frequent PWM cycles.103Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!