Skip to content

Commit

Permalink
Fixed DRV8301 false fault signal, GUI fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rombrew committed Jan 28, 2024
1 parent e72494d commit bfc3a03
Show file tree
Hide file tree
Showing 37 changed files with 410 additions and 463 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ electric transport.
* Flux weakening and MTPA control (**EXPERIMENTAL**).
* Three and two phase machine support.
* Hardware abstraction layer (HAL) over STM32F4 and STM32F7.
* Various controller boards are supported (including VESC clones).
* Various controller hardware are supported (including VESC clones).
* Regular Command Line Interface (CLI) with autocompletion and history.
* Graphical front-end software based on
[Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) and
Expand Down
6 changes: 3 additions & 3 deletions bench/blm.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void blm_AB_DQ(double theta, double A, double B, double *D, double *Q)
double X, Y, tS, tC;

X = A;
Y = .577350269189626 * A + 1.15470053837925 * B;
Y = 0.577350269189626 * A + 1.15470053837925 * B;

tS = sin(theta);
tC = cos(theta);
Expand All @@ -29,8 +29,8 @@ void blm_DQ_ABC(double theta, double D, double Q, double *A, double *B, double *
Y = tS * D + tC * Q;

*A = X;
*B = - .5 * X + .866025403784439 * Y;
*C = - .5 * X - .866025403784439 * Y;
*B = - 0.5 * X + 0.866025403784439 * Y;
*C = - 0.5 * X - 0.866025403784439 * Y;
}

double blm_Kv_lambda(blm_t *m, double Kv)
Expand Down
38 changes: 19 additions & 19 deletions bench/tsfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,23 +444,23 @@ ts_script_speed()
* pm.const_fb_U / pm.const_lambda;

ts_wait_for_spinup();
sim_runtime(.5);
sim_runtime(0.5);

TS_assert(pm.lu_MODE == PM_LU_ESTIMATE);

m.Mq[0] = - 1.5 * m.Zp * m.lambda * 20.f;
sim_runtime(.5);
sim_runtime(0.5);

m.Mq[0] = 0.f;
sim_runtime(.5);
sim_runtime(0.5);

TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);

pm.s_setpoint_speed = 10.f * pm.k_EMAX / 100.f
* pm.const_fb_U / pm.const_lambda;

ts_wait_for_spinup();
sim_runtime(.5);
sim_runtime(0.5);

TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);

Expand Down Expand Up @@ -488,17 +488,17 @@ ts_script_hfi()
TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);

pm.s_setpoint_speed = 0;
sim_runtime(.5);
sim_runtime(0.5);

TS_assert(pm.lu_MODE == PM_LU_ON_HFI);

pm.s_setpoint_speed = - 1.f / m.lambda;
sim_runtime(.5);
sim_runtime(0.5);

TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);

pm.s_setpoint_speed = 0;
sim_runtime(.5);
sim_runtime(0.5);

m.unsync_flag = 0;

Expand Down Expand Up @@ -528,18 +528,18 @@ ts_script_weakening()
TS_assert(pm.lu_MODE == PM_LU_ESTIMATE);

m.Mq[0] = - 1.5 * m.Zp * m.lambda * 5.f;
sim_runtime(.5);
sim_runtime(0.5);

m.Mq[0] = 0.f;
sim_runtime(.5);
sim_runtime(0.5);

TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);

pm.s_setpoint_speed = 10.f * pm.k_EMAX / 100.f
* pm.const_fb_U / pm.const_lambda;

ts_wait_for_spinup();
sim_runtime(.5);
sim_runtime(0.5);

TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);

Expand All @@ -562,7 +562,7 @@ ts_script_hall()
pm.config_LU_ESTIMATE = PM_FLUX_NONE;
pm.config_LU_SENSOR = PM_SENSOR_HALL;

pm.s_damping = .5f;
pm.s_damping = 0.5f;

pm_auto(&pm, PM_AUTO_LOOP_SPEED);

Expand All @@ -575,23 +575,23 @@ ts_script_hall()
* pm.const_fb_U / pm.const_lambda;

ts_wait_for_spinup();
sim_runtime(.5);
sim_runtime(0.5);

TS_assert(pm.lu_MODE == PM_LU_SENSOR_HALL);

m.Mq[0] = - 1.5 * m.Zp * m.lambda * 20.f;
sim_runtime(.5);
sim_runtime(0.5);

m.Mq[0] = 0.f;
sim_runtime(.5);
sim_runtime(0.5);

TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);

pm.s_setpoint_speed = 10.f * pm.k_EMAX / 100.f
* pm.const_fb_U / pm.const_lambda;

ts_wait_for_spinup();
sim_runtime(.5);
sim_runtime(0.5);

TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);

Expand Down Expand Up @@ -643,13 +643,13 @@ ts_script_eabi(int knob_EABI)
* pm.const_fb_U / pm.const_lambda;

ts_wait_for_spinup();
sim_runtime(.5);
sim_runtime(0.5);

m.Mq[0] = - 1.5 * m.Zp * m.lambda * 20.f;
sim_runtime(.5);
sim_runtime(0.5);

m.Mq[0] = 0.f;
sim_runtime(.5);
sim_runtime(0.5);

TS_assert(pm.lu_MODE == PM_LU_SENSOR_EABI);
TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);
Expand All @@ -658,7 +658,7 @@ ts_script_eabi(int knob_EABI)
* pm.const_fb_U / pm.const_lambda;

ts_wait_for_spinup();
sim_runtime(.5);
sim_runtime(0.5);

TS_assert_absolute(pm.lu_wS, pm.s_setpoint_speed, 50.);

Expand Down
4 changes: 2 additions & 2 deletions doc/CommandLineInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ need to be captured.

Telemetry grab into RAM and flush textual dump.

(pmc) tlm_grab <freq>
(pmc) tlm_grab <rate>
(pmc) tlm_flush_sync

Or live telemetry printout.

(pmc) tlm_live_sync <freq>
(pmc) tlm_live_sync <rate>

Using CAN data pipes you are able to link register across CAN network. You can
easily control many machines from single input. Build a traction control by
Expand Down
17 changes: 9 additions & 8 deletions doc/GettingStarted.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
## Overview

This manual gives a basic info about Phobia Motor Controller (PMC). Look into
other docs for specific issues.
other documents for specific questions.

## Hardware

