From 02ab024a4011ea113115444da592addd17fffa45 Mon Sep 17 00:00:00 2001 From: Avi Levkovich Date: Thu, 2 May 2019 12:05:35 +0300 Subject: Add Read_Screw_Encoder() --- Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c | 45 ++++++++++++++++++++++- Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.h | 12 ++++++ 2 files changed, 56 insertions(+), 1 deletion(-) (limited to 'Software/Embedded_SW') diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c index aff2e7cd1..41a28b4c1 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.c @@ -9,7 +9,7 @@ #include "FPGA_Rename.h" #include "FPGA_COMM.h" -#include +#include "FPGA.h" #include "driverlib/sysctl.h" //for SysCtlDelay #include @@ -426,3 +426,46 @@ uint32_t Read_Speed_Sensor_TypeII()//must be delay between Set_Speed_Sensor_Type return Speed_Hz; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +typedef union +{ + struct + { + uint16_t M:10;//0..9 + uint16_t Direction:1;//10 + uint8_t Spare:5;//11-15 + }Bits; + uint32_t Word; +}SCREW_ENC_M; + +typedef union +{ + struct + { + uint16_t M; + uint16_t L; + }Word; + uint32_t Position; +}SCREW_POS; + + + + +SCREW_ENC Screw_RotEnc; + +void Read_Screw_Encoder() +{ + SCREW_ENC_M Screw_Enc_M; + SCREW_POS Screw_Pos; + + Screw_Pos.Word.L = F1_SCREW_ROTENC_L; // Must First Read the register of Lsw. + Screw_Enc_M.Word = F1_SCREW_ROTENC_M; + + Screw_Pos.Word.M = Screw_Enc_M.Bits.M; + + + Screw_RotEnc.Position = Screw_Pos.Position; + Screw_RotEnc.Direction = Screw_Enc_M.Bits.Direction; + Screw_RotEnc.Index = F1_SCREW_ROTENC_I; +} diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.h b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.h index 0e5cdb66a..8564c2266 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.h +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA.h @@ -19,4 +19,16 @@ uint32_t Read_Dryer_Fan_Tacho(); void Set_Speed_Sensor_TypeII_Registers(uint32_t Counter, uint32_t Prescaler); uint32_t Read_Speed_Sensor_TypeII(); +void Read_Screw_Encoder(); + +typedef struct +{ + uint32_t Position; + bool Direction; + uint16_t Index; // This counter counts the amount of index pulses that have occurred since the last time the register was read. + +}SCREW_ENC; + +extern SCREW_ENC Screw_RotEnc;; + #endif //FPGA_H -- cgit v1.3.1