User Tools

Site Tools

한국어

cubloc:count:index

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 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.

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.

'
' 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

Go CUBLOC home

cubloc/count/index.txt · Last modified: 2022/12/28 08:43 by COMFILE Technology