winIDEA SDK
fnet_counter.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5"""
6This example shows FNet Counter controller initialization and usage.
7
8(c) iSYSTEM Labs, 2022
9"""
10import isystem.connect as ic
11
12winidea_id = ''
13
14
15try:
16 # connect to last winIDEA
17 connMgr = ic.ConnectionMgr()
18 connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
19
20 # initialize FNet Counter Controller
21 SessionCtrl = ic.CSessionCtrl(connMgr)
22 FNetCtrl = ic.CFNetCtrl(connMgr)
23 CounterCtrl = FNetCtrl.counter('Root.COUNTER1')
24
25
26
27 SessionCtrl.end() #end first for cfg to take effect
28 SessionCtrl.begin_prepare()
29
30
31
32 # use FNetTrigger 5 in the example
33 FTrigQ = 5
34 FTrigGen = 6
35
36 optCounterOp = CounterCtrl.op()
37 # qualifier - starts on FTrig, not enabled from start
38 CounterCtrl.op_qualifier_enable(FTrigQ)
39 CounterCtrl.op_qualifier_enable_on_start(False)
40
41 # configure channel 1
42 optChannel = optCounterOp.opt_channel(nChannel = 1)
43 #count every 10us, or TC4
44 optChannel.set_count_on(bCount = True, nPeriod_us = 10, nFEvent = 4)
45 # no trigger generation on increment
46 optChannel.set_on_increment(nFTrig = 0)
47 # active from start, restart on TC5, suspend on TC6, resume on TC7
48 optChannel.set_active(bStart = True, nFTrigRestart = 5, nFTrigSuspend = 6, nFTrigResume = 7)
49 # counter has a limit of 1000, generates TC8 when reached, does not auto-restart
50 optChannel.set_limit(bLimit = True, nLimit = 1000, nFTrig = 8, bRestart = False)
51 # record changes
52 optChannel.set_record(bOnChange = True)
53
54 # apply new operation settings and restart operation
55 FNetCtrl.op_apply()
56
57
59 nCount = CounterCtrl.ctrl_get_FTrig_count(FTrigQ)
60 # reset count on a specific FTrig counter
61 CounterCtrl.ctrl_reset_FTrig_count(nFTrig = 1)
62 # reset count on a number of FTrig counters
63 # CounterCtrl.ctrl_reset_FTrig_count(vnChannels = {1, 2}) #maybe later if necessary
64
65 # get the value from the specific channel counter
66 # reset count on a specific channel
67 CounterCtrl.ctrl_reset (nChannel = 1)
68 CounterCtrl.ctrl_suspend(nChannel = 1)
69 CounterCtrl.ctrl_resume (nChannel = 1)
70 #CounterCtrl.ctrl_reset ({vnChannels = {1, 2}}) #maybe later
71 #CounterCtrl.ctrl_suspend({vnChannels = {1, 2}}) #maybe later
72 #CounterCtrl.ctrl_resume ({vnChannels = {1, 2}}) #maybe later
73 Status = CounterCtrl.ctrl_get_status(nChannel = 1)
74 print(f"count: {Status.m_nCount}, active: {Status.m_bActive}")
75
76except Exception as ex:
77 print(ex)