Updated Software description (markdown)
1 parent
5b1cd54e7d
commit
1246539dea
1 file changed
+33
-1
+33
-1
@@ -13,13 +13,45 @@ The Software is structured as follows:
|
||||
|
||||
Conveniently The Raspberry Pi Foundation provides a complete and well documented [SDK](https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf) for the RP2040. The SDK provides abstraction to a higher level and therefore there is no need to directly access any Registers directly. Everything is written using the SDK so hopefully the code is easier to understand. In the following, the motor control and the decoding of the DCC signals will be explained in particular.
|
||||
|
||||
Motor Control
|
||||
Motor control overview
|
||||
-------------------------------------
|
||||

|
||||
***
|
||||
**Block diagram - Motor control**
|
||||
|
||||
The above block diagram in essence describes the functionality of the control loop. While the central component is the PID controller, there are two other blocks that have an impact on the control output variable(pid.output). Firstly there is an additional block to counteract initial friction of the motor, this block only contributes to pid.output when the desired motor speed is very low. The second additional block establishes a baseline PWM offset which is necessary due to the motor having a certain threshold PWM level after which it starts spinning. The offset is adjusted when the absolute value of pid.e_sum reaches half of its limit. The speed helper block is corresponding to the speed_helper() function which sets the current target speed according to the configured deceleration/acceleration rates.
|
||||
|
||||
|
||||
PID Controller
|
||||
-------------------------------------
|
||||

|
||||
|
||||
The block diagram above shows the PID controller in the s-domain. The derivative part contains an additional digital low pass filter used to filter out high-frequency noise.
|
||||
|
||||
Output = E * (K<sub>P</sub> + K<sub>I</sub>/s + (K<sub>D</sub>*s)/(sτ+1)) = P + I + D
|
||||
|
||||
* P = E * K<sub>P</sub>
|
||||
* I = E * K<sub>I</sub>/s
|
||||
* D = E * (K<sub>D</sub>*s)/(sτ+1)
|
||||
|
||||
The continuous-time system representation can now be transformed into a discrete-time representation using bilinear transform [ s = 2*(z-1) / T<sub>s</sub>*(z+1) ].
|
||||
|
||||
This results in the following difference equations which are then implemented in software:
|
||||
|
||||
* p<sub>n</sub> = K<sub>P</sub> * e<sub>n</sub>
|
||||
* i<sub>n</sub> = 0.5K<sub>I</sub> * (e<sub>n</sub> + e<sub>n-1</sub>) + i<sub>n-1</sub>
|
||||
* d<sub>n</sub> = [ 2K<sub>D</sub> * (e<sub>n</sub> - e<sub>n-1</sub>) + (2τ - T<sub>s</sub>) * d<sub>n-1</sub> ] / [ 2τ + T<sub>s</sub>]
|
||||
|
||||
=> output<sub>n</sub> = p<sub>n</sub> + i<sub>n</sub> + d<sub>n</sub>
|
||||
|
||||
Also note that instead of using derivative of error, derivative on measurement is used. This is done to prevent a high derivative part in the event of a large change in setpoint.
|
||||
|
||||

|
||||
|
||||
Another aspect to consider is the implementation of gain scheduling. K<sub>P</sub> is a function of the current setpoint. Often it is favorable to have a higher proportional gain K<sub>P</sub> for slow speed. The illustration above shows the default setting. CV_54 & CV_55 are used to set K<sub>P</sub> @ x<sub>0</sub>, CV_56 & CV_57 for K<sub>P</sub> @ x<sub>1</sub> and CV_58 & CV_59 for K<sub>P</sub> @ x<sub>2</sub>. Additionally CV_60 is used to shift x<sub>1</sub> from the leftmost point (0% = 0/255) to the rightmost point (100% = 255/255).
|
||||
|
||||
|
||||
|
||||
DCC signal decoding
|
||||
-------------------------------------
|
||||
The detection of the DCC is very simple, it works by looking at every rising and falling edge and calculating the time between them. When the time between rising and falling edge is greater than 87μs then this is equivalent to "0", else "1".
|
||||
|
||||
Reference in new issue
Block a user