We do not assemble hardware for sales. You can get fabrication files from our
[releases](https://sourceforge.net/projects/phobia/files/) or look into the PCB
repos. You will have to order the fabrication and assembly yourself.

$ hg clone https://hg.code.sf.net/p/phobia/pcb phobia-pcb
$ git clone https://github.com/rombrew/phobia-pcb.git phobia-pcb

The aim of our PCB design is to optimize electrical and thermal performance.
Expand All @@ -21,13 +20,15 @@ copper foil thickness. To improve heat dissipation it is necessary to mount an
aluminium heatsink at bottom side through thermal interface.

You can also try to use third-party hardware like VESC or its clones. Look into
`src/hal/hw/...` directory to get the actual list of supported hardware.
[Hardware VESC](HardwareVESC.md) document to get an overview of supported
hardware.

## Basic wiring

Plug PMC according to the diagram. If you need to run a bootloader (in case of
erased MCU) then short BOOT pin to +3.3v before the power up.

```
+-----------+
| | +---------------+
| Host PC |-------//------| USART adapter |
Expand All @@ -45,6 +46,7 @@ erased MCU) then short BOOT pin to +3.3v before the power up.
+--------+------+--------------+
| |
+--/ --+
```

## Software

Expand All @@ -65,9 +67,9 @@ There are a few parts of software:
implemented here.

The firmware can be compiled with appropriate [GCC](https://gcc.gnu.org/) or
[Clang](https://clang.llvm.org/) toolchain.
[Clang](https://clang.llvm.org/) toolchain. For example, let us build the
firmware for the `REV5A` hardware.

$ hg clone https://hg.code.sf.net/p/phobia/code phobia
$ git clone https://github.com/rombrew/phobia.git phobia
$ cd phobia/src
$ make HWREV=REV5A
Expand Down Expand Up @@ -116,6 +118,8 @@ embedded bootloader without BOOT pin. Just run the command in the CLI.
Read the following documentation for setting PMC up.

* [Command Line Interface](CommandLineInterface.md)
* [Hardware Design](HardwareDesign.md)
* [Hardware VESC](HardwareVESC.md)
* [Integrity Self Test](IntegritySelfTest.md)
* [Machine Probe](MachineProbe.md)
* [Machine Tuning](MachineTuning.md)
Expand All @@ -126,9 +130,6 @@ Read the following documentation for setting PMC up.
* [Network CAN](NetworkCAN.md)
* [Trouble Shooting](TroubleShooting.md)

* [Hardware Design](HardwareDesign.md)
* [Hardware VESC](HardwareVESC.md)

## Feedback and support

Yuo can contact me on [sourceforge](https://sourceforge.net/projects/phobia/)
Expand Down
25 changes: 20 additions & 5 deletions doc/HardwareDesign.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ six metal–oxide–semiconductor field-effect transistors (MOSFET). The voltage
each of the output terminals is measured. Phase current A and B (optionally
C) is measured. The output terminals are connected to the machine.

```
(VCC) >---+--------+---------+---------+
| | | |
| --FET --FET --FET
Expand All @@ -19,13 +20,15 @@ C) is measured. The output terminals are connected to the machine.
| --FET --FET --FET
| | | |
(GND) >---+--------+---------+---------+
// Three-phase VSI //
```

The three-phase bridge operates as three separate half-bridges. Each of which
can be abstractly considered as controlled voltage source. We use a symmetric
PWM scheme as shown in the diagram.

```
---+ | +-----------------------------+ | +---
| | | |
| | | A = 75\% | | |
Expand All @@ -35,7 +38,7 @@ PWM scheme as shown in the diagram.
| | | |
| B = 50\% |
--------|---------+ +---------|--------
------+ | +-----------------------------------+ | +------
| | | |
| | | C = 90\% | | |
Expand All @@ -44,12 +47,14 @@ PWM scheme as shown in the diagram.
<---------------- dT ----------------->
| |
// Output voltage waveform //
```

Each half-bridge consists of two MOSFETs controlled by a gate drivers with a
specified Dead-Time `DET`. Depending on the direction of the current flow
during the Dead-Time the actual voltage on half-bridge may be different. The
amount of uncertainty in the output voltage `dU` expressed as follows:

```
2 * DET * DC_link_voltage
dU = ---------------------------
dT
Expand Down Expand Up @@ -80,6 +85,7 @@ amount of uncertainty in the output voltage `dU` expressed as follows:
|
|
---
```

The voltage divider (R1, R2) and filter capacitor (C1) are used to measure the
terminal voltage (uA, uB, uC). This RC scheme forms an exponential integrator
Expand All @@ -91,6 +97,7 @@ To get acceptable accuracy you need to make sure that the RC scheme time
constant is comparable to dT. Also make sure that your capacitors are stable
over whole temperature and voltage range.

```
+------< REF
| // Voltage measurement //
|
Expand All @@ -111,6 +118,7 @@ over whole temperature and voltage range.
|
---
\ / AGND
```

The current (iA, iB, iC) is measured in phases A and B (optionally C) using a
shunt and amplifier. Typically the measurement is distorted for some time after
Expand All @@ -119,6 +127,7 @@ a switching of the MOSFETs.
Note that we prefer to use in-line current measurement. To use low-side
measurement you will need to configure the software appropriately.

```
// Current measurement //
>-----+
| (+) |\ R1 = 0.5 mOhm
Expand All @@ -132,6 +141,7 @@ measurement you will need to configure the software appropriately.
| |/
|
+---< Terminal
```

Also supply voltage (uS) is measured using a voltage divider.

Expand All @@ -145,8 +155,9 @@ The values obtained are passed to the main IRQ handler to process. The MCU
software calculates a new value of duty cycle and load it to hw timer. This
value will be used at next PWM period.

```
// Control loop diagram //
-->|<--------------------- dT ---------------------->|<-------------
| |
| TIM update +----+---+----+ PWM |
Expand All @@ -160,15 +171,16 @@ value will be used at next PWM period.
\ / \ ...
pm_feedback() /
proc_set_DC(xA, xB, xC)

```

## Clean zones

We typically need about 5us before current samples to be clean. If MOSFETs
switching occur at this time then ADC result is discarded.

```
// ADC sample clean zones //
-->|<--------------------- dT ---------------------->|<-------------
| |
| PWM +--------+---+--------+ |
Expand All @@ -179,16 +191,19 @@ switching occur at this time then ADC result is discarded.
-->| clearence |<--
| |
-->| skip |<--
```

The diagram above shows `clearance` and `skip` parameters that is used in
software to decide ADC samples further usage. Based on transient performance of
current measurements circuit you should specify clerance thresholds in board
configuration. To get the best result you should have a current sensor with a
fast transient that allows you to specify narrow clearance zone.

```
1 - sqrt(3) / 2
clearance < -----------------
PWM_freq
```

## TODO

Loading

0 comments on commit bfc3a03

Please sign in to comment.