winIDEA SDK
Loading...
Searching...
No Matches
fnet_counter.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
"""
This example shows FNet Counter controller initialization and usage.
(c) iSYSTEM Labs, 2022
"""
import isystem.connect as ic
winidea_id = ''
try:
# connect to last winIDEA
connMgr = ic.ConnectionMgr()
connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
# initialize FNet Counter Controller
SessionCtrl = ic.CSessionCtrl(connMgr)
FNetCtrl = ic.CFNetCtrl(connMgr)
CounterCtrl = FNetCtrl.counter('Root.COUNTER1')
SessionCtrl.end() #end first for cfg to take effect
SessionCtrl.begin_prepare()
# use FNetTrigger 5 in the example
FTrigQ = 5
FTrigGen = 6
optCounterOp = CounterCtrl.op()
# qualifier - starts on FTrig, not enabled from start
CounterCtrl.op_qualifier_enable(FTrigQ)
CounterCtrl.op_qualifier_enable_on_start(False)
# configure channel 1
optChannel = optCounterOp.opt_channel(nChannel = 1)
#count every 10us, or TC4
optChannel.set_count_on(bCount = True, nPeriod_us = 10, nFEvent = 4)
# no trigger generation on increment
optChannel.set_on_increment(nFTrig = 0)
# active from start, restart on TC5, suspend on TC6, resume on TC7
optChannel.set_active(bStart = True, nFTrigRestart = 5, nFTrigSuspend = 6, nFTrigResume = 7)
# counter has a limit of 1000, generates TC8 when reached, does not auto-restart
optChannel.set_limit(bLimit = True, nLimit = 1000, nFTrig = 8, bRestart = False)
# record changes
optChannel.set_record(bOnChange = True)
# apply new operation settings and restart operation
FNetCtrl.op_apply()
nCount = CounterCtrl.ctrl_get_FTrig_count(FTrigQ)
# reset count on a specific FTrig counter
CounterCtrl.ctrl_reset_FTrig_count(nFTrig = 1)
# get the value from the specific channel counter
# reset count on a specific channel
CounterCtrl.ctrl_reset (nChannel = 1)
CounterCtrl.ctrl_suspend(nChannel = 1)
CounterCtrl.ctrl_resume (nChannel = 1)
Status = CounterCtrl.ctrl_get_status(nChannel = 1)
print(f"count: {Status.m_nCount}, active: {Status.m_bActive}")
except Exception as ex:
print(ex)