aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/stubs/Scripts/NewSpeedSensor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Stubs Collection/stubs/Scripts/NewSpeedSensor.cs')
-rw-r--r--Software/Stubs Collection/stubs/Scripts/NewSpeedSensor.cs45
1 files changed, 45 insertions, 0 deletions
diff --git a/Software/Stubs Collection/stubs/Scripts/NewSpeedSensor.cs b/Software/Stubs Collection/stubs/Scripts/NewSpeedSensor.cs
new file mode 100644
index 000000000..02f8384bc
--- /dev/null
+++ b/Software/Stubs Collection/stubs/Scripts/NewSpeedSensor.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Text;
+using System.Linq;
+using System.Drawing;
+using System.Diagnostics;
+using System.Windows.Forms;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+using Tango.PMR.Stubs;
+using Tango.Stubs;
+
+const UInt32 Freq = 29166667;//FPGA Freq
+
+const UInt32 F1_Tacho_reg9 = 0x1E2;//Time of Tacho / No of clk in one cycle
+const UInt32 F1_gpo_cnt_A_reg = 0x3B0;// how many pulses to count
+//const Int32 F1_Prescaler1_reg5 = 0x3E8; //OLD FPGA 05.022019
+const UInt32 F1_Prescaler1_reg6 = 0x3EA; //New FPGA
+
+const UInt32 CNT = 4;//bigger number for resolution
+const UInt32 Presc = 2;//Lower number for resolution
+UInt32 temp;
+
+public void OnExecute(StubManager stubManager)
+{
+ stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,0x60000000 + F1_Prescaler1_reg6, Presc);//for new FPGA use reg6!!
+ var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000000 + F1_Prescaler1_reg6);//for new FPGA use reg6!!!
+ response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000000 + F1_gpo_cnt_A_reg);
+ stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,0x60000000 + F1_gpo_cnt_A_reg, CNT);
+ response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000000 + F1_gpo_cnt_A_reg);
+
+ for(int i =0;i<1000;i++)
+ {
+ response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000000 + F1_Tacho_reg9);
+
+
+ temp = (Freq * CNT) /((UInt32)response.Value * Presc);
+
+ stubManager.Write(temp);
+ stubManager.Write(" Hz, ");
+ stubManager.WriteHex((response.Value & 0xffff),4);
+ stubManager.WriteLine("");
+ Thread.Sleep(100); //Sleep for 100 milli.
+ }
+} \ No newline at end of file