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.51. PULSINSyntax :Overview :Operators :Example :Loop:Variable = PULSIN Pin , StateChange the specified pin to input and measure an input pulse.Variable is a user defined variable. This may be a word variable witha range of 1 to 65535, or a byte variable with a range of 1 to 255.Pin is a Port.Pin constant that specifies the I/O pin to use.State is a constant (0 or 1) or name HIGH - LOW that specifies whichedge must occur before beginning the measurement.DIM Var as BYTEVar = PULSIN PORTB.0 , 100 , 1 ’ Measure a pulse on pin 0 of PortB.PRINT @Var , “ ”' Display the readingGOTO Loop' Repeat the process.Notes : PULSIN acts as a fast clock that is triggered by a change in state (0or 1) on the specified pin. When the state on the pin changes to thestate specified, the clock starts counting. When the state on the pinchanges again, the clock stops. If the state of the pin doesn’t change(even if it is already in the state specified in the PULSIN instruction),the clock won’t trigger. PULSIN waits a maximum of 0.65535 secondsfor a trigger, then returns with 0 in variable.The variable can be either a WORD or a BYTE. If the variable is aword, the value returned by PULSIN can range from 1 to 65535 units.The units are dependant on the frequency of the crystal used. If a4MHz crys tal is used, then each unit is 10us, while a 20MHz crystalproduces a unit length of 2us.If the variable is a byte and the crystal is 4MHz, the value returnedcan range from 1 to 255 units of 10µs. Internally, PULSIN alwaysuses a 16-bit timer. When your program specifies a byte, PULSINstores the lower 8 bits of the internal counter into it. Pulse widthslonger than 2550µs will give false, low readings with a byte variable.For example, a 2560µs pulse returns a reading of 256 with a wordvariable and 0 with a byte variable.See also :1COUNTER, PULSOUT101Copyright Crownhill 2001

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

Saved successfully!

Ooh no, something went wrong!