Implemented PETERS_PLATINE
This commit is contained in:
@ -36,6 +36,7 @@ include_directories(
|
||||
#add_definitions(-DMOTOR_TEST)
|
||||
#add_definitions(-DFEATURE_IGNORE_OTHER_MOTOR)
|
||||
add_definitions(-DFEATURE_BUTTON)
|
||||
#add_definitions(-DPETERS_PLATINE)
|
||||
|
||||
add_executable(firmware.elf
|
||||
STM32CubeF1/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c
|
||||
|
14
config.h
14
config.h
@ -1,12 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#define PWM_FREQ 16000 // PWM frequency in Hz
|
||||
#define DEAD_TIME 48 // PWM deadtime
|
||||
#ifdef MOTOR_TEST
|
||||
#define DELAY_IN_MAIN_LOOP 10
|
||||
#ifdef PETERS_PLATINE
|
||||
#define PWM_FREQ 10000 // PWM frequency in Hz
|
||||
#else
|
||||
#define DELAY_IN_MAIN_LOOP 5
|
||||
#define PWM_FREQ 16000 // PWM frequency in Hz
|
||||
#endif
|
||||
#define DEAD_TIME 48 // PWM deadtime
|
||||
//#ifdef MOTOR_TEST
|
||||
// #define DELAY_IN_MAIN_LOOP 10
|
||||
//#else
|
||||
#define DELAY_IN_MAIN_LOOP 5
|
||||
//#endif
|
||||
#define TIMEOUT 5 // number of wrong / missing input commands before emergency off
|
||||
#define A2BIT_CONV 50 // A to bit for current conversion on ADC. Example: 1 A = 50, 2 A = 100, etc
|
||||
|
||||
|
11
defines.h
11
defines.h
@ -45,14 +45,23 @@
|
||||
#define LEFT_TIM_UL_PIN GPIO_PIN_7
|
||||
#define LEFT_TIM_UL_PORT GPIOA
|
||||
#define LEFT_TIM_V CCR2
|
||||
#ifdef PETERS_PLATINE
|
||||
#define LEFT_TIM_VH_PIN GPIO_PIN_8
|
||||
#define LEFT_TIM_VL_PIN GPIO_PIN_1
|
||||
#else
|
||||
#define LEFT_TIM_VH_PIN GPIO_PIN_7
|
||||
#define LEFT_TIM_VH_PORT GPIOC
|
||||
#define LEFT_TIM_VL_PIN GPIO_PIN_0
|
||||
#endif
|
||||
#define LEFT_TIM_VH_PORT GPIOC
|
||||
#define LEFT_TIM_VL_PORT GPIOB
|
||||
#define LEFT_TIM_W CCR3
|
||||
#define LEFT_TIM_WH_PIN GPIO_PIN_8
|
||||
#define LEFT_TIM_WH_PORT GPIOC
|
||||
#ifdef PETERS_PLATINE
|
||||
#define LEFT_TIM_WL_PIN GPIO_PIN_0
|
||||
#else
|
||||
#define LEFT_TIM_WL_PIN GPIO_PIN_1
|
||||
#endif
|
||||
#define LEFT_TIM_WL_PORT GPIOB
|
||||
|
||||
#define RIGHT_TIM TIM1
|
||||
|
32
main.cpp
32
main.cpp
@ -229,17 +229,17 @@ int main()
|
||||
timeout = 0;
|
||||
|
||||
#ifdef MOTOR_TEST
|
||||
left.state.enable = false;
|
||||
left.state.ctrlMod = ControlMode::Voltage;
|
||||
left.state.ctrlTyp = ControlType::Sinusoidal;
|
||||
left.state.enable = true;
|
||||
left.state.ctrlMod = ControlMode::Torque;
|
||||
left.state.ctrlTyp = ControlType::FieldOrientedControl;
|
||||
left.state.pwm = pwm;
|
||||
left.state.iMotMax = 1;
|
||||
left.state.iMotMax = 10;
|
||||
|
||||
right.state.enable = true;
|
||||
right.state.ctrlMod = ControlMode::Voltage;
|
||||
right.state.ctrlTyp = ControlType::Sinusoidal;
|
||||
right.state.ctrlMod = ControlMode::Torque;
|
||||
right.state.ctrlTyp = ControlType::FieldOrientedControl;
|
||||
right.state.pwm = pwm;
|
||||
right.state.iMotMax = 1;
|
||||
right.state.iMotMax = 10;
|
||||
|
||||
constexpr auto pwmMax = 500;
|
||||
|
||||
@ -302,13 +302,23 @@ void updateMotors()
|
||||
}
|
||||
|
||||
// Get Left motor currents
|
||||
#ifdef PETERS_PLATINE
|
||||
int16_t curL_phaB = (int16_t)(offsetrl1 - adc_buffer.rl1)*2;
|
||||
int16_t curL_phaA = (int16_t)(offsetrl2 - adc_buffer.rl2)*2;
|
||||
#else
|
||||
int16_t curL_phaA = (int16_t)(offsetrl1 - adc_buffer.rl1);
|
||||
int16_t curL_phaB = (int16_t)(offsetrl2 - adc_buffer.rl2);
|
||||
#endif
|
||||
int16_t curL_DC = (int16_t)(offsetdcl - adc_buffer.dcl);
|
||||
|
||||
// Get Right motor currents
|
||||
#ifdef PETERS_PLATINE
|
||||
int16_t curR_phaB = (int16_t)(offsetrr1 - adc_buffer.rr1)*2;
|
||||
int16_t curR_phaC = (int16_t)(offsetrr2 - adc_buffer.rr2)*2;
|
||||
#else
|
||||
int16_t curR_phaB = (int16_t)(offsetrr1 - adc_buffer.rr1);
|
||||
int16_t curR_phaC = (int16_t)(offsetrr2 - adc_buffer.rr2);
|
||||
#endif
|
||||
int16_t curR_DC = (int16_t)(offsetdcr - adc_buffer.dcr);
|
||||
|
||||
const int8_t chopL = std::abs(curL_DC) > (left.state.iDcMax * A2BIT_CONV);
|
||||
@ -813,7 +823,11 @@ void MX_TIM_Init() {
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
#ifdef PETERS_PLATINE
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
#else
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_LOW;
|
||||
#endif
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_SET;
|
||||
@ -854,7 +868,11 @@ void MX_TIM_Init() {
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
#ifdef PETERS_PLATINE
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
#else
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_LOW;
|
||||
#endif
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_SET;
|
||||
|
Reference in New Issue
Block a user