From 4dbced4c9d5ff5aa26413231e1b8fa7814571761 Mon Sep 17 00:00:00 2001 From: Nicolas Trimborn Date: Sun, 22 Aug 2021 14:03:02 +0200 Subject: [PATCH] Got AS series of angle sensor working --- .../.atmelstart/atmel_start_config.atstart | 2 +- .../Motor_Master/Config/hpl_sercom_config.h | 2 +- .../Motor_Master/EtherCAT_SlaveDef.h | 8 +++--- .../Motor_Master/Ethercat_SlaveDef.h | 8 +++--- .../Motor_Master/Motor_Master.cproj | 4 +-- .../Motor_Master/Motor_Master/angle_sensors.c | 20 +++++++------- .../Motor_Master/Motor_Master/angle_sensors.h | 7 ++--- .../Motor_Master/Motor_Master/bldc.c | 12 ++++++--- .../Motor_Master/Motor_Master/main.c | 19 +++++++++---- .../Motor_Slave/Motor_Slave/MSIF_slave.h | 4 +-- .../Motor_Slave/Motor_Slave/angle_sensors.c | 16 +++++------ .../Motor_Slave/Motor_Slave/angle_sensors.h | 6 ++--- 2_Motor_Slave/Motor_Slave/Motor_Slave/bldc.c | 11 +++++--- 2_Motor_Slave/Motor_Slave/Motor_Slave/main.c | 27 ++++++++++++------- 14 files changed, 87 insertions(+), 59 deletions(-) diff --git a/2_Motor_Master/Motor_Master/Motor_Master/.atmelstart/atmel_start_config.atstart b/2_Motor_Master/Motor_Master/Motor_Master/.atmelstart/atmel_start_config.atstart index 2fef071..46fdc49 100644 --- a/2_Motor_Master/Motor_Master/Motor_Master/.atmelstart/atmel_start_config.atstart +++ b/2_Motor_Master/Motor_Master/Motor_Master/.atmelstart/atmel_start_config.atstart @@ -1904,7 +1904,7 @@ drivers: spi_master_arch_dord: MSB first spi_master_arch_ibon: In data stream spi_master_arch_runstdby: false - spi_master_baud_rate: 8000000 + spi_master_baud_rate: 1000000 spi_master_character_size: 8 bits spi_master_dummybyte: 511 spi_master_rx_enable: true diff --git a/2_Motor_Master/Motor_Master/Motor_Master/Config/hpl_sercom_config.h b/2_Motor_Master/Motor_Master/Motor_Master/Config/hpl_sercom_config.h index 7d62662..27176cc 100644 --- a/2_Motor_Master/Motor_Master/Motor_Master/Config/hpl_sercom_config.h +++ b/2_Motor_Master/Motor_Master/Motor_Master/Config/hpl_sercom_config.h @@ -377,7 +377,7 @@ // The SPI data transfer rate // spi_master_baud_rate #ifndef CONF_SERCOM_5_SPI_BAUD -#define CONF_SERCOM_5_SPI_BAUD 8000000 +#define CONF_SERCOM_5_SPI_BAUD 1000000 #endif // 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 e5aac6b..a97b274 100644 --- a/2_Motor_Master/Motor_Master/Motor_Master/EtherCAT_SlaveDef.h +++ b/2_Motor_Master/Motor_Master/Motor_Master/EtherCAT_SlaveDef.h @@ -176,7 +176,7 @@ static void update_telemetry(void) *M1_Motor__hallState = Motor1.motor_status.currentHallPattern; *M1_Motor_dutyCycle = Motor1.motor_status.duty_cycle; *M1_Motor_speed = (int16_t)Motor1.motor_status.calc_rpm; - *M1_Joint_abs_position = Motor1.motor_status.actualDirection; + //*M1_Joint_abs_position = Motor1.motor_status.actualDirection; /* Motor 2 */ *M2_Status = Motor2.motor_state.currentstate; *M2_Joint_rel_position = Motor2.motor_status.Num_Steps; @@ -189,7 +189,7 @@ static void update_telemetry(void) *M2_Motor__hallState = Motor2.motor_status.currentHallPattern; *M2_Motor_dutyCycle = Motor2.motor_status.duty_cycle; *M2_Motor_speed = (int16_t)Motor2.motor_status.calc_rpm; - *M2_Joint_abs_position = Motor2.motor_status.actualDirection; + //*M2_Joint_abs_position = Motor2.motor_status.actualDirection; } static void update_setpoints(void) @@ -266,7 +266,7 @@ static inline void comms_check(void) *M1_Status = 1; *M1_Mode = 2; *M1_Joint_rel_position = -3; - *M1_Joint_abs_position = 4; + //*M1_Joint_abs_position = 4; *M1_Motor_speed = -5; *M1_Motor_current_bus = 6; *M1_Motor_currentPhA = -7; @@ -278,7 +278,7 @@ static inline void comms_check(void) *M2_Status = 12; *M2_Mode = 13; *M2_Joint_rel_position = 14; - *M2_Joint_abs_position = -15; + //*M2_Joint_abs_position = -15; *M2_Motor_speed = 16; *M2_Motor_current_bus = -17; *M2_Motor_currentPhA = 18; 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 e5aac6b..a97b274 100644 --- a/2_Motor_Master/Motor_Master/Motor_Master/Ethercat_SlaveDef.h +++ b/2_Motor_Master/Motor_Master/Motor_Master/Ethercat_SlaveDef.h @@ -176,7 +176,7 @@ static void update_telemetry(void) *M1_Motor__hallState = Motor1.motor_status.currentHallPattern; *M1_Motor_dutyCycle = Motor1.motor_status.duty_cycle; *M1_Motor_speed = (int16_t)Motor1.motor_status.calc_rpm; - *M1_Joint_abs_position = Motor1.motor_status.actualDirection; + //*M1_Joint_abs_position = Motor1.motor_status.actualDirection; /* Motor 2 */ *M2_Status = Motor2.motor_state.currentstate; *M2_Joint_rel_position = Motor2.motor_status.Num_Steps; @@ -189,7 +189,7 @@ static void update_telemetry(void) *M2_Motor__hallState = Motor2.motor_status.currentHallPattern; *M2_Motor_dutyCycle = Motor2.motor_status.duty_cycle; *M2_Motor_speed = (int16_t)Motor2.motor_status.calc_rpm; - *M2_Joint_abs_position = Motor2.motor_status.actualDirection; + //*M2_Joint_abs_position = Motor2.motor_status.actualDirection; } static void update_setpoints(void) @@ -266,7 +266,7 @@ static inline void comms_check(void) *M1_Status = 1; *M1_Mode = 2; *M1_Joint_rel_position = -3; - *M1_Joint_abs_position = 4; + //*M1_Joint_abs_position = 4; *M1_Motor_speed = -5; *M1_Motor_current_bus = 6; *M1_Motor_currentPhA = -7; @@ -278,7 +278,7 @@ static inline void comms_check(void) *M2_Status = 12; *M2_Mode = 13; *M2_Joint_rel_position = 14; - *M2_Joint_abs_position = -15; + //*M2_Joint_abs_position = -15; *M2_Motor_speed = 16; *M2_Motor_current_bus = -17; *M2_Motor_currentPhA = 18; diff --git a/2_Motor_Master/Motor_Master/Motor_Master/Motor_Master.cproj b/2_Motor_Master/Motor_Master/Motor_Master/Motor_Master.cproj index 84e5c1e..211dacf 100644 --- a/2_Motor_Master/Motor_Master/Motor_Master/Motor_Master.cproj +++ b/2_Motor_Master/Motor_Master/Motor_Master/Motor_Master.cproj @@ -221,7 +221,7 @@ - + @@ -419,7 +419,7 @@ True Maximum (-g3) True - -std=gnu11 -mfloat-abi=hard -mfpu=fpv4-sp-d16 + -std=gnu99 -mfloat-abi=hard -mfpu=fpv4-sp-d16 True diff --git a/2_Motor_Master/Motor_Master/Motor_Master/angle_sensors.c b/2_Motor_Master/Motor_Master/Motor_Master/angle_sensors.c index fe559ac..6500eae 100644 --- a/2_Motor_Master/Motor_Master/Motor_Master/angle_sensors.c +++ b/2_Motor_Master/Motor_Master/Motor_Master/angle_sensors.c @@ -29,20 +29,19 @@ void angle_sensor_init() gpio_set_pin_level(ANGLESENSOR.SS_pin, true); } -//void read(ASCommand command) -//{ - //_read(command); // Send command to device(s) - //_read(AS_CMD_NOP); // Read-out device(s) -//} +int16_t* ang_sense_read(ASCommand command) +{ + _read(command); // Send command to device(s) + return _read(command); // Read-out device(s) +} int16_t* read_angle() { _read(AS_CMD_ANGLE); // Send command to device(s) - _read(AS_CMD_ANGLE); // Read-out device(s) - return &ANGLESENSOR._readBuffer; + return _read(AS_CMD_ANGLE); // Read-out device(s) } -void _read(ASCommand command) +int16_t* _read(ASCommand command) { if(ANGLESENSOR.n_dev == 1) @@ -50,7 +49,7 @@ void _read(ASCommand command) // Give command to start reading the angle gpio_set_pin_level(ANGLESENSOR.SS_pin, false); uint16_t temp = _spi_transfer16(&ANGLESENSOR, command); - ANGLESENSOR._readBuffer[0] = (temp & AS_MASK); + ANGLESENSOR._readBuffer[0] = (temp); gpio_set_pin_level(ANGLESENSOR.SS_pin, true); //delay_us(1); // Wait at least 350ns after chip select } else { @@ -60,11 +59,12 @@ void _read(ASCommand command) for(int i = 0; i < ANGLESENSOR.n_dev; ++i) { uint16_t temp = _spi_transfer16(&ANGLESENSOR, command); - ANGLESENSOR._readBuffer[i] = (temp & AS_MASK); + ANGLESENSOR._readBuffer[i] = (temp); } gpio_set_pin_level(ANGLESENSOR.SS_pin, true); //delay_us(1); // Wait at least 350ns after chip select } + return &ANGLESENSOR._readBuffer; } diff --git a/2_Motor_Master/Motor_Master/Motor_Master/angle_sensors.h b/2_Motor_Master/Motor_Master/Motor_Master/angle_sensors.h index c9627e5..2e4be9c 100644 --- a/2_Motor_Master/Motor_Master/Motor_Master/angle_sensors.h +++ b/2_Motor_Master/Motor_Master/Motor_Master/angle_sensors.h @@ -57,8 +57,9 @@ typedef enum { AS_CMD_NOP = 0x0000, AS_CMD_ERROR = 0x0001 | AS_FLAG_READ, // Reads error register of sensor and clear error flags AS_CMD_DIAGNOSTICS = 0x3FFD | AS_FLAG_READ, // Reads automatic gain control and diagnostics info - AS_CMD_MAGNITUDE = 0x3FFE | AS_FLAG_READ, + AS_CMD_MAGNITUDE = (uint16_t)(((0x2A & AS_ADDRESS_MASK) | AS_FLAG_READ) << 8), AS_CMD_ANGLE = (uint16_t)(((0x20 & AS_ADDRESS_MASK) | AS_FLAG_READ) << 8), + AS_CMD_TEMP = ((0x28 & AS_ADDRESS_MASK) | AS_FLAG_READ) << 8, } ASCommand; // Masks for bits in the result of the AS_CMD_DIAGNOSTICS command @@ -88,7 +89,7 @@ static struct SPI_ANGLE_SENSOR ANGLESENSOR = { }; void angle_sensor_init(); -void read(ASCommand command); +int16_t* ang_sense_read(ASCommand command); // Performs a single angle measurement on all sensors // @return Array of raw angle data. To get the 14-bit value representing // the angle, apply the mask() to the result. @@ -103,7 +104,7 @@ static bool parity_check(int16_t sensor_result); int16_t degrees(int16_t sensor_result); // Intended to be used Internally -void _read(ASCommand command); +int16_t* _read(ASCommand command); uint16_t _spi_transfer16(struct spi_m_sync_descriptor *spi, uint16_t value); diff --git a/2_Motor_Master/Motor_Master/Motor_Master/bldc.c b/2_Motor_Master/Motor_Master/Motor_Master/bldc.c index 966d875..fe94b79 100644 --- a/2_Motor_Master/Motor_Master/Motor_Master/bldc.c +++ b/2_Motor_Master/Motor_Master/Motor_Master/bldc.c @@ -35,7 +35,7 @@ void motor_StateMachine(BLDCMotor_t* const motor) case MOTOR_IDLE: //hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, DISABLE_PATTERN); motor->motor_state.previousstate = motor->motor_state.currentstate; - motor->motor_state.currentstate = MOTOR_IDLE; + motor->motor_state.currentstate = MOTOR_PVI_CTRL_STATE; break; case MOTOR_OPEN_LOOP_STATE: BLDC_runOpenLoop(motor, *M1_Desired_dc); @@ -227,12 +227,18 @@ void exec_commutation(BLDCMotor_t* const motor) volatile uint16_t temp_M1 = COMMUTATION_PATTERN[currentHall + motor->motor_setpoints.directionOffset]; - hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, temp_M1); + //TCC0->PATTBUF.reg = temp_M1; + Tcc * tmp = (Tcc *)motor->motor_param->pwm_desc->device.hw; + tmp->PATTBUF.reg = (uint16_t)temp_M1; + //motor->motor_param->pwm_desc->device.hw->PATTBUF.reg = temp_M1; + //hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, temp_M1); // ---------------------------------------------------------------------- // Set Calculated Duty Cycle // ---------------------------------------------------------------------- - hri_tcc_write_CCBUF_CCBUF_bf(motor->motor_param->pwm_desc->device.hw, 0, motor->motor_status.duty_cycle); + //hri_tcc_write_CCBUF_CCBUF_bf(motor->motor_param->pwm_desc->device.hw, 0, motor->motor_status.duty_cycle); + tmp->CCBUF[0].reg = (uint32_t)motor->motor_status.duty_cycle; + volatile uint8_t cur_comm_step = MOTOR_COMMUTATION_STEPS[currentHall]; motor->motor_status.cur_comm_step = cur_comm_step; diff --git a/2_Motor_Master/Motor_Master/Motor_Master/main.c b/2_Motor_Master/Motor_Master/Motor_Master/main.c index ba864c4..70bc95d 100644 --- a/2_Motor_Master/Motor_Master/Motor_Master/main.c +++ b/2_Motor_Master/Motor_Master/Motor_Master/main.c @@ -54,7 +54,7 @@ static struct timer_task Onems_task; void One_ms_timer_init(void) { - Onems_task.interval = 10; + Onems_task.interval = 1; Onems_task.cb = One_ms_cycle_callback; Onems_task.mode = TIMER_TASK_REPEAT; timer_add_task(&TIMER_0, &Onems_task); @@ -191,11 +191,20 @@ int main(void) _dma_enable_transaction(DMAC_CHANNEL_CONF_SERCOM_1_TRANSMIT, false); volatile int x = 1; - + // int16_t* angles; - angles = read_angle(); - *M1_Joint_abs_position = degrees(angles[0]); - *M2_Joint_abs_position = degrees(angles[1]); + //int16_t* field; + //int16_t* temp; + //angles = read_angle(); + //*M1_Joint_abs_position = degrees(angles[0]); + //*M2_Joint_abs_position = degrees(angles[1]); + //field = ang_sense_read(AS_CMD_MAGNITUDE); + //*Spare1_tx = (field[0] & AS_MASK); + //*Spare2_tx = (field[1] & AS_MASK); + //temp = ang_sense_read(AS_CMD_TEMP); + //*Spare3_tx = (int16_t)(((float)(temp[0] & AS_MASK) / 8.0) - 273.15); + //*Spare4_tx = (int16_t)(((float)(temp[1] & AS_MASK) / 8.0) - 273.15); + volatile int y = 0; //spi_m_dma_transfer(&SPI_1_MSIF, (uint8_t*)Slave_1.tx_buffer, (uint8_t*)Slave_1.rx_buffer, MASTER_BUFFER_SIZE); diff --git a/2_Motor_Slave/Motor_Slave/Motor_Slave/MSIF_slave.h b/2_Motor_Slave/Motor_Slave/Motor_Slave/MSIF_slave.h index ba4afe0..28d6f85 100644 --- a/2_Motor_Slave/Motor_Slave/Motor_Slave/MSIF_slave.h +++ b/2_Motor_Slave/Motor_Slave/Motor_Slave/MSIF_slave.h @@ -102,7 +102,7 @@ static void update_telemetry(void) *M3_Motor__hallState = Motor1.motor_status.currentHallPattern; *M3_Motor_dutyCycle = Motor1.motor_status.duty_cycle; *M3_Motor_speed = (int16_t)Motor1.motor_status.calc_rpm; - *M3_Joint_abs_position = Motor1.motor_status.actualDirection; + //*M3_Joint_abs_position = ; /* Motor 2 */ *M4_Status = Motor2.motor_state.currentstate; *M4_Joint_rel_position = Motor2.motor_status.Num_Steps; @@ -115,7 +115,7 @@ static void update_telemetry(void) *M4_Motor__hallState = Motor2.motor_status.currentHallPattern; *M4_Motor_dutyCycle = Motor2.motor_status.duty_cycle; *M4_Motor_speed = (int16_t)Motor2.motor_status.calc_rpm; - *M4_Joint_abs_position = Motor2.motor_status.actualDirection; + //*M4_Joint_abs_position = Motor2.motor_status.actualDirection; } static void update_setpoints(void) diff --git a/2_Motor_Slave/Motor_Slave/Motor_Slave/angle_sensors.c b/2_Motor_Slave/Motor_Slave/Motor_Slave/angle_sensors.c index dcea02e..a1cb6c5 100644 --- a/2_Motor_Slave/Motor_Slave/Motor_Slave/angle_sensors.c +++ b/2_Motor_Slave/Motor_Slave/Motor_Slave/angle_sensors.c @@ -29,20 +29,19 @@ void angle_sensor_init() gpio_set_pin_level(ANGLESENSOR.SS_pin, true); } -void read(ASCommand command) +int16_t* read(ASCommand command) { _read(command); // Send command to device(s) - _read(AS_CMD_NOP); // Read-out device(s) + return _read(AS_CMD_NOP); // Read-out device(s) } int16_t* read_angle() { _read(AS_CMD_ANGLE); // Send command to device(s) - _read(AS_CMD_ANGLE); // Read-out device(s) - return &ANGLESENSOR._readBuffer; + return _read(AS_CMD_ANGLE); // Read-out device(s) } -void _read(ASCommand command) +int16_t* _read(ASCommand command) { if(ANGLESENSOR.n_dev == 1) @@ -52,19 +51,20 @@ void _read(ASCommand command) uint16_t temp = _spi_transfer16(&ANGLESENSOR, command); ANGLESENSOR._readBuffer[0] = (temp & ~0xC000); gpio_set_pin_level(ANGLESENSOR.SS_pin, true); - //delay_us(1); // Wait at least 350ns after chip select + delay_us(1); // Wait at least 350ns after chip select } else { // Enable the sensor on the chain gpio_set_pin_level(ANGLESENSOR.SS_pin, false); - //delay_us(1); // Wait at least 350ns after chip select + delay_us(1); // Wait at least 350ns after chip select for(int i = 0; i < ANGLESENSOR.n_dev; ++i) { uint16_t temp = _spi_transfer16(&ANGLESENSOR, command); ANGLESENSOR._readBuffer[i] = (temp & ~0xC000); } gpio_set_pin_level(ANGLESENSOR.SS_pin, true); - //delay_us(1); // Wait at least 350ns after chip select + delay_us(1); // Wait at least 350ns after chip select } + return &ANGLESENSOR._readBuffer; } diff --git a/2_Motor_Slave/Motor_Slave/Motor_Slave/angle_sensors.h b/2_Motor_Slave/Motor_Slave/Motor_Slave/angle_sensors.h index fbee68d..010015d 100644 --- a/2_Motor_Slave/Motor_Slave/Motor_Slave/angle_sensors.h +++ b/2_Motor_Slave/Motor_Slave/Motor_Slave/angle_sensors.h @@ -83,12 +83,12 @@ static struct SPI_ANGLE_SENSOR ANGLESENSOR = { .SPI_descr = &SPI_3, .flags = 0, .SS_pin = SPI3_SS, - .n_dev = 1, + .n_dev = 2, ._readBuffer = {0} // Must Equal n_dev }; void angle_sensor_init(); -void read(ASCommand command); +int16_t* read(ASCommand command); // Performs a single angle measurement on all sensors // @return Array of raw angle data. To get the 14-bit value representing // the angle, apply the mask() to the result. @@ -103,7 +103,7 @@ static bool parity_check(int16_t sensor_result); int16_t degrees(int16_t sensor_result); // Intended to be used Internally -void _read(ASCommand command); +int16_t* _read(ASCommand command); uint16_t _spi_transfer16(struct spi_m_sync_descriptor *spi, uint16_t value); diff --git a/2_Motor_Slave/Motor_Slave/Motor_Slave/bldc.c b/2_Motor_Slave/Motor_Slave/Motor_Slave/bldc.c index 832187c..fc99b5a 100644 --- a/2_Motor_Slave/Motor_Slave/Motor_Slave/bldc.c +++ b/2_Motor_Slave/Motor_Slave/Motor_Slave/bldc.c @@ -227,13 +227,18 @@ void exec_commutation(BLDCMotor_t* const motor) volatile uint16_t temp_M1 = COMMUTATION_PATTERN[currentHall + motor->motor_setpoints.directionOffset]; - hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, temp_M1); + //TCC0->PATTBUF.reg = temp_M1; + Tcc * tmp = (Tcc *)motor->motor_param->pwm_desc->device.hw; + tmp->PATTBUF.reg = (uint16_t)temp_M1; + //motor->motor_param->pwm_desc->device.hw->PATTBUF.reg = temp_M1; + //hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, temp_M1); // ---------------------------------------------------------------------- // Set Calculated Duty Cycle // ---------------------------------------------------------------------- - hri_tcc_write_CCBUF_CCBUF_bf(motor->motor_param->pwm_desc->device.hw, 0, motor->motor_status.duty_cycle); - + //hri_tcc_write_CCBUF_CCBUF_bf(motor->motor_param->pwm_desc->device.hw, 0, motor->motor_status.duty_cycle); + tmp->CCBUF[0].reg = (uint32_t)motor->motor_status.duty_cycle; + volatile uint8_t cur_comm_step = MOTOR_COMMUTATION_STEPS[currentHall]; motor->motor_status.cur_comm_step = cur_comm_step; volatile int8_t step_change = (cur_comm_step - motor->motor_status.prev_comm_step); diff --git a/2_Motor_Slave/Motor_Slave/Motor_Slave/main.c b/2_Motor_Slave/Motor_Slave/Motor_Slave/main.c index b57f315..99b834d 100644 --- a/2_Motor_Slave/Motor_Slave/Motor_Slave/main.c +++ b/2_Motor_Slave/Motor_Slave/Motor_Slave/main.c @@ -70,7 +70,7 @@ static struct timer_task Onems_task; void One_ms_timer_init(void) { - Onems_task.interval = 10; + Onems_task.interval = 1; Onems_task.cb = One_ms_cycle_callback; Onems_task.mode = TIMER_TASK_REPEAT; timer_add_task(&TIMER_0, &Onems_task); @@ -86,6 +86,10 @@ void SERCOM1_1_Handler() //SERCOM1->SPI.INTFLAG.bit.TXC = 0x01; //SPI_tx_buffer[0] += 1; //tx_buffer[31] += 1; + + //DMAC->Channel[0].CHCTRLA.reg |= DMAC_CHCTRLA_ENABLE; + //DMAC->Channel[1].CHCTRLA.reg |= DMAC_CHCTRLA_ENABLE; + _dma_enable_transaction(CONF_SERCOM_1_RECEIVE_DMA_CHANNEL, false); _dma_enable_transaction(CONF_SERCOM_1_TRANSMIT_DMA_CHANNEL, false); @@ -103,6 +107,7 @@ void SERCOM1_3_Handler() //SERCOM1->SPI.INTFLAG.bit.TXC = 0x01; //tx_buffer[0] += 1; //tx_buffer[31] += 1; + //_dma_enable_transaction(CONF_SERCOM_1_RECEIVE_DMA_CHANNEL, false); //_dma_enable_transaction(CONF_SERCOM_1_TRANSMIT_DMA_CHANNEL, false); @@ -129,13 +134,15 @@ void enable_NVIC_IRQ(void) NVIC_SetPriority(DMAC_0_IRQn, 2); NVIC_SetPriority(ADC1_0_IRQn, 3); NVIC_EnableIRQ(TCC0_0_IRQn); + NVIC_SetPriority(TCC0_0_IRQn, 1); NVIC_EnableIRQ(TCC1_0_IRQn); + NVIC_SetPriority(TCC1_0_IRQn, 1); //NVIC_EnableIRQ(SERCOM5_0_IRQn); - //NVIC_EnableIRQ(SERCOM1_1_IRQn); - //NVIC_SetPriority(SERCOM1_1_IRQn, 1); - //NVIC_EnableIRQ(SERCOM1_3_IRQn); - //NVIC_SetPriority(SERCOM1_3_IRQn, 1); + NVIC_EnableIRQ(SERCOM1_1_IRQn); + NVIC_SetPriority(SERCOM1_1_IRQn, 0); + NVIC_EnableIRQ(SERCOM1_3_IRQn); + NVIC_SetPriority(SERCOM1_3_IRQn, 0); //NVIC_EnableIRQ(SERCOM1_3_IRQn); //NVIC_EnableIRQ(EIC_5_IRQn); } @@ -171,7 +178,7 @@ void APPLICATION_StateMachine(void) //applicationStatus.currentstate ; //comms_check(); motor_StateMachine(&Motor1); - motor_StateMachine(&Motor2); + //motor_StateMachine(&Motor2); break; case APP_FAULT: //DisableGateDrivers(&Motor1); @@ -239,10 +246,10 @@ int main(void) /* Replace with your application code */ while (1) { - //if (Motor1.timerflags.adc_readings_ready_tic) {process_currents();} + if (Motor1.timerflags.adc_readings_ready_tic) {process_currents();} if (Motor1.timerflags.current_loop_tic) { - //APPLICATION_StateMachine(); - //exec_commutation(&Motor1); + APPLICATION_StateMachine(); + exec_commutation(&Motor1); //exec_commutation(&Motor2); } @@ -263,7 +270,7 @@ int main(void) int16_t* angles; angles = read_angle(); *M3_Joint_abs_position = degrees(angles[0]); - //*M4_Joint_abs_position = angles[1]; + *M4_Joint_abs_position = degrees(angles[1]); volatile int y = 0;