Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Read every 0.1 seconds, but the counter is not fixed

Dear all

 

I use python write an ci counter read code

my input frequency is fixed at 20Khz and i use while loop to get counter every 0.1 sec

but the conter is not fixed number

There will be a two-digit jump 

for example 1421 →1421 →1423 →1421 →1428 →1425 →1426 →1421 ........

how can i get fix counter ?

 

CT = 0
while (tCT >0):
tCT = NI.read() //NI is function task.ci_channels.add_ci_count_edges_chan('Dev1/ctr0').ci_count_edges_term = 'PFI0'
print(str(thCT-CT))
CT = tCT
time.sleep(0.1)

 

thanks all

 

 

 

 

0 Kudos
Message 1 of 2
(1,177 Views)

I think it's not a problem with the counter but with the execution of the Python program, your python program does not execute "exactly" at 100ms intervals.

 

Software execution times are not guaranteed by OS and hence the difference is counter readback values are the variation in OS execution time of your loop.

 

Edit - counters being an HW are the most precise you can get given the reference clock is the best you can get

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 2
(1,168 Views)