/ examples / HSC / hsc_counting_mode.py
hsc_counting_mode.py
 1  """
 2  	Example: hsc_counting_mode
 3  
 4  	This example shows how to configure an HSC channel with different counting modes.
 5  
 6      This example works with the P1-02HSC
 7  
 8  	This example will configure channel 1 as a Quadrature 1X counter and channel 2 as
 9      a Quadrature 4X counter. The default mode before configuring is Step Direction.
10      It will then print the position of each channel every second.
11  
12  	 _____  _____
13  	|  P  ||  S  |
14  	|  1  ||  L  |
15  	|  A  ||  O  |
16  	|  M  ||  T  |
17  	|  -  ||     |
18  	|  2  ||  0  |
19  	|  0  ||  1  |
20  	|  0  ||     |
21  	 ¯¯¯¯¯  ¯¯¯¯¯
22  	Written by FACTS Engineering
23  	Copyright (c) 2023 FACTS Engineering, LLC
24  	Licensed under the MIT license.
25  
26  """
27  
28  import time
29  import P1AM
30  
31  base = P1AM.Base()
32  hsc = base[1] # P1-02HSC module in slot 1
33  cnt1 = hsc[1] # Channel 1
34  cnt2 = hsc[2] # Channel 2
35  
36  cnt1.counting_mode = "quadrature_1x"
37  cnt2.counting_mode = "quadrature_4x"
38  
39  hsc.update_settings() # Write settings to module
40  
41  last_time = time.monotonic()
42  while True:
43      if time.monotonic() - last_time > 1:
44          print(f"cnt1 position = {cnt1.position}")
45          print(f"cnt2 position = {cnt2.position}\n")
46          last_time = time.monotonic()
47