diff --git a/BLDC_E54/.vs/BLDC_E54/v14/.atsuo b/BLDC_E54/.vs/BLDC_E54/v14/.atsuo index ac508ab..401804d 100644 Binary files a/BLDC_E54/.vs/BLDC_E54/v14/.atsuo and b/BLDC_E54/.vs/BLDC_E54/v14/.atsuo differ diff --git a/BLDC_E54/BLDC_E54/Debug/Makefile b/BLDC_E54/BLDC_E54/Debug/Makefile index a6fe0fd..888eb84 100644 --- a/BLDC_E54/BLDC_E54/Debug/Makefile +++ b/BLDC_E54/BLDC_E54/Debug/Makefile @@ -76,7 +76,7 @@ C_SRCS += \ ../driver_init.c \ ../ethercat/ethercat_e54.c \ ../examples/driver_examples.c \ -../hal/src/hal_adc_async.c \ +../hal/src/hal_adc_sync.c \ ../hal/src/hal_atomic.c \ ../hal/src/hal_cache.c \ ../hal/src/hal_delay.c \ @@ -86,12 +86,12 @@ C_SRCS += \ ../hal/src/hal_init.c \ ../hal/src/hal_io.c \ ../hal/src/hal_pdec_async.c \ +../hal/src/hal_pwm.c \ ../hal/src/hal_sleep.c \ ../hal/src/hal_spi_m_dma.c \ ../hal/utils/src/utils_assert.c \ ../hal/utils/src/utils_event.c \ ../hal/utils/src/utils_list.c \ -../hal/utils/src/utils_ringbuffer.c \ ../hal/utils/src/utils_syscalls.c \ ../hpl/adc/hpl_adc.c \ ../hpl/ccl/hpl_ccl.c \ @@ -109,7 +109,7 @@ C_SRCS += \ ../hpl/pm/hpl_pm.c \ ../hpl/ramecc/hpl_ramecc.c \ ../hpl/sercom/hpl_sercom.c \ -../hpl/tcc/tcc_lite.c \ +../hpl/tcc/hpl_tcc.c \ ../hpl/tc/tc_lite.c \ ../main.c @@ -128,7 +128,7 @@ Device_Startup/system_same54.o \ driver_init.o \ ethercat/ethercat_e54.o \ examples/driver_examples.o \ -hal/src/hal_adc_async.o \ +hal/src/hal_adc_sync.o \ hal/src/hal_atomic.o \ hal/src/hal_cache.o \ hal/src/hal_delay.o \ @@ -138,12 +138,12 @@ hal/src/hal_gpio.o \ hal/src/hal_init.o \ hal/src/hal_io.o \ hal/src/hal_pdec_async.o \ +hal/src/hal_pwm.o \ hal/src/hal_sleep.o \ hal/src/hal_spi_m_dma.o \ hal/utils/src/utils_assert.o \ hal/utils/src/utils_event.o \ hal/utils/src/utils_list.o \ -hal/utils/src/utils_ringbuffer.o \ hal/utils/src/utils_syscalls.o \ hpl/adc/hpl_adc.o \ hpl/ccl/hpl_ccl.o \ @@ -161,7 +161,7 @@ hpl/pdec/hpl_pdec.o \ hpl/pm/hpl_pm.o \ hpl/ramecc/hpl_ramecc.o \ hpl/sercom/hpl_sercom.o \ -hpl/tcc/tcc_lite.o \ +hpl/tcc/hpl_tcc.o \ hpl/tc/tc_lite.o \ main.o @@ -173,7 +173,7 @@ Device_Startup/system_same54.o \ driver_init.o \ ethercat/ethercat_e54.o \ examples/driver_examples.o \ -hal/src/hal_adc_async.o \ +hal/src/hal_adc_sync.o \ hal/src/hal_atomic.o \ hal/src/hal_cache.o \ hal/src/hal_delay.o \ @@ -183,12 +183,12 @@ hal/src/hal_gpio.o \ hal/src/hal_init.o \ hal/src/hal_io.o \ hal/src/hal_pdec_async.o \ +hal/src/hal_pwm.o \ hal/src/hal_sleep.o \ hal/src/hal_spi_m_dma.o \ hal/utils/src/utils_assert.o \ hal/utils/src/utils_event.o \ hal/utils/src/utils_list.o \ -hal/utils/src/utils_ringbuffer.o \ hal/utils/src/utils_syscalls.o \ hpl/adc/hpl_adc.o \ hpl/ccl/hpl_ccl.o \ @@ -206,7 +206,7 @@ hpl/pdec/hpl_pdec.o \ hpl/pm/hpl_pm.o \ hpl/ramecc/hpl_ramecc.o \ hpl/sercom/hpl_sercom.o \ -hpl/tcc/tcc_lite.o \ +hpl/tcc/hpl_tcc.o \ hpl/tc/tc_lite.o \ main.o @@ -218,7 +218,7 @@ Device_Startup/system_same54.d \ driver_init.d \ ethercat/ethercat_e54.d \ examples/driver_examples.d \ -hal/src/hal_adc_async.d \ +hal/src/hal_adc_sync.d \ hal/src/hal_atomic.d \ hal/src/hal_cache.d \ hal/src/hal_delay.d \ @@ -228,12 +228,12 @@ hal/src/hal_gpio.d \ hal/src/hal_init.d \ hal/src/hal_io.d \ hal/src/hal_pdec_async.d \ +hal/src/hal_pwm.d \ hal/src/hal_sleep.d \ hal/src/hal_spi_m_dma.d \ hal/utils/src/utils_assert.d \ hal/utils/src/utils_event.d \ hal/utils/src/utils_list.d \ -hal/utils/src/utils_ringbuffer.d \ hal/utils/src/utils_syscalls.d \ hpl/adc/hpl_adc.d \ hpl/ccl/hpl_ccl.d \ @@ -251,7 +251,7 @@ hpl/pdec/hpl_pdec.d \ hpl/pm/hpl_pm.d \ hpl/ramecc/hpl_ramecc.d \ hpl/sercom/hpl_sercom.d \ -hpl/tcc/tcc_lite.d \ +hpl/tcc/hpl_tcc.d \ hpl/tc/tc_lite.d \ main.d @@ -263,7 +263,7 @@ Device_Startup/system_same54.d \ driver_init.d \ ethercat/ethercat_e54.d \ examples/driver_examples.d \ -hal/src/hal_adc_async.d \ +hal/src/hal_adc_sync.d \ hal/src/hal_atomic.d \ hal/src/hal_cache.d \ hal/src/hal_delay.d \ @@ -273,12 +273,12 @@ hal/src/hal_gpio.d \ hal/src/hal_init.d \ hal/src/hal_io.d \ hal/src/hal_pdec_async.d \ +hal/src/hal_pwm.d \ hal/src/hal_sleep.d \ hal/src/hal_spi_m_dma.d \ hal/utils/src/utils_assert.d \ hal/utils/src/utils_event.d \ hal/utils/src/utils_list.d \ -hal/utils/src/utils_ringbuffer.d \ hal/utils/src/utils_syscalls.d \ hpl/adc/hpl_adc.d \ hpl/ccl/hpl_ccl.d \ @@ -296,7 +296,7 @@ hpl/pdec/hpl_pdec.d \ hpl/pm/hpl_pm.d \ hpl/ramecc/hpl_ramecc.d \ hpl/sercom/hpl_sercom.d \ -hpl/tcc/tcc_lite.d \ +hpl/tcc/hpl_tcc.d \ hpl/tc/tc_lite.d \ main.d @@ -366,7 +366,7 @@ examples/driver_examples.o: ../examples/driver_examples.c @echo Finished building: $< -hal/src/hal_adc_async.o: ../hal/src/hal_adc_async.c +hal/src/hal_adc_sync.o: ../hal/src/hal_adc_sync.c @echo Building file: $< @echo Invoking: ARM/GNU C Compiler : 6.3.1 $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -x c -mthumb -D__SAME54P20A__ -DDEBUG -DARM_MATH_CM4 -D__FPU_PRESENT=1 -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\arm\CMSIS\5.4.0\CMSIS\Core\Include" -I"../Config" -I".." -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/adc" -I"../hpl/ccl" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/eic" -I"../hpl/evsys" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pdec" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/tc" -I"../hpl/tcc" -I"../hri" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAME54_DFP\1.1.134\include" -Og -ffunction-sections -mlong-calls -g3 -Wall -pedantic -mcpu=cortex-m4 -c -std=gnu99 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" @@ -436,6 +436,13 @@ hal/src/hal_pdec_async.o: ../hal/src/hal_pdec_async.c @echo Finished building: $< +hal/src/hal_pwm.o: ../hal/src/hal_pwm.c + @echo Building file: $< + @echo Invoking: ARM/GNU C Compiler : 6.3.1 + $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -x c -mthumb -D__SAME54P20A__ -DDEBUG -DARM_MATH_CM4 -D__FPU_PRESENT=1 -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\arm\CMSIS\5.4.0\CMSIS\Core\Include" -I"../Config" -I".." -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/adc" -I"../hpl/ccl" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/eic" -I"../hpl/evsys" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pdec" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/tc" -I"../hpl/tcc" -I"../hri" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAME54_DFP\1.1.134\include" -Og -ffunction-sections -mlong-calls -g3 -Wall -pedantic -mcpu=cortex-m4 -c -std=gnu99 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" + @echo Finished building: $< + + hal/src/hal_sleep.o: ../hal/src/hal_sleep.c @echo Building file: $< @echo Invoking: ARM/GNU C Compiler : 6.3.1 @@ -471,13 +478,6 @@ hal/utils/src/utils_list.o: ../hal/utils/src/utils_list.c @echo Finished building: $< -hal/utils/src/utils_ringbuffer.o: ../hal/utils/src/utils_ringbuffer.c - @echo Building file: $< - @echo Invoking: ARM/GNU C Compiler : 6.3.1 - $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -x c -mthumb -D__SAME54P20A__ -DDEBUG -DARM_MATH_CM4 -D__FPU_PRESENT=1 -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\arm\CMSIS\5.4.0\CMSIS\Core\Include" -I"../Config" -I".." -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/adc" -I"../hpl/ccl" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/eic" -I"../hpl/evsys" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pdec" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/tc" -I"../hpl/tcc" -I"../hri" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAME54_DFP\1.1.134\include" -Og -ffunction-sections -mlong-calls -g3 -Wall -pedantic -mcpu=cortex-m4 -c -std=gnu99 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" - @echo Finished building: $< - - hal/utils/src/utils_syscalls.o: ../hal/utils/src/utils_syscalls.c @echo Building file: $< @echo Invoking: ARM/GNU C Compiler : 6.3.1 @@ -597,7 +597,7 @@ hpl/sercom/hpl_sercom.o: ../hpl/sercom/hpl_sercom.c @echo Finished building: $< -hpl/tcc/tcc_lite.o: ../hpl/tcc/tcc_lite.c +hpl/tcc/hpl_tcc.o: ../hpl/tcc/hpl_tcc.c @echo Building file: $< @echo Invoking: ARM/GNU C Compiler : 6.3.1 $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -x c -mthumb -D__SAME54P20A__ -DDEBUG -DARM_MATH_CM4 -D__FPU_PRESENT=1 -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\arm\CMSIS\5.4.0\CMSIS\Core\Include" -I"../Config" -I".." -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/adc" -I"../hpl/ccl" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/eic" -I"../hpl/evsys" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pdec" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/tc" -I"../hpl/tcc" -I"../hri" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAME54_DFP\1.1.134\include" -Og -ffunction-sections -mlong-calls -g3 -Wall -pedantic -mcpu=cortex-m4 -c -std=gnu99 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" diff --git a/BLDC_E54/BLDC_E54/Debug/bldc.o b/BLDC_E54/BLDC_E54/Debug/bldc.o index 46ec334..0467ce0 100644 Binary files a/BLDC_E54/BLDC_E54/Debug/bldc.o and b/BLDC_E54/BLDC_E54/Debug/bldc.o differ diff --git a/BLDC_E54/BLDC_E54/Debug/main.o b/BLDC_E54/BLDC_E54/Debug/main.o index 5f2bbae..d9459bf 100644 Binary files a/BLDC_E54/BLDC_E54/Debug/main.o and b/BLDC_E54/BLDC_E54/Debug/main.o differ diff --git a/BLDC_E54/BLDC_E54/bldc.c b/BLDC_E54/BLDC_E54/bldc.c index f33343c..07380fa 100644 --- a/BLDC_E54/BLDC_E54/bldc.c +++ b/BLDC_E54/BLDC_E54/bldc.c @@ -117,7 +117,6 @@ void BldcInitStruct(BLDCMotor_t *motor) motor->controllers.Pid_Speed.Ki = 0.0f; motor->controllers.Pid_Speed.Kd = 0.0001f; - //motor->controllers.Pid_Speed.Ki = 0.0001f; motor->controllers.Pid_Speed.OutMax_pu = (MOTOR_MAX_CURRENT_IDC_A); motor->controllers.Pid_Speed.OutMin_pu = -(MOTOR_MAX_CURRENT_IDC_A); @@ -147,8 +146,6 @@ void BldcInitFunctions() Motor1.SetDutyCycle = SetM1DutyCycle; Motor2.SetDutyCycle = SetM2DutyCycle; Motor3.SetDutyCycle = SetM3DutyCycle; - - } // ---------------------------------------------------------------------- @@ -383,8 +380,8 @@ void exec_commutation(void) // Set Calculated Duty Cycles // ---------------------------------------------------------------------- Motor1.SetDutyCycle((uint16_t)Motor1.motor_status.duty_cycle); - //Motor2.SetDutyCycle((uint16_t)Motor1.motor_status.duty_cycle); - //Motor3.SetDutyCycle((uint16_t)Motor1.motor_status.duty_cycle); + Motor2.SetDutyCycle((uint16_t)Motor1.motor_status.duty_cycle); + Motor3.SetDutyCycle((uint16_t)Motor1.motor_status.duty_cycle); Motor1.motor_status.cur_comm_step = MOTOR_COMMUTATION_STEPS[Motor1.motor_status.currentHallPattern]; @@ -462,7 +459,7 @@ void DisableMotor(BLDCMotor_t *motor) //------------------------------------------------------------------------------ // pi current control -// Current Feedback +//------------------------------------------------------------------------------ void BLDC_runCurrentCntl(BLDCMotor_t *motor, volatile float curfbk, volatile float curRef) { @@ -494,6 +491,7 @@ void BLDC_runCurrentCntl(BLDCMotor_t *motor, volatile float curfbk, volatile flo //// ------------------------------------------------------------------------------ // Speed Control: Input in RPM units (int16_t) +//------------------------------------------------------------------------------ void BLDC_runSpeedCntl(BLDCMotor_t *motor, volatile float speedfbk, volatile float speedRef) { @@ -531,6 +529,7 @@ void BLDC_runSpeedCntl(BLDCMotor_t *motor, volatile float speedfbk, volatile flo //// ------------------------------------------------------------------------------ // Position Control:Input in Hall step units (int16_t) +//------------------------------------------------------------------------------ void BLDC_runPosCntl(BLDCMotor_t *motor, int16_t posfbk, int16_t posRef) { /* Output Pu in RPM */ diff --git a/BLDC_E54/BLDC_E54/main.c b/BLDC_E54/BLDC_E54/main.c index 9c51b9c..8f924d0 100644 --- a/BLDC_E54/BLDC_E54/main.c +++ b/BLDC_E54/BLDC_E54/main.c @@ -102,15 +102,21 @@ inline void CONTROLLER_StateMachine(void) Motor1.timerflags.motor_telemetry_flag = true; // Update telemetry flag //tic(DEBUG_4); BLDC_runPosCntl(&Motor1, Motor1.motor_status.Num_Steps, Motor1.motor_setpoints.desired_position); + BLDC_runPosCntl(&Motor2, Motor1.motor_status.Num_Steps, Motor1.motor_setpoints.desired_position); + BLDC_runPosCntl(&Motor3, Motor1.motor_status.Num_Steps, Motor1.motor_setpoints.desired_position); //toc(DEBUG_4); case 5: case 10: case 15: case 20:/* PWM FREQ / 5 - 5kHz */ //tic(DEBUG_3); //tic(DEBUG_4); //tic(DEBUG_2); calculate_motor_speed(); + calculate_motor_speed(); + calculate_motor_speed(); //toc(DEBUG_2); //tic(DEBUG_3); BLDC_runSpeedCntl(&Motor1, Motor1.motor_status.calc_rpm, Motor1.controllers.Pid_Speed.Ref_pu); + BLDC_runSpeedCntl(&Motor2, Motor1.motor_status.calc_rpm, Motor1.controllers.Pid_Speed.Ref_pu); + BLDC_runSpeedCntl(&Motor3, Motor1.motor_status.calc_rpm, Motor1.controllers.Pid_Speed.Ref_pu); //toc(DEBUG_3); //toc(DEBUG_4); //toc(DEBUG_3); @@ -118,9 +124,13 @@ inline void CONTROLLER_StateMachine(void) //tic(DEBUG_2); //tic(DEBUG_3); select_active_phase(&Motor1, Motor1.motor_status.currentHallPattern); + select_active_phase(&Motor2, Motor2.motor_status.currentHallPattern); + select_active_phase(&Motor3, Motor3.motor_status.currentHallPattern); ////toc(DEBUG_2); ////tic(DEBUG_3); BLDC_runCurrentCntl(&Motor1, Motor1.Iphase_pu.Bus, Motor1.controllers.Pi_Idc.Ref_pu); + BLDC_runCurrentCntl(&Motor2, Motor1.Iphase_pu.Bus, Motor1.controllers.Pi_Idc.Ref_pu); + BLDC_runCurrentCntl(&Motor3, Motor1.Iphase_pu.Bus, Motor1.controllers.Pi_Idc.Ref_pu); //toc(DEBUG_3); //toc(DEBUG_2); break; @@ -220,9 +230,9 @@ int main(void) if(Motor1.timerflags.current_loop_tic) { Motor1.timerflags.current_loop_tic = false; - //tic_port(DEBUG_1_PORT); + tic_port(DEBUG_1_PORT); CONTROLLER_StateMachine(); - //toc_port(DEBUG_1_PORT); + toc_port(DEBUG_1_PORT); } //do {