Skip to content

Commit

Permalink
Merge branch 'master' into bmw-i3-adc
Browse files Browse the repository at this point in the history
  • Loading branch information
jsphuebner committed May 4, 2021
2 parents 64cff59 + fc2c185 commit 6cd5bd1
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions include/anain_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#define NUM_SAMPLES 12
#define SAMPLE_TIME ADC_SMPR_SMP_7DOT5CYC
#elif CONTROL == CTRL_FOC
#define NUM_SAMPLES 3
#define SAMPLE_TIME ADC_SMPR_SMP_1DOT5CYC
#define NUM_SAMPLES 8
#define SAMPLE_TIME ADC_SMPR_SMP_7DOT5CYC
#endif // CONTROL

#define ANA_IN_LIST \
Expand Down
6 changes: 1 addition & 5 deletions include/hwdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define USART_BAUDRATE 115200
//Maximum PWM frequency is 36MHz/2^MIN_PWM_DIGITS
#define MIN_PWM_DIGITS 11
#define RCC_CLOCK_SETUP rcc_clock_setup_in_hse_8mhz_out_72mhz

#define PWM_TIMER TIM1
#define PWM_TIMRST RST_TIM1
Expand All @@ -25,10 +24,7 @@
#define OVER_CUR_POS hwRev == HW_BLUEPILL ? TIM_OC2 : TIM_OC3

//Address of parameter block in flash
#define FLASH_PAGE_SIZE 1024
#define PARAM_ADDRESS 0x0801FC00
#define PARAM_BLKSIZE FLASH_PAGE_SIZE
#define CANMAP_ADDRESS 0x0801F800
#define PARAM_BLKSIZE 1024

#define REV_CNT_IC hwRev == HW_REV1 ? TIM_IC3 : TIM_IC1
#define REV_CNT_OC hwRev == HW_REV1 ? TIM_OC3 : TIM_OC1
Expand Down
15 changes: 8 additions & 7 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define VER 5.02.R
#define VER 5.05.R

/* Entries must be ordered as follows:
1. Saveable parameters (id != 0)
Expand Down Expand Up @@ -78,6 +78,7 @@
PARAM_ENTRY(CAT_DERATE, idcmax, "A", 0, 5000, 5000, 96 ) \
PARAM_ENTRY(CAT_DERATE, idcmin, "A", -5000, 0, -5000, 98 ) \
PARAM_ENTRY(CAT_DERATE, idckp, "dig", 0.1, 20, 2, 130 ) \
PARAM_ENTRY(CAT_DERATE, idcflt, "dig", 0, 11, 9, 132 ) \
PARAM_ENTRY(CAT_DERATE, tmphsmax, "°C", 50, 150, 85, 125 ) \
PARAM_ENTRY(CAT_DERATE, tmpmmax, "°C", 70, 300, 300, 127 ) \
PARAM_ENTRY(CAT_DERATE, throtmax, "%", 0, 100, 100, 97 ) \
Expand Down Expand Up @@ -176,7 +177,7 @@
VALUE_ENTRY(din_ocur, OKERR, 2030 ) \
VALUE_ENTRY(din_desat, OKERR, 2031 ) \
VALUE_ENTRY(din_bms, ONOFF, 2032 ) \
VALUE_ENTRY(cpuload, "%", 2035 )
VALUE_ENTRY(cpuload, "%", 2035 ) \

#define VALUES_SINE \
VALUE_ENTRY(ilmax, "A", 2005 ) \
Expand All @@ -198,12 +199,12 @@
MOTOR_PARAMETERS_SINE \
MOTOR_PARAMETERS_COMMON \
INVERTER_PARAMETERS_COMMON \
DERATE_PARAMETERS_COMMON \
DERATE_PARAMETERS_SINE \
CHARGER_PARAMETERS \
THROTTLE_PARAMETERS_COMMON \
THROTTLE_PARAMETERS_SINE \
REGEN_PARAMETERS \
DERATE_PARAMETERS_COMMON \
DERATE_PARAMETERS_SINE \
CHARGER_PARAMETERS \
AUTOMATION_CONTACT_PWM_COMM_PARAMETERS \
PARAM_ENTRY(CAT_TEST, fslipspnt, "Hz", -100, 1000, 0, 0 ) \
PARAM_ENTRY(CAT_TEST, ampnom, "%", 0, 100, 0, 0 ) \
Expand All @@ -218,11 +219,11 @@
MOTOR_PARAMETERS_COMMON \
INVERTER_PARAMETERS_COMMON \
INVERTER_PARAMETERS_FOC \
DERATE_PARAMETERS_COMMON \
CHARGER_PARAMETERS \
THROTTLE_PARAMETERS_COMMON \
THROTTLE_PARAMETERS_FOC \
REGEN_PARAMETERS \
DERATE_PARAMETERS_COMMON \
CHARGER_PARAMETERS \
AUTOMATION_CONTACT_PWM_COMM_PARAMETERS \
PARAM_ENTRY(CAT_TEST, manualiq, "A", -400, 400, 0, 0 ) \
PARAM_ENTRY(CAT_TEST, manualid, "A", -400, 400, 0, 0 ) \
Expand Down
2 changes: 1 addition & 1 deletion libopencm3
5 changes: 3 additions & 2 deletions src/hwinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
*/
void clock_setup(void)
{
RCC_CLOCK_SETUP();
rcc_clock_setup_in_hse_8mhz_out_72mhz();

//Run ADC at 12 MHz
rcc_set_adcpre(RCC_CFGR_ADCPRE_PCLK2_DIV6);

//The reset value for PRIGROUP (=0) is not actually a defined
Expand All @@ -60,7 +61,7 @@ void clock_setup(void)
rcc_periph_clock_enable(RCC_TIM2); //Scheduler, over current on blue pill
rcc_periph_clock_enable(RCC_TIM3); //Rotor Encoder
rcc_periph_clock_enable(RCC_TIM4); //Overcurrent / AUX PWM, scheduler on blue pill
rcc_periph_clock_enable(RCC_DMA1); //ADC, Encoder and UART receive
rcc_periph_clock_enable(RCC_DMA1); //ADC, Encoder and UART3
rcc_periph_clock_enable(RCC_ADC1);
rcc_periph_clock_enable(RCC_CRC);
rcc_periph_clock_enable(RCC_AFIO); //CAN
Expand Down
16 changes: 9 additions & 7 deletions src/pwmgeneration-foc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void PwmGeneration::Run()
Encoder::UpdateRotorAngle(dir);

CalcNextAngleSync(dir);
FOC::SetAngle(angle);

frqFiltered = IIRFILTER(frqFiltered, frq, 8);
int moddedKi = curki + kifrqgain * FP_TOINT(frqFiltered);
Expand All @@ -68,7 +69,7 @@ void PwmGeneration::Run()

if (opmode == MOD_RUN && initwait == 0)
{
s32fp fwIdRef = idref <= 0 ? fwController.Run(iq) : 0;
s32fp fwIdRef = idref <= 0 ? fwController.RunProportionalOnly(iq) : 0;
dController.SetRef(idref + fwIdRef);
}
else if (opmode == MOD_MANUAL)
Expand All @@ -82,11 +83,11 @@ void PwmGeneration::Run()
int32_t qlimit = FOC::GetQLimit(ud);
qController.SetMinMaxY(-qlimit, qlimit);
int32_t uq = qController.Run(iq);
FOC::InvParkClarke(ud, uq, angle);
FOC::InvParkClarke(ud, uq);

s32fp idc = (iq * uq + id * ud) / FOC::GetMaximumModulationIndex();
idc = FP_MUL(idc, dcCurFac);
idcFiltered = IIRFILTER(idcFiltered, idc, 10);
idcFiltered = IIRFILTER(idcFiltered, idc, Param::GetInt(Param::idcflt));

Param::SetFlt(Param::fstat, frq);
Param::SetFlt(Param::angle, DIGIT_TO_DEGREE(angle));
Expand Down Expand Up @@ -229,7 +230,6 @@ void PwmGeneration::PwmInit()

s32fp PwmGeneration::ProcessCurrents(s32fp& id, s32fp& iq)
{

if (initwait > 0)
{
initwait--;
Expand All @@ -239,9 +239,9 @@ s32fp PwmGeneration::ProcessCurrents(s32fp& id, s32fp& iq)
s32fp il2 = GetCurrent(AnaIn::il2, ilofs[1], Param::Get(Param::il2gain));

if ((Param::GetInt(Param::pinswap) & SWAP_CURRENTS) > 0)
FOC::ParkClarke(il2, il1, angle);
FOC::ParkClarke(il2, il1);
else
FOC::ParkClarke(il1, il2, angle);
FOC::ParkClarke(il1, il2);
id = FOC::id;
iq = FOC::iq;

Expand All @@ -259,9 +259,11 @@ void PwmGeneration::CalcNextAngleSync(int dir)
{
uint16_t syncOfs = Param::GetInt(Param::syncofs);
uint16_t rotorAngle = Encoder::GetRotorAngle();
int syncadv = (frq - FP_FROMINT(10)) * 10;
syncadv = MAX(0, syncadv);

//Compensate rotor movement that happened between sampling and processing
syncOfs += FP_TOINT(dir * frq * 10);
syncOfs += FP_TOINT(dir * syncadv);

angle = polePairRatio * rotorAngle + syncOfs;
frq = polePairRatio * Encoder::GetRotorFrequency();
Expand Down
1 change: 1 addition & 0 deletions src/stm32_sine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ static void Ms10Task(void)

if (newMode != MOD_OFF)
{
opmode = newMode;
DigIo::dcsw_out.Set();
DigIo::err_out.Clear();
DigIo::prec_out.Clear();
Expand Down

0 comments on commit 6cd5bd1

Please sign in to comment.