Monitor Track and Booster Power State
DRV8874 fault may be: - over current trip - under volage on VM or charge pump - over temperature
Current Sense
The DRV8874 current sense pin is a current source that produces 450 µA/A of output current. The load resistor on the Pololu board is 2.49 kΩ. I.e .45 mA * 2.49kΩ => 1.1205 V at the sense pin per amp output. The over current circuit will trip when sense pin V is c. 3.3 V - it's the logic high (false) level at _sleep. => 2.95 A. However the continuous rating for the DRV8874 as mounted on the Pololu board is 2.1 A.
The sense reading is a 16 bit number with 65535 corresponding to 3.3 volts. We set thresholds at 1A and 2A.
The thresholds are used to set the NeoPixel colour: - < 1A = pure green - < 2A = yellowish - > 2A = orange The DCC monitor is a singleton class that monitors the DCC status and updates the NeoPixel accordingly. It uses a statistical median filter and an Infinite Impulse Response (IIR) filter to smooth the current sense reading and the zero offset to remove the zero offset when the DCC is asleep. The statistical median filter is non linear and removes outlying values.The IIR filter is implemented using a simple formula:
new_value = (old_value * (FILTER_FACTOR - 1) /FILTER_FACTOR + (new_reading / FILTER_FACTOR)
where FILTER_FACTOR is a constant that determines the amount of filtering applied. The zero offset is calculated when the DCC is asleep and is used to remove the zero offset from the current sense reading when the DCC is awake. The zero offset is also filtered using the same IIR filter formula.
This code is intended to run on the second core (core1) and cannot use preemptive code such as timer callbacks or interrupts.
| Class Method | get |
Get the Track Monitor instance. |
| Method | __init__ |
Initialise the Track Monitor |
| Method | get |
Get the current |
| Method | scan |
Scan the DCC status and update the NeoPixel accordingly. |
| Constant | BRIGHT |
NeoLed default brightness. |
| Constant | DRV |
convert the raw sensor reading to current in mA. |
| Constant | FILTER |
The IIR filter factor for reading. |
| Constant | FILTER |
The IIR filter ratio ((filter factor - 1)/filter factor) |
| Constant | SCAN |
The time interval between scans in ms. |
| Constant | STAT |
The index of the median value within the value list. |
| Constant | STAT |
The size of the statistical median filter (must be odd). |
| Constant | THRESHOLD |
The threshold for 1A in the current sense reading. |
| Constant | THRESHOLD |
The threshold for 2A in the current sense reading. |
| Constant | Z |
IIR filter factor for zero offest |
| Constant | Z |
The 0 offset filter ratio ((filter factor - 1)/filter factor) |
| Class Variable | _this |
Undocumented |
| Instance Variable | _enable |
Undocumented |
| Instance Variable | _fault |
Undocumented |
| Instance Variable | _led |
Undocumented |
| Instance Variable | _next |
Undocumented |
| Instance Variable | _readings |
Undocumented |
| Instance Variable | _sense |
Undocumented |
| Instance Variable | _sense |
Undocumented |
| Instance Variable | _sense |
Undocumented |
| Instance Variable | _sleep |
Undocumented |
Get the Track Monitor instance.
This returns the singleton instance of the Track/Booster Monitor.
Instantiate the singleton on the first call.
| Parameters | |
| cls | |
| Returns | |
| The Track monitor instance |
Initialise the Track Monitor
This initialises the Monitor with the pins that it will use to monitor the DCC status.
- Reads the following from hardware configuration
- _sleep_pin: The pin that is low when the DRV8874 is asleep. _enable_pin: The pin that is high when the DRV8874 is enabled. _fault_pin: The pin that is low when there is a fault. _sense_pin: The pin that reads the current sense voltage.
Scan the DCC status and update the NeoPixel accordingly.
This scans the DCC status and updates the NeoPixel accordingly. This method is called periodically to update the DCC status and NeoPixel. It checks the fault pin, sleep pin, and enable pin to determine the DCC status and updates the NeoPixel accordingly. If the fault pin is low, it indicates a fault condition and the NeoPixel is set to blue. If the sleep pin is low, it indicates that the DCC is asleep and the current sense reading is updated to the zero offset. If the enable pin is low, it indicates that the DCC is in a cutout condition and the NeoPixel is set to blue if the fault pin is low, otherwise it is set to red.
If the DCC is awake, the current sense reading is updated and the NeoPixel is set to green, yellowish, or orange depending on the current sense reading. The NeoPixel is updated with the appropriate RGB values based on the current sense reading.
The method also updates the next run time to be 100 ms in the future.
convert the raw sensor reading to current in mA.
| Value |
|
The IIR filter ratio ((filter factor - 1)/filter factor)
| Value |
|
The index of the median value within the value list.
| Value |
|
The 0 offset filter ratio ((filter factor - 1)/filter factor)
| Value |
|