diff --git a/2_Motor_Master/LAN9252-2_motor_master_mkIV.xml b/2_Motor_Master/LAN9252-2_motor_master_mkIV.xml
new file mode 100644
index 0000000..f0d767f
--- /dev/null
+++ b/2_Motor_Master/LAN9252-2_motor_master_mkIV.xml
@@ -0,0 +1,895 @@
+
+
+
+ #x000004D8
+ Microchip Technology Inc
+
+
+
+
+ LAN9252-2_motor_Master
+ LAN9252-2_motor_Master
+ 424DD8020000000000003600000028000000100000000E0000000100180000000000A2020000120B0000120B000000000000000000001306E31306E3190CE42B1FE62B1FE61306E31F13E5190CE42519E51306E31306E3190CE42F24E7190CE41306E31306E31306E31306E35F56EC645CED645CED4137E91F13E5473DE95F57EC3227E71306E3473DE95A51EC271BE61306E31306E31409CA524CC68E8AD74F48C1615CC82218D03E36BF716BCE746FCE453DC01307CE3931BA7D78D27671D1150CB21409CA1712801B1D1D1B1D1D1B1D1D1B1D1D120B891B1D1D1B1D1D1B1D1D1B1D1D120B891B1D1D1B1D1D1B1D1D1B1D1D1712801712807F8080D4D5D5D4D5D5383939120B89545656D4D5D5D4D5D5626464130C89292B2BD4D5D5D4D5D56264641915801712804647471B1D1DAAAAAAD4D5D5130E82383939292B2B717272D4D5D5151183D4D5D57F80801B1D1D7172721E1C81191580464747D4D5D5D4D5D51B1D1D19158A292B2BD4D5D5D4D5D5292B2B1B1B8AD4D5D56264641B1D1D1B1D1D2427821E1D81D4D5D54647476264643839391E208BD4D5D57F8080464747545656242A8BD4D5D59B9C9C292B2BAAAAAA2D3683252882464747D4D5D5D4D5D51B1D1D272D85292B2BD4D5D5D4D5D5292B2B2E37861B1D1DD4D5D5D4D5D5464747394484323BB52324812122822426822526824554C0323883292B822A2D83353C84424CBF3238843940842E32834853865D6EBB5262EB3E43E83334E74147E94349E9535FEB4D56EA5662EB484DEA545DEB636FED545AEA5A63EC6671ED8CA0F290A5F2748AEF6B7BEE5D68EC6874ED788AEF8397F17684EF7986EF8C9FF2818FF1818EF08E9DF18A97F18791F19BA9F3B0C0F691A4F291A2F28390F192A1F29CACF3A3B3F498A6F3A4B3F4AEBDF5B0BEF59EA8F3A3ADF4BBC7F7C4D1F8CAD7F8CED9F9B4C4F6B8C8F6ACB8F59AA3F3B6C1F6C5D2F8C2CDF8CCD7F9D2DDF9D5E0FAD2DAF9D5DCF9DFE7FBE2E9FBE5EBFBE8EEFB0000
+
+
+
+
+ LAN9252-2_motor_Master
+
+
+
+ 4096
+ 4
+ 3
+
+
+ MII
+ 0
+
+
+ MII
+ 1
+
+ #x0012
+
+ LAN9252-2_motor_Master
+ Outputs
+ Inputs
+ Outputs
+ Inputs
+
+ #x1a00
+ ECAT2MCU
+
+ #x3101
+ 1
+ 8
+ M1__control_mode
+ BYTE
+
+
+ #x3102
+ 1
+ 8
+ M1__control_set
+ BYTE
+
+
+ #x3103
+ 1
+ 16
+ M1__desired_position
+ INT
+
+
+ #x3104
+ 1
+ 16
+ M1__desired_speed
+ INT
+
+
+ #x3105
+ 1
+ 16
+ M1__desired__current
+ INT
+
+
+ #x3106
+ 1
+ 16
+ M1__Max_Pos
+ INT
+
+
+ #x3107
+ 1
+ 16
+ M1__Max_velocity
+ INT
+
+
+ #x3108
+ 1
+ 16
+ M1__Max_current
+ INT
+
+
+ #x3109
+ 1
+ 16
+ M1__Spare
+ INT
+
+
+ #x310A
+ 1
+ 8
+ M2__control_mode
+ BYTE
+
+
+ #x310B
+ 1
+ 8
+ M2__control_set
+ BYTE
+
+
+ #x310C
+ 1
+ 16
+ M2__desired_position
+ INT
+
+
+ #x310D
+ 1
+ 16
+ M2__desired_speed
+ INT
+
+
+ #x310E
+ 1
+ 16
+ M2__desired__current
+ INT
+
+
+ #x310F
+ 1
+ 16
+ M2__Max_Pos
+ INT
+
+
+ #x3110
+ 1
+ 16
+ M2__Max_velocity
+ INT
+
+
+ #x3111
+ 1
+ 16
+ M2__Max_current
+ INT
+
+
+ #x3112
+ 1
+ 16
+ M2__Spare
+ INT
+
+
+ #x3113
+ 1
+ 16
+ SPARE__1_RX
+ INT
+
+
+ #x3114
+ 1
+ 16
+ SPARE__2_RX
+ INT
+
+
+ #x3115
+ 1
+ 16
+ SPARE__3_RX
+ INT
+
+
+ #x3116
+ 1
+ 16
+ SPARE__4_RX
+ INT
+
+
+ #x3117
+ 1
+ 16
+ SPARE__5_RX
+ INT
+
+
+ #x3118
+ 1
+ 16
+ SPARE__6_RX
+ INT
+
+
+ #x3119
+ 1
+ 16
+ SPARE__7_RX
+ INT
+
+
+ #x311A
+ 1
+ 16
+ SPARE__8_RX
+ INT
+
+
+ #x311B
+ 1
+ 16
+ SPARE__9_RX
+ INT
+
+
+ #x311C
+ 1
+ 16
+ SPARE__10_RX
+ INT
+
+
+ #x311D
+ 1
+ 16
+ SPARE__11_RX
+ INT
+
+
+ #x311E
+ 1
+ 16
+ SPARE__12_RX
+ INT
+
+
+ #x311F
+ 1
+ 16
+ SPARE__13_RX
+ INT
+
+
+ #x3120
+ 1
+ 16
+ SPARE__14_RX
+ INT
+
+
+ #x3121
+ 1
+ 16
+ SPARE__15_RX
+ INT
+
+
+ #x3122
+ 1
+ 16
+ SPARE__16_RX
+ INT
+
+
+ #x3123
+ 1
+ 8
+ M3__control_mode
+ BYTE
+
+
+ #x3124
+ 1
+ 8
+ M3__control_set
+ BYTE
+
+
+ #x3125
+ 1
+ 16
+ M3__desired_position
+ INT
+
+
+ #x3126
+ 1
+ 16
+ M3__desired_speed
+ INT
+
+
+ #x3127
+ 1
+ 16
+ M3__desired__current
+ INT
+
+
+ #x3128
+ 1
+ 16
+ M3__Max_Pos
+ INT
+
+
+ #x3129
+ 1
+ 16
+ M3__Max_velocity
+ INT
+
+
+ #x312A
+ 1
+ 16
+ M3__Max_current
+ INT
+
+
+ #x312B
+ 1
+ 16
+ M3__Spare
+ INT
+
+
+ #x312C
+ 1
+ 8
+ M4__control_mode
+ BYTE
+
+
+ #x312D
+ 1
+ 8
+ M4__control_set
+ BYTE
+
+
+ #x312E
+ 1
+ 16
+ M4__desired_position
+ INT
+
+
+ #x312F
+ 1
+ 16
+ M4__desired_speed
+ INT
+
+
+ #x3130
+ 1
+ 16
+ M4__desired__current
+ INT
+
+
+ #x3131
+ 1
+ 16
+ M4__Max_Pos
+ INT
+
+
+ #x3132
+ 1
+ 16
+ M4__Max_velocity
+ INT
+
+
+ #x3133
+ 1
+ 16
+ M4__Max_current
+ INT
+
+
+ #x3134
+ 1
+ 16
+ M4__Spare
+ INT
+
+
+
+ #x1600
+ MCU2ECAT
+
+ #x3001
+ 1
+ 8
+ M1__status
+ BYTE
+
+
+ #x3002
+ 1
+ 8
+ M1__mode
+ BYTE
+
+
+ #x3003
+ 1
+ 16
+ M1__Joint_rel_position
+ INT
+
+
+ #x3004
+ 1
+ 16
+ M1__Joint_abs_position
+ INT
+
+
+ #x3005
+ 1
+ 16
+ M1__Motor_speed
+ INT
+
+
+ #x3006
+ 1
+ 16
+ M1__Motor_current_bus
+ INT
+
+
+ #x3007
+ 1
+ 16
+ M1__Motor_currentPhA
+ INT
+
+
+ #x3008
+ 1
+ 16
+ M1__Motor_currentPhB
+ INT
+
+
+ #x3009
+ 1
+ 16
+ M1__Motor_currentPhC
+ INT
+
+
+ #x300A
+ 1
+ 16
+ M1__Motor_hallState
+ INT
+
+
+ #x300B
+ 1
+ 16
+ M1__Motor_dutyCycle
+ INT
+
+
+ #x300C
+ 1
+ 8
+ M2__status
+ BYTE
+
+
+ #x300D
+ 1
+ 8
+ M2__mode
+ BYTE
+
+
+ #x300E
+ 1
+ 16
+ M2__Joint__rel_position
+ INT
+
+
+ #x300F
+ 1
+ 16
+ M2__Joint_abs_position
+ INT
+
+
+ #x3010
+ 1
+ 16
+ M2__Motor_speed
+ INT
+
+
+ #x3011
+ 1
+ 16
+ M2__Motor_current_bus
+ INT
+
+
+ #x3012
+ 1
+ 16
+ M2__Motor_currentPhA
+ INT
+
+
+ #x3013
+ 1
+ 16
+ M2__Motor_currentPhB
+ INT
+
+
+ #x3014
+ 1
+ 16
+ M2__Motor_currentPhC
+ INT
+
+
+ #x3015
+ 1
+ 16
+ M2__Motor_hallState
+ INT
+
+
+ #x3016
+ 1
+ 16
+ M2__Motor_dutyCycle
+ INT
+
+
+ #x3017
+ 1
+ 16
+ EMG__CH1
+ INT
+
+
+ #x3018
+ 1
+ 16
+ EMG__CH2
+ INT
+
+
+ #x3019
+ 1
+ 16
+ EMG__CH3
+ INT
+
+
+ #x301A
+ 1
+ 16
+ EMG__CH4
+ INT
+
+
+ #x301B
+ 1
+ 16
+ EMG__CH5
+ INT
+
+
+ #x301C
+ 1
+ 16
+ EMG__CH6
+ INT
+
+
+ #x301D
+ 1
+ 16
+ EMG__CH7
+ INT
+
+
+ #x301E
+ 1
+ 16
+ EMG__CH8
+ INT
+
+
+ #x301F
+ 1
+ 16
+ SPARE__1_TX
+ INT
+
+
+ #x3020
+ 1
+ 16
+ SPARE__2_TX
+ INT
+
+
+ #x3021
+ 1
+ 16
+ SPARE__3_TX
+ INT
+
+
+ #x3022
+ 1
+ 16
+ SPARE__4_TX
+ INT
+
+
+ #x3023
+ 1
+ 8
+ M3__status
+ BYTE
+
+
+ #x3024
+ 1
+ 8
+ M3__mode
+ BYTE
+
+
+ #x3025
+ 1
+ 16
+ M3__Joint__rel_position
+ INT
+
+
+ #x3026
+ 1
+ 16
+ M3__Joint_abs_position
+ INT
+
+
+ #x3027
+ 1
+ 16
+ M3__Motor_speed
+ INT
+
+
+ #x3028
+ 1
+ 16
+ M3__Motor_current_bus
+ INT
+
+
+ #x3029
+ 1
+ 16
+ M3__Motor_currentPhA
+ INT
+
+
+ #x302A
+ 1
+ 16
+ M3__Motor_currentPhB
+ INT
+
+
+ #x302B
+ 1
+ 16
+ M3__Motor_currentPhC
+ INT
+
+
+ #x302C
+ 1
+ 16
+ M3__Motor_hallState
+ INT
+
+
+ #x302D
+ 1
+ 16
+ M3__Motor_dutyCycle
+ INT
+
+
+ #x302E
+ 1
+ 8
+ M4__status
+ BYTE
+
+
+ #x302F
+ 1
+ 8
+ M4__mode
+ BYTE
+
+
+ #x3030
+ 1
+ 16
+ M4__Joint__rel_position
+ INT
+
+
+ #x3031
+ 1
+ 16
+ M4__Joint_abs_position
+ INT
+
+
+ #x3032
+ 1
+ 16
+ M4__Motor_speed
+ INT
+
+
+ #x3033
+ 1
+ 16
+ M4__Motor_current_bus
+ INT
+
+
+ #x3034
+ 1
+ 16
+ M4__Motor_currentPhA
+ INT
+
+
+ #x3035
+ 1
+ 16
+ M4__Motor_currentPhB
+ INT
+
+
+ #x3036
+ 1
+ 16
+ M4__Motor_currentPhC
+ INT
+
+
+ #x3037
+ 1
+ 16
+ M4__Motor_hallState
+ INT
+
+
+ #x3038
+ 1
+ 16
+ M4__Motor_dutyCycle
+ INT
+
+
+ #x3039
+ 1
+ 16
+ IMU__q_x0
+ INT
+
+
+ #x303A
+ 1
+ 16
+ IMU__q_y0
+ INT
+
+
+ #x303B
+ 1
+ 16
+ IMU__q_z0
+ INT
+
+
+ #x303C
+ 1
+ 16
+ IMU__q_w0
+ INT
+
+
+ #x303D
+ 1
+ 16
+ FSR__CH1
+ INT
+
+
+ #x303E
+ 1
+ 16
+ FSR__CH2
+ INT
+
+
+ #x303F
+ 1
+ 16
+ FSR__CH3
+ INT
+
+
+ #x3040
+ 1
+ 16
+ FSR__CH4
+ INT
+
+
+ #x3041
+ 1
+ 16
+ FSR__CH5
+ INT
+
+
+ #x3042
+ 1
+ 16
+ Pressure__CH1
+ INT
+
+
+ #x3043
+ 1
+ 16
+ Pressure__CH2
+ INT
+
+
+ #x3044
+ 1
+ 16
+ Pressure__CH3
+ INT
+
+
+
+ 2048
+ 803100CC1000F0FF
+
+
+
+
+
\ No newline at end of file
diff --git a/2_Motor_Master/Motor_Master/Motor_Master/EtherCAT_SlaveDef.h b/2_Motor_Master/Motor_Master/Motor_Master/EtherCAT_SlaveDef.h
index 0a5526c..e5aac6b 100644
--- a/2_Motor_Master/Motor_Master/Motor_Master/EtherCAT_SlaveDef.h
+++ b/2_Motor_Master/Motor_Master/Motor_Master/EtherCAT_SlaveDef.h
@@ -208,6 +208,21 @@ static void update_setpoints(void)
Motor2.motor_setpoints.max_torque = *M2_Max_current;
Motor2.motor_setpoints.max_velocity = *M2_Max_velocity;
+ //*M3_Desired_pos = 1;
+ //*M3_Desired_speed = 2;
+ //*M3_Desired_current = 3;
+ //*M3_Max_current = 4;
+ //*M3_Max_current = 5;
+ //*M3_Max_velocity = 6;
+ //
+ //*M4_Desired_pos = 7;
+ //*M4_Desired_speed = 8;
+ //*M4_Desired_current = 9;
+ //*M4_Max_current = 10;
+ //*M4_Max_current = 11;
+ //*M4_Max_velocity = 12;
+
+
//volatile uint8_t a = *M1_Control_mode;
//volatile uint8_t b = *M1_Control_set;
//volatile int16_t c = *M1_Desired_pos;
diff --git a/2_Motor_Master/Motor_Master/Motor_Master/Ethercat_SlaveDef.h b/2_Motor_Master/Motor_Master/Motor_Master/Ethercat_SlaveDef.h
index 0a5526c..e5aac6b 100644
--- a/2_Motor_Master/Motor_Master/Motor_Master/Ethercat_SlaveDef.h
+++ b/2_Motor_Master/Motor_Master/Motor_Master/Ethercat_SlaveDef.h
@@ -208,6 +208,21 @@ static void update_setpoints(void)
Motor2.motor_setpoints.max_torque = *M2_Max_current;
Motor2.motor_setpoints.max_velocity = *M2_Max_velocity;
+ //*M3_Desired_pos = 1;
+ //*M3_Desired_speed = 2;
+ //*M3_Desired_current = 3;
+ //*M3_Max_current = 4;
+ //*M3_Max_current = 5;
+ //*M3_Max_velocity = 6;
+ //
+ //*M4_Desired_pos = 7;
+ //*M4_Desired_speed = 8;
+ //*M4_Desired_current = 9;
+ //*M4_Max_current = 10;
+ //*M4_Max_current = 11;
+ //*M4_Max_velocity = 12;
+
+
//volatile uint8_t a = *M1_Control_mode;
//volatile uint8_t b = *M1_Control_set;
//volatile int16_t c = *M1_Desired_pos;
diff --git a/2_Motor_Master/Motor_Master/Motor_Master/bldc.c b/2_Motor_Master/Motor_Master/Motor_Master/bldc.c
index 53768f4..966d875 100644
--- a/2_Motor_Master/Motor_Master/Motor_Master/bldc.c
+++ b/2_Motor_Master/Motor_Master/Motor_Master/bldc.c
@@ -39,7 +39,7 @@ void motor_StateMachine(BLDCMotor_t* const motor)
break;
case MOTOR_OPEN_LOOP_STATE:
BLDC_runOpenLoop(motor, *M1_Desired_dc);
- //calculate_motor_speed(motor);
+ calculate_motor_speed(motor);
motor->motor_state.previousstate = motor->motor_state.currentstate;
break;
case MOTOR_V_CTRL_STATE:
diff --git a/2_Motor_Master/Motor_Master/Motor_Master/configuration.h b/2_Motor_Master/Motor_Master/Motor_Master/configuration.h
index f47bfda..b41ddeb 100644
--- a/2_Motor_Master/Motor_Master/Motor_Master/configuration.h
+++ b/2_Motor_Master/Motor_Master/Motor_Master/configuration.h
@@ -151,22 +151,6 @@ extern DmacDescriptor _descriptor_section[DMAC_CH_NUM];
extern DmacDescriptor _write_back_section[DMAC_CH_NUM];
-struct SPI_slaveboard {
- struct spi_m_dma_descriptor *SPI_Mn;
- uint8_t state;
- uint32_t SS_pin;
- uint32_t *tx_buffer;
- uint32_t *rx_buffer;
-};
-
-struct SPI_slaveboard Slave_1 = {
- .SPI_Mn = &SPI_1_MSIF,
- .state = 0,
- .SS_pin = SPI1_CS,
- .tx_buffer = &QSPI_tx_buffer[16],
- .rx_buffer = &QSPI_rx_buffer[16],
-};
-
#define DMAC_CHANNEL_CONF_SERCOM_1_RECEIVE 0u
#define DMAC_CHANNEL_CONF_SERCOM_1_TRANSMIT 1U
@@ -184,10 +168,10 @@ void init_spi_master_dma_descriptors()
{
_dma_set_source_address(DMAC_CHANNEL_CONF_SERCOM_1_RECEIVE,
(uint32_t *)&(((SercomSpi *)(SPI_1_MSIF.dev.prvt))->DATA.reg));
- _dma_set_destination_address(DMAC_CHANNEL_CONF_SERCOM_1_RECEIVE, &Slave_1.rx_buffer[0]);
+ _dma_set_destination_address(DMAC_CHANNEL_CONF_SERCOM_1_RECEIVE, &QSPI_tx_buffer[16]);
_dma_set_data_amount(DMAC_CHANNEL_CONF_SERCOM_1_RECEIVE, MASTER_BUFFER_SIZE);
- _dma_set_source_address(DMAC_CHANNEL_CONF_SERCOM_1_TRANSMIT, &Slave_1.tx_buffer[0]);
+ _dma_set_source_address(DMAC_CHANNEL_CONF_SERCOM_1_TRANSMIT, &QSPI_rx_buffer[16]);
_dma_set_destination_address(DMAC_CHANNEL_CONF_SERCOM_1_TRANSMIT,
(uint32_t *)&(((SercomSpi *)(SPI_1_MSIF.dev.prvt))->DATA.reg));
_dma_set_data_amount(DMAC_CHANNEL_CONF_SERCOM_1_TRANSMIT, MASTER_BUFFER_SIZE);
diff --git a/2_Motor_Master/Motor_Master/Motor_Master/main.c b/2_Motor_Master/Motor_Master/Motor_Master/main.c
index deaa601..ecc8a56 100644
--- a/2_Motor_Master/Motor_Master/Motor_Master/main.c
+++ b/2_Motor_Master/Motor_Master/Motor_Master/main.c
@@ -182,8 +182,6 @@ int main(void)
update_telemetry();
update_setpoints();
PORT->Group[1].OUTCLR.reg = (1<Group[1].OUTCLR.reg = (1<