Skip to content

Commit

Permalink
Squashed 'motorcontrol' changes from 3036eec..fb2f08e (#821)
Browse files Browse the repository at this point in the history
fb2f08e Merge pull request Xilinx#310 from yuxiangz/encode_mode
572425a update results
8272b1f Merge pull request Xilinx#309 from yuxiangz/encode_mode
34a73a5 update results
3df41ed Merge pull request Xilinx#308 from yuxiangz/encode_mode
f546bf9 update qei
4ca3e0c update encode type for doc
e350a16 Merge pull request Xilinx#306 from congt/next
ced7186 [tutorial]correct git checkout next position
15c8bbf [tutorial] add git checkout next
b66a84e Merge pull request Xilinx#305 from congt/next
764b078 [foc-sensorless]align with foc, testbench refine
9cefa00 Merge pull request Xilinx#304 from yunleiz/next
4578eab [doc] sensor foc refine
70c1748 Merge branch 'next' of gitenterprise.xilinx.com:FaaSApps/xf_motorcontrol into next
072b954 [doc]refine foc
cee5e77 Merge pull request Xilinx#303 from congt/next
620e10e [tutorial]fix path
ba2c022 Merge branch 'next' of https://gitenterprise.xilinx.com/congt/xf_motorcontrol into next
b6ed77c [foc-sensorless]fix bug about axis interfaces
5288f36 Merge branch 'FaaSApps:next' into next
62a4976 [tutorial]rm useless dirctory
15179fc Merge pull request Xilinx#302 from congt/next
42a5002 Merge pull request Xilinx#301 from yunleiz/next
64c22a6 Merge pull request Xilinx#300 from yuxiangz/explanation
22ed83f [tutorial]first version
7d5ad26 [sensor] refine sin/cos table from 500 steps to 1000
35ce325 clang formate for host
179dcd5 fix the dir explanation
9749f1c Refined the B_leading_A for host and added an enum Direction_QEI
78979a9 Merge pull request Xilinx#299 from yuxiangz/leading_mode
f7b3a73 update leading mode for host
8e42089 add default setting of leading mode
8b603f7 Merge pull request Xilinx#297 from congt/next
f312213 [foc-sensorless]code refine
37c14e1 Merge branch 'FaaSApps:next' into next
f7cd92d [foc-sensorless]add missing foc_sensorless.hpp and smo.hpp files
b58a312 [foc-sensorless]three interfaces of Vabc for smo added
01ae670 [foc-sensorless]coding style
54aa881 Merge branch 'next' of https://gitenterprise.xilinx.com/congt/xf_motorcontrol into next
6a846e2 [foc-sensorless]fix the axilite address mismatch
590f7c3 Merge pull request Xilinx#296 from yunleiz/next
2311560 [sensor-foc] add both directions simulation test

Co-authored-by: sdausr <[email protected]>
  • Loading branch information
2 people authored and GitHub Enterprise committed Mar 29, 2023
1 parent d5401d8 commit fcd15fe
Show file tree
Hide file tree
Showing 18 changed files with 1,482 additions and 525 deletions.
2 changes: 1 addition & 1 deletion motorcontrol/L1/include/hw/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define COMM_MACRO_PPR (2)

// Number of sin-cos table for 2*pi.
#define COMM_MACRO_TLB_LENTH (500)
#define COMM_MACRO_TLB_LENTH (1000)
//
#define COMM_CLOCK_FREQ (100000000)

Expand Down
295 changes: 146 additions & 149 deletions motorcontrol/L1/include/hw/foc.hpp

Large diffs are not rendered by default.

58 changes: 45 additions & 13 deletions motorcontrol/L1/include/hw/foc_sensorless.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ void hls_foc_strm_ap_fixed_sensorless(
hls::stream<T_IO>& Ia,
hls::stream<T_IO>& Ib,
hls::stream<T_IO>& Ic,
hls::stream<T_IO>& Va_smo,
hls::stream<T_IO>& Vb_smo,
hls::stream<T_IO>& Vc_smo,
hls::stream<T_RPM_THETA_FOC>& FOC_RPM_THETA_m, // RPM & Theta_m
// Output
hls::stream<T_IO>& Va_cmd,
Expand Down Expand Up @@ -140,27 +143,38 @@ void hls_foc_strm_ap_fixed_sensorless(
const T_IO RPM_factor = 60.0 / 2 / 3.1415926535;
T_IO speed_to_RPM = RPM_factor / (T_IO)ppr_args;
T_IO RPM_to_speed = (T_IO)ppr_args / RPM_factor;
bool Filebased_flag = (control_mode_args & 0x40000000) != 0;
LOOP_FOC_STRM:
for (long i = 0; i < trip_cnt; i++) {
//#pragma HLS pipeline II = 1
#pragma HLS PIPELINE off
control_mode_args &= 0xBFFFFFFF;
bool Filebased_flag = (control_mode_args & 0x40000000) != 0;
int control_mode = control_mode_args & 0x0000FFFF;
static int FOC_RPM_THETA_m_in; // = FOC_RPM_THETA_m.read();
static T_IO Ia_in;
static T_IO Ib_in;
static T_IO Ic_in;
static T_IO Va_in;
static T_IO Vb_in;
static T_IO Vc_in;
if (Filebased_flag) {
if (!Ia.empty()) {
Ia_in = Ia.read();
Ib_in = Ib.read();
Ic_in = Ic.read();

Va_in = Va_smo.read();
Vb_in = Vb_smo.read();
Vc_in = Vc_smo.read();
}
} else {
while (!Ia.empty()) {
while (!Ia.empty()) { // hardware on board
Ia_in = Ia.read();
Ib_in = Ib.read();
Ic_in = Ic.read();

Va_in = Va_smo.read();
Vb_in = Vb_smo.read();
Vc_in = Vc_smo.read();
}
}
if (!FOC_RPM_THETA_m.empty()) FOC_RPM_THETA_m_in = FOC_RPM_THETA_m.read();
Expand All @@ -177,11 +191,11 @@ void hls_foc_strm_ap_fixed_sensorless(

// details::foc_core_ap_fixed<VALUE_CPR, T_IO, MAX_IO , W, I>(
foc_core_ap_fixed_sensorless<VALUE_CPR, T_IO, MAX_IO, W, I>(
Ia_in, Ib_in, Ic_in, RPM_in, Angle_in, Va_out, Vb_out, Vc_out, tab_map_factor, cpr_div_ppr, speed_to_RPM,
RPM_to_speed, control_mode_args, control_fixperiod_args, flux_sp_args, flux_kp_args, flux_ki_args,
flux_kd_args, torque_sp_args, torque_kp_args, torque_ki_args, torque_kd_args, speed_sp_args, speed_kp_args,
speed_ki_args, speed_kd_args, angle_sh_args, vd_args, vq_args, trigger_args, control2_args, fw_kp_args,
fw_ki_args,
Ia_in, Ib_in, Ic_in, Va_in, Vb_in, Vc_in, RPM_in, Angle_in, Va_out, Vb_out, Vc_out, tab_map_factor,
cpr_div_ppr, speed_to_RPM, RPM_to_speed, control_mode, control_fixperiod_args, flux_sp_args, flux_kp_args,
flux_ki_args, flux_kd_args, torque_sp_args, torque_kp_args, torque_ki_args, torque_kd_args, speed_sp_args,
speed_kp_args, speed_ki_args, speed_kd_args, angle_sh_args, vd_args, vq_args, trigger_args, control2_args,
fw_kp_args, fw_ki_args,
//
id_stts, flux_acc_stts, flux_err_stts, flux_out_stts, iq_stts, torque_acc_stts, torque_err_stts,
torque_out_stts, speed_stts, speed_acc_stts, speed_err_stts, speed_out_stts, angle_stts, Ialpha_stts,
Expand Down Expand Up @@ -211,6 +225,9 @@ void hls_foc_strm_int_sensorless(
hls::stream<int>& Ia,
hls::stream<int>& Ib,
hls::stream<int>& Ic,
hls::stream<int>& Va_smo,
hls::stream<int>& Vb_smo,
hls::stream<int>& Vc_smo,
hls::stream<T_RPM_THETA_FOC>& FOC_RPM_THETA_m, // RPM & Theta_m
// Output
hls::stream<int>& Va_cmd,
Expand Down Expand Up @@ -270,19 +287,34 @@ void hls_foc_strm_int_sensorless(
static int Ia_in0;
static int Ib_in0;
static int Ic_in0;
static int Va_in0;
static int Vb_in0;
static int Vc_in0;
if (!Ia.empty()) {
Ia_in0 = Ia.read();
Ib_in0 = Ib.read();
Ic_in0 = Ic.read();

Va_in0 = Va_smo.read();
Vb_in0 = Vb_smo.read();
Vc_in0 = Vc_smo.read();
}
t_glb_q15q16 Ia_in;
t_glb_q15q16 Ib_in;
t_glb_q15q16 Ic_in;

t_glb_q15q16 Va_in;
t_glb_q15q16 Vb_in;
t_glb_q15q16 Vc_in;

Ia_in(31, 0) = Ia_in0;
Ib_in(31, 0) = Ib_in0;
Ic_in(31, 0) = Ic_in0;

Va_in(31, 0) = Va_in0;
Vb_in(31, 0) = Vb_in0;
Vc_in(31, 0) = Vc_in0;

if (!FOC_RPM_THETA_m.empty()) FOC_RPM_THETA_m_in = FOC_RPM_THETA_m.read();

short RPM_in = (FOC_RPM_THETA_m_in & 0x0000FFFF);
Expand All @@ -297,11 +329,11 @@ void hls_foc_strm_int_sensorless(
int control2_args = 0;

foc_core_ap_fixed_sensorless<VALUE_CPR, T_M, MAX_IO, W, I>(
(T_M)Ia_in, (T_M)Ib_in, (T_M)Ic_in, RPM_in, Angle_in, Va_out, Vb_out, Vc_out, tab_map_factor, cpr_div_ppr,
(T_M)speed_to_RPM, (T_M)RPM_to_speed, control_mode_args, control_fixperiod_args, flux_sp_args, flux_kp_args,
flux_ki_args, flux_kd_args, torque_sp_args, torque_kp_args, torque_ki_args, torque_kd_args, speed_sp_args,
speed_kp_args, speed_ki_args, speed_kd_args, angle_sh_args, vd_args, vq_args, trigger_args, control2_args,
fw_kp_args, fw_ki_args,
(T_M)Ia_in, (T_M)Ib_in, (T_M)Ic_in, (T_M)Va_in, (T_M)Vb_in, (T_M)Vc_in, RPM_in, Angle_in, Va_out, Vb_out,
Vc_out, tab_map_factor, cpr_div_ppr, (T_M)speed_to_RPM, (T_M)RPM_to_speed, control_mode_args,
control_fixperiod_args, flux_sp_args, flux_kp_args, flux_ki_args, flux_kd_args, torque_sp_args,
torque_kp_args, torque_ki_args, torque_kd_args, speed_sp_args, speed_kp_args, speed_ki_args, speed_kd_args,
angle_sh_args, vd_args, vq_args, trigger_args, control2_args, fw_kp_args, fw_ki_args,
//
id_stts, flux_acc_stts, flux_err_stts, flux_out_stts, iq_stts, torque_acc_stts, torque_err_stts,
torque_out_stts, speed_stts, speed_acc_stts, speed_err_stts, speed_out_stts, angle_stts, Ialpha_stts,
Expand Down
10 changes: 5 additions & 5 deletions motorcontrol/L1/include/hw/qei.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
// Argument
//--------------------------------------------------------------------------

enum Encoding_Mode { A_Leading_B = 0, B_Leading_A };

enum Encoding_Mode { B_Leading_A = 0, A_Leading_B };
enum Dirction_QEI { clockwise_n = 0, clockwise_p };
struct AxiParameters_QEI { //
int qei_args_cpr;
int qei_args_ctrl;
Expand Down Expand Up @@ -243,9 +243,8 @@ static bool isRaising(int idx, QEI_EdgeInfo edges_cur) {
* between the two pulses.
* @param pre The previous status of pulse
* @param cur The current status of pulse
* @param mode The mode represents encoding mode, A leading B is represented by 0 and B leading A is represented by 1.
* @param dir The direction of current pulse, clockwise is represented by 1 and counterclockwise is represented by 0 in
* Channel A leading Channel B. Another mode is the oppsite.
* @param mode The mode represents encoding mode, B leading A is represented by 0 and A leading B is represented by 1.
* @param dir The direction of current pulse, clockwise is represented by 1 and counterclockwise is represented by 0.
* @param ii_cycles The number of cycles between previous pulse and current pulse
*/
static void processABedges(QEI_EdgeInfo pre, QEI_EdgeInfo cur, ap_uint<1>& mode, bool& dir, unsigned int& ii_cycles) {
Expand Down Expand Up @@ -329,6 +328,7 @@ void calcCounter(hls::stream<QEI_EdgeInfo>& strm_cntEdge,
bool dir = true; // clockwise
ap_uint<32> ctrl = axi_qei_ctrl;
ap_uint<1> mode = (ctrl > (ap_uint<32>)0);
mode = mode ^ 1; // inversing the behavior for default setting of axi_qei_ctrl '0' means B leading A
//#define DBG_CHIPSCOPE
#ifdef DBG_CHIPSCOPE
unsigned short freqA = 0;
Expand Down
Loading

0 comments on commit fcd15fe

Please sign in to comment.