Positron Compiler Documentation

Counter

Positron16 · Revision 1.1.3.5 · PDF page 151

Assignment Variable = Counter Pin, Period

Count the number of pulses that appear on pin during period, and store the result in variable.

Pin is a Port.Pin constant declaration i.e. PORTA.0. Period may be a constant, variable, or expression. Assignment Variable is a user defined variable or constant.

' Count the pulses that occur on PORTA.0 within a 100ms period
' and displays the results.

  Device = 24FJ64GA002             ' Select the device to compile for
  Declare Xtal = 16

  Declare Hserial_Baud = 9600       ' USART1 Baud rate
  Declare Hrsout1_Pin = PORTB.14    ' Select the pin for TX with USART1

  Dim MyWord as Word               ' Create a word size variable
  Symbol CounterPin = PORTA.0      ' Assign the input pin to PORTA.0

  RPOR7 = 3                         ' Make PPS Pin RP14 U1TX
  Do                                ' Create a loop
     MyWord = Counter CounterPin, 100  ' Variable MyWord now contains the Count
     HrsoutLn Dec MyWord             ' Display the decimal result
  Loop                              ' Do it forever

The resolution of period is in milliseconds (ms). It obtains its scaling from the oscillator declaration, Declare Xtal.

Counter checks the state of the pin in a concise loop, and counts the rising edge of a transition.

See also : PulseIn, Rcin.

View original PDF page 151Open page in PDFOriginal PDF page 151