Compare commits
2 Commits
test_firmw
...
peter-reba
Author | SHA1 | Date | |
---|---|---|---|
aa589cb565 | |||
985cfdd802 |
Submodule bobbycar-foc-model updated: 24e9a0af18...e41c8c605c
2
config.h
2
config.h
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define PWM_FREQ 16000 // PWM frequency in Hz
|
||||
#define PWM_FREQ 10000 // PWM frequency in Hz
|
||||
#define DEAD_TIME 48 // PWM deadtime
|
||||
#ifdef VARIANT_TRANSPOTTER
|
||||
#define DELAY_IN_MAIN_LOOP 2
|
||||
|
17
defines.h
17
defines.h
@ -39,22 +39,25 @@
|
||||
#define RIGHT_HALL_W_PORT GPIOC
|
||||
|
||||
#define LEFT_TIM TIM8
|
||||
|
||||
#define LEFT_TIM_U CCR1
|
||||
#define LEFT_TIM_UH_PIN GPIO_PIN_6
|
||||
#define LEFT_TIM_UH_PORT GPIOC
|
||||
#define LEFT_TIM_UL_PIN GPIO_PIN_7
|
||||
#define LEFT_TIM_UL_PORT GPIOA
|
||||
|
||||
#define LEFT_TIM_V CCR2
|
||||
#define LEFT_TIM_VH_PIN GPIO_PIN_7
|
||||
#define LEFT_TIM_VH_PORT GPIOC
|
||||
#define LEFT_TIM_VL_PIN GPIO_PIN_0
|
||||
#define LEFT_TIM_VL_PORT GPIOB
|
||||
#define LEFT_TIM_W CCR3
|
||||
#define LEFT_TIM_WH_PIN GPIO_PIN_8
|
||||
#define LEFT_TIM_WH_PIN GPIO_PIN_7
|
||||
#define LEFT_TIM_WH_PORT GPIOC
|
||||
#define LEFT_TIM_WL_PIN GPIO_PIN_1
|
||||
#define LEFT_TIM_WL_PIN GPIO_PIN_0
|
||||
#define LEFT_TIM_WL_PORT GPIOB
|
||||
|
||||
#define LEFT_TIM_W CCR3
|
||||
#define LEFT_TIM_VH_PIN GPIO_PIN_8
|
||||
#define LEFT_TIM_VH_PORT GPIOC
|
||||
#define LEFT_TIM_VL_PIN GPIO_PIN_1
|
||||
#define LEFT_TIM_VL_PORT GPIOB
|
||||
|
||||
#define RIGHT_TIM TIM1
|
||||
#define RIGHT_TIM_U CCR1
|
||||
#define RIGHT_TIM_UH_PIN GPIO_PIN_8
|
||||
|
30
main.cpp
30
main.cpp
@ -165,7 +165,7 @@ int main()
|
||||
HAL_ADC_Start(&hadc2);
|
||||
|
||||
left.rtP = rtP_Left;
|
||||
left.rtP.b_selPhaABCurrMeas = 1; // Left motor measured current phases = {iA, iB} -> do NOT change
|
||||
left.rtP.z_selPhaCurMeasABC = 1; // Left motor measured current phases = {iA, iB} -> do NOT change
|
||||
left.rtP.z_ctrlTypSel = uint8_t(left.state.ctrlTyp);
|
||||
left.rtP.b_diagEna = DIAG_ENA;
|
||||
left.rtP.i_max = (left.state.iMotMax * A2BIT_CONV) << 4; // fixdt(1,16,4)
|
||||
@ -181,7 +181,7 @@ int main()
|
||||
left.rtM.outputs = &left.rtY;
|
||||
|
||||
right.rtP = rtP_Left;
|
||||
right.rtP.b_selPhaABCurrMeas = 0; // Left motor measured current phases = {iB, iC} -> do NOT change
|
||||
right.rtP.z_selPhaCurMeasABC = 1; // Left motor measured current phases = {iB, iC} -> do NOT change
|
||||
right.rtP.z_ctrlTypSel = uint8_t(right.state.ctrlTyp);
|
||||
right.rtP.b_diagEna = DIAG_ENA;
|
||||
right.rtP.i_max = (right.state.iMotMax * A2BIT_CONV) << 4; // fixdt(1,16,4)
|
||||
@ -218,21 +218,21 @@ int main()
|
||||
const int pwmMax = 1000;
|
||||
|
||||
for (;;) {
|
||||
HAL_Delay(DELAY_IN_MAIN_LOOP * 2); //delay in ms
|
||||
HAL_Delay(DELAY_IN_MAIN_LOOP ); //delay in ms
|
||||
|
||||
timeout = 0;
|
||||
|
||||
left.state.enable = false;
|
||||
left.state.ctrlMod = ControlMode::Voltage;
|
||||
left.state.ctrlTyp = ControlType::Sinusoidal;
|
||||
left.state.enable = true;
|
||||
left.state.ctrlMod = ControlMode::Voltage;//FieldOrientedControl
|
||||
left.state.ctrlTyp = ControlType::FieldOrientedControl;//Sinusoidal;
|
||||
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.ctrlTyp = ControlType::FieldOrientedControl;
|
||||
right.state.pwm = pwm;
|
||||
right.state.iMotMax = 1;
|
||||
right.state.iMotMax = 10;
|
||||
|
||||
pwm += dir;
|
||||
if (pwm > pwmMax) {
|
||||
@ -288,13 +288,13 @@ void updateMotors()
|
||||
}
|
||||
|
||||
// Get Left motor currents
|
||||
int16_t curL_phaA = (int16_t)(offsetrl1 - adc_buffer.rl1);
|
||||
int16_t curL_phaB = (int16_t)(offsetrl2 - adc_buffer.rl2);
|
||||
int16_t curL_phaB = (int16_t)(offsetrl1 - adc_buffer.rl1)*2;
|
||||
int16_t curL_phaA = (int16_t)(offsetrl2 - adc_buffer.rl2)*2;
|
||||
int16_t curL_DC = (int16_t)(offsetdcl - adc_buffer.dcl);
|
||||
|
||||
// Get Right motor currents
|
||||
int16_t curR_phaB = (int16_t)(offsetrr1 - adc_buffer.rr1);
|
||||
int16_t curR_phaC = (int16_t)(offsetrr2 - adc_buffer.rr2);
|
||||
int16_t curR_phaB = (int16_t)(offsetrr1 - adc_buffer.rr1)*2;
|
||||
int16_t curR_phaC = (int16_t)(offsetrr2 - adc_buffer.rr2)*2;
|
||||
int16_t curR_DC = (int16_t)(offsetdcr - adc_buffer.dcr);
|
||||
|
||||
const int8_t chopL = std::abs(curL_DC) > (left.state.iDcMax * A2BIT_CONV);
|
||||
@ -792,7 +792,7 @@ void MX_TIM_Init() {
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_LOW;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_SET;
|
||||
@ -833,7 +833,7 @@ void MX_TIM_Init() {
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_LOW;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_SET;
|
||||
|
Reference in New Issue
Block a user