bldc/mcpwm.h

96 lines
3.4 KiB
C
Raw Normal View History

2014-01-09 06:20:26 -08:00
/*
2016-11-04 07:18:34 -07:00
Copyright 2016 Benjamin Vedder benjamin@vedder.se
2014-01-09 06:20:26 -08:00
2016-11-04 07:18:34 -07:00
This file is part of the VESC firmware.
The VESC firmware is free software: you can redistribute it and/or modify
2014-01-09 06:20:26 -08:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2016-11-04 07:18:34 -07:00
The VESC firmware is distributed in the hope that it will be useful,
2014-01-09 06:20:26 -08:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MCPWM_H_
#define MCPWM_H_
2014-04-14 14:02:45 -07:00
#include "conf_general.h"
2014-01-09 06:20:26 -08:00
// Functions
2015-12-08 12:01:23 -08:00
void mcpwm_init(volatile mc_configuration *configuration);
void mcpwm_deinit(void);
2016-11-04 07:18:34 -07:00
bool mcpwm_init_done(void);
2015-12-08 12:01:23 -08:00
void mcpwm_set_configuration(volatile mc_configuration *configuration);
void mcpwm_init_hall_table(int8_t *table);
2014-01-09 06:20:26 -08:00
void mcpwm_set_duty(float dutyCycle);
void mcpwm_set_duty_noramp(float dutyCycle);
void mcpwm_set_pid_speed(float rpm);
void mcpwm_set_pid_pos(float pos);
void mcpwm_set_current(float current);
void mcpwm_release_motor(void);
void mcpwm_set_brake_current(float current);
int mcpwm_set_tachometer_value(int steps);
void mcpwm_brake_now(void);
2014-04-12 13:02:22 -07:00
void mcpwm_release_motor(void);
2014-01-09 06:20:26 -08:00
int mcpwm_get_comm_step(void);
2014-04-02 02:54:21 -07:00
float mcpwm_get_duty_cycle_set(void);
2014-04-02 11:23:27 -07:00
float mcpwm_get_duty_cycle_now(void);
float mcpwm_get_switching_frequency_now(void);
2014-01-09 06:20:26 -08:00
float mcpwm_get_rpm(void);
2014-04-02 02:54:21 -07:00
mc_state mcpwm_get_state(void);
2014-01-09 06:20:26 -08:00
float mcpwm_get_kv(void);
float mcpwm_get_kv_filtered(void);
int mcpwm_get_tachometer_value(bool reset);
int mcpwm_get_tachometer_abs_value(bool reset);
2015-12-08 12:01:23 -08:00
void mcpwm_stop_pwm(void);
2014-01-09 06:20:26 -08:00
float mcpwm_get_tot_current(void);
2014-04-02 02:54:21 -07:00
float mcpwm_get_tot_current_filtered(void);
float mcpwm_get_tot_current_directional(void);
float mcpwm_get_tot_current_directional_filtered(void);
2014-01-09 06:20:26 -08:00
float mcpwm_get_tot_current_in(void);
2014-04-02 02:54:21 -07:00
float mcpwm_get_tot_current_in_filtered(void);
2014-01-09 06:20:26 -08:00
void mcpwm_set_detect(void);
2014-03-13 07:28:56 -07:00
float mcpwm_get_detect_pos(void);
void mcpwm_reset_hall_detect_table(void);
int mcpwm_get_hall_detect_result(int8_t *table);
int mcpwm_read_hall_phase(void);
float mcpwm_read_reset_avg_cycle_integrator(void);
void mcpwm_set_comm_mode(mc_comm_mode mode);
mc_comm_mode mcpwm_get_comm_mode(void);
2014-01-09 06:20:26 -08:00
float mcpwm_get_last_adc_isr_duration(void);
float mcpwm_get_last_inj_adc_isr_duration(void);
mc_rpm_dep_struct mcpwm_get_rpm_dep(void);
2015-12-08 12:01:23 -08:00
bool mcpwm_is_dccal_done(void);
void mcpwm_switch_comm_mode(mc_comm_mode next);
2014-01-09 06:20:26 -08:00
2019-02-18 10:30:19 -08:00
void drv8323s_dccal_on(void);
void drv8323s_dccal_off(void);
2014-01-09 06:20:26 -08:00
// Interrupt handlers
void mcpwm_adc_inj_int_handler(void);
void mcpwm_adc_int_handler(void *p, uint32_t flags);
// External variables
2014-03-13 07:28:56 -07:00
extern volatile float mcpwm_detect_currents[];
extern volatile float mcpwm_detect_voltages[];
2014-04-21 07:17:39 -07:00
extern volatile float mcpwm_detect_currents_diff[];
extern volatile int mcpwm_vzero;
2014-01-09 06:20:26 -08:00
/*
* Fixed parameters
2014-01-09 06:20:26 -08:00
*/
#define MCPWM_RPM_TIMER_FREQ 1000000.0 // Frequency of the RPM measurement timer
#define MCPWM_CMD_STOP_TIME 0 // Ignore commands for this duration in msec after a stop has been sent
2014-05-05 11:39:25 -07:00
#define MCPWM_DETECT_STOP_TIME 500 // Ignore commands for this duration in msec after a detect command
2014-01-09 06:20:26 -08:00
// Speed PID parameters
2014-01-09 06:20:26 -08:00
#define MCPWM_PID_TIME_K 0.001 // Pid controller sample time in seconds
2014-01-09 06:20:26 -08:00
#endif /* MC_PWM_H_ */