Skip to content

Commit 8dbdb1b

Browse files
committed
Set new tachometer value interface added.
1 parent 23e6192 commit 8dbdb1b

6 files changed

+64
-0
lines changed

mc_interface.c

+21
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,27 @@ float mc_interface_get_abs_motor_current_unbalance(void) {
982982
return ret;
983983
}
984984

985+
int mc_interface_set_tachometer_value(int steps)
986+
{
987+
int ret = 0;
988+
switch (m_conf.motor_type)
989+
{
990+
case MOTOR_TYPE_BLDC:
991+
case MOTOR_TYPE_DC:
992+
ret = mcpwm_set_tachometer_value(DIR_MULT * steps);
993+
break;
994+
995+
case MOTOR_TYPE_FOC:
996+
ret = mcpwm_foc_set_tachometer_value(DIR_MULT * steps);
997+
break;
998+
999+
default:
1000+
break;
1001+
}
1002+
1003+
return DIR_MULT * ret;
1004+
}
1005+
9851006
int mc_interface_get_tachometer_value(bool reset) {
9861007
int ret = 0;
9871008

mc_interface.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void mc_interface_set_current_rel(float val);
4444
void mc_interface_set_brake_current_rel(float val);
4545
void mc_interface_set_handbrake(float current);
4646
void mc_interface_set_handbrake_rel(float val);
47+
int mc_interface_set_tachometer_value(int steps);
4748
void mc_interface_brake_now(void);
4849
void mc_interface_release_motor(void);
4950
float mc_interface_get_duty_cycle_set(void);

mcpwm.c

+20
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,26 @@ float mcpwm_get_tot_current_in_filtered(void) {
832832
return mcpwm_get_tot_current_filtered() * fabsf(dutycycle_now);
833833
}
834834

835+
/**
836+
* Set the number of steps the motor has rotated. This number is signed and
837+
* becomes a negative when the motor is rotating backwards.
838+
*
839+
* @param steps
840+
* New number of motor steps will be set after this call.
841+
*
842+
* @return
843+
* The previous tachometer value in motor steps. The number of motor revolutions will
844+
* be this number divided by (3 * MOTOR_POLE_NUMBER).
845+
*/
846+
int mcpwm_set_tachometer_value(int steps)
847+
{
848+
int val = tachometer;
849+
850+
tachometer = steps;
851+
852+
return val;
853+
}
854+
835855
/**
836856
* Read the number of steps the motor has rotated. This number is signed and
837857
* will return a negative number when the motor is rotating backwards.

mcpwm.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void mcpwm_set_pid_speed(float rpm);
3434
void mcpwm_set_pid_pos(float pos);
3535
void mcpwm_set_current(float current);
3636
void mcpwm_set_brake_current(float current);
37+
int mcpwm_set_tachometer_value(int steps);
3738
void mcpwm_brake_now(void);
3839
void mcpwm_release_motor(void);
3940
int mcpwm_get_comm_step(void);

mcpwm_foc.c

+20
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,26 @@ float mcpwm_foc_get_tot_current_in_filtered(void) {
958958
return m_motor_state.i_bus; // TODO: Calculate filtered current?
959959
}
960960

961+
/**
962+
* Set the number of steps the motor has rotated. This number is signed and
963+
* becomes a negative when the motor is rotating backwards.
964+
*
965+
* @param steps
966+
* New number of steps will be set after this call.
967+
*
968+
* @return
969+
* The previous tachometer value in motor steps. The number of motor revolutions will
970+
* be this number divided by (3 * MOTOR_POLE_NUMBER).
971+
*/
972+
int mcpwm_foc_set_tachometer_value(int steps)
973+
{
974+
int val = m_tachometer;
975+
976+
m_tachometer = steps;
977+
978+
return val;
979+
}
980+
961981
/**
962982
* Read the number of steps the motor has rotated. This number is signed and
963983
* will return a negative number when the motor is rotating backwards.

mcpwm_foc.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void mcpwm_foc_set_openloop(float current, float rpm);
4343
void mcpwm_foc_set_openloop_phase(float current, float phase);
4444
void mcpwm_foc_set_openloop_duty(float dutyCycle, float rpm);
4545
void mcpwm_foc_set_openloop_duty_phase(float dutyCycle, float phase);
46+
int mcpwm_foc_set_tachometer_value(int steps);
4647
float mcpwm_foc_get_duty_cycle_set(void);
4748
float mcpwm_foc_get_duty_cycle_now(void);
4849
float mcpwm_foc_get_pid_pos_set(void);

0 commit comments

Comments
 (0)