====== Count( ) ======
''variable = Count(channel)''
| //variable //| Variable to store results. (No String or Single) |
| //channel //| Counter channel number (0 to 1) |
Return the counted value from the specified counter channel. Please set the
counter's input pins to //input// before use of this command (refer to the
[[:cubloc:index#core_modules|pin/port table]] for the appropriate CUBLOC module). The maximum pulse
frequency is 10KHz.
The CUBLOC’s counter is hardware driven, meaning it runs independently from
the main program. It is able to count reliably in real-time regardless of how
busy the CUBLOC processor is.
The CUBLOC has 2 x 32 bit counter inputs. Counter channel 0 uses the same
resources as PWM0 through PWM2, so you cannot use both at the same
time. However, counter channel 1 can be used while PWM channel 0 is
running. The ''Set Count0 On'' command must be executed before using
counter channel 0. Counter channel 1 requires no additional settings.
For MSB products, the high speed counter pins are already configured as ''Input'', so it is not necessary to add the ''Input xx'' statements.
{{ :cubloc:count:count.png?nolink |}}
Dim R As Integer
Input 15 ' Set port 15 as input. (Counter Channel 1)
R = Count(1) ' Read current counter value.
Set Count0 On ' Activate counter channel 0
' (PWM0,1, and 2 becomes deactivated.)
Input 14 ' Set port 14 as input (Counter Channel 0)
R = Count(0) ' Read current Counter value.
As illustrated below, counter 0 uses the same resources as PWM0 through
PWM2, so please be careful not to use both at the same time.
{{ :cubloc:count:countstruct.png?nolink |}}
'
' Measure frequency from pulse output PWM 0 channel
'
Const Device = CB280
Dim A as Integer
Input 15
Low 5
Freqout 0,2000
Low 0
On Timer(100) Gosub GetFreq
Do
Loop
GetFreq:
A = Count(1)
Debug goxy,10,2
Debug dec5 A
Countreset 1
Reverse 0
Return
[[cubloc:index#system_library:|Go CUBLOC home]]