Counters
Cnt_Sync_Latch
ADwin
128
ADwin-Gold II
, Manual February 2013
Example
Rem Please select the appropriate include for ADbasic /
TiCoBasic
#Include
ADwinGoldII.inc
'for ADbasic
Rem #Include GoldIITiCo.inc 'for TiCoBasic
#Define
frequency
FPar_1
Dim
time
As
Long
Dim
edges
As
Long
Dim
oldpw
As
Long
Dim
oldcnt
As
Long
Dim
newpw
As
Long
Dim
newcnt
As
Long
Dim
pw_cnt
As
Long
Init:
Processdelay
=
3000000
'100Hz
Cnt_Enable
(
0001b
)
Cnt_Mode
(
1
,
0b
)
'mode: clock/dir
Cnt_Clear
(
0Fh
)
Cnt_Enable
(
0F0Fh
)
'enable standard and PWM
'counters
Cnt_PW_Latch
(
0Fh
)
'copy PWM counter values
oldpw
=
0
oldcnt
=
0
frequency
=
0
Event:
REM latch values of counter 1 (both standard and PWM)
Cnt_Sync_Latch
(
0001b
)
newcnt
=
Cnt_Read_Latch
(
1
)
'value of clock/dir counter
edges
=
(
newcnt
-
oldcnt
)
'number of edges between events
If
(
edges
<>
0
)
Then
pw_cnt
=
Cnt_Read_Int_Register
(
1
,
8
)
'positive edges latch 1
time
=
pw_cnt
-
oldpw
'calculate timebase
frequency
=
edges
*
100000000
/
time
'frequency
'(100000000=timer frequency)
oldcnt
=
newcnt
'store VR-counter value
oldpw
=
newpw
'store PW-counter value
EndIf