---
# System prepended metadata

title: APPS
tags: [NTURT, electrical_system, firmware_hardware]

---

# APPS
###### tags: `firmware_hardware` `electrical_system` `NTURT`

Rules: T4.1

#### Transfer function: 
1. different positive slope
2. different offset

any one of the 2, as long as 2 transfer function only intersects at 0%.

#### Implausibility: 
1. \>10% travel deviation
2. open circuit
3. short circuit

2 and 3 must generate a signal outside of the normal voltage range

Implausibility >100ms must shut down the motors

## EP4
KPM22 50mm electrical travel constrained to 2.5~39.5mm
VDDA: 3.3V
VSSA: Gnd
R: 5k Ohm +-5%
max output resistance of sensor: 2.5k/2 = 1250 Ohm
ADC: 12 bit or 10 bit SAR ADC on STM32

#### 100% travel
2.5mm
250 + 4750
3.14V
3891 @12bit ADC

#### 0% travel
39.5mm
3950 + 1050
0.69V
860 @12bit ADC

#### implausibility: short to GND
At 100% travel: 
R = 250 Ohm from Vref to Gnd
13.2 mA if Vref = 3.3V

#### implausibility: short to high
At 0% travel:
R = 1050 Ohm from Vref to Gnd
3.14mA if Vref = 3.3V


### circuit design
1 APPS connects to VDDA and Gnd
1 APPS connects VDDA/2 and Gnd

VDDA/2 is provided by a voltage divider connected to a unity gain buffer.
OpAmp of choice is LM358
(Other once considered candidate: MCP600x, MCP602x, MCP602, OP07, TL072, TL082, AD8551)

#### reasonable region
The sensors are constrained to 2.5mm to 39.5mm travel. 
On APPS1 this is 860~3891 out of the total 12bit range.
On APPS2 this is 430~1946 out of the total 12bit range.
if the numbers fall out of this it is an implausibility.

#### open circuit
pulldown resistor is connected to the output (10k to 100k) so that output=0 when the sensor is disconnected
TBD: resistor value

upper limit: strong enough to pull the ADC input high [[datasheet]](https://www.st.com/resource/en/datasheet/stm32h723ve.pdf)
R_AINmax for 16bit ADC @8bit: 26.5k w/ 2 LSB tolerance
R_AINmax for 12bit ADC @8bit: 12k w/ 2 LSB tolerance

lower limit: weak enough to not effect the readings too much 
max deviation due to pull down is when the wiper is at the middle. That is, R_O = 1250 and V_O = V_I/2

100k pull down correspond to 1.23% deviation at R_O=1250.
10k pull down correspond to 11% deviation at R_O=1250.

 - 5/19 test
ADCclock 96MHz
10bit resolution 
ADC IN5
sampling time: 64.5cycles
84k pulldown: 30~36
510k pulldown: 32~37
56R pulldown: 30~32
84k pullup: 885~890
2k pullup: 1023
short to Gnd: 28~35
open: 94~150
output wiggles when you wiggles the resistor(direcly put on the pins). bigger the value, bigger the wiggle.


#### short circuit
If the outputs short to Gnd or V_I, the number should immediately fall out of the usable range.

In a short circuit, the sensor might draw more current.(In normal condition the sensor draws a constant V_I/5 mA) Their values are caculated above.
LM358 can withstand a short circuit to Gnd. But the maximum output current is ~40mA. It should be enough to keep the calculated voltages intact despite the excess current.

TBD: There are mechanical errors in sensors. So it should be tested whether the current won't stress the OpAmp too much.

#### transfer function

|  | APPS1 | APPS2 |
| -------- | -------- | -------- |
| 0%     | 0.69     | 0.35     |
| 20%     | 1.18     | 0.59     |
| 40%     | 1.63     | 0.82     |
| 60%     | 2.16     | 1.08     |
| 80%     | 2.65     | 1.32     |
| 100%     | 3.14     | 1.57     |

## EP5
Choosing new APPS

criteria:
1. balanced signal for better EMI immunity
2. simple and detectable failure mode including stuff in T.4
3. digital APPS requires FMEA satisfaction - [FMEA form](https://fsaeonline.com/cdsweb/gen/DownloadDocument.aspx?DocumentID=a757fccd-24e3-4e51-ad47-6f60117b20eb)

candidate:
* AMT21: 12/14 bit RS485 rotary encoder. same physical dimension as AMT22 used as steering encoder on EP4 [RS485 explained](https://www.cuidevices.com/blog/rs-485-serial-interface-explained)

big nono:
* quadrature encoder: signal wire disconnection is undetectable
* potentiometer: high impedance single ended signal is vulnerable to EMI attacks

### AMT21
absolute rotary position sensor that transmit 12 bit or 14 bit info in RS485.
#### transmisson time
2 speed for RS485: 2Mbps or 115200bps
turnaround time: 3us min or 10.8 us min
1 stop bit, no parity
1 byte for command; 2 byte of data

transmission time for 2Mbps model:
0.5\*10\*3 + 3 = 18us

transmission time for 115200bps model
1/115200 \*10\*3 \*1000000 + 10.8 = 271us

#### error detection
* short circuit between A and B:
SN65HVD72 force receiver output to get stuck at high -> timeout -> 0 output torque (still need experiment)
* open circuit on either A or B:
timeout -> 0 output torque
~~SN65HVD72 have receiver output to be high but noise margin is low
TODO: do we need additional circuit to split A and B on open circuit.~~
* either A or B short circuit to 5V or Gnd
timeout -> 0 output torque
~~I don't know for now
TODO: can the message still go through
TODO: should we actively look for this scenario
TODO: would SN65HVD72(transmitter) break if this happens.~~
* power goes down - either Gnd or 5V line breaks
sensor powers down -> timeout
* corruption of messages
some bit gets messed up -> checksum fails

* either APPS1 A or B short to APPS2 A or B
Basicly the message will be corrupted, hence the ckecksum will fail, and . even if the message gets transfered successfully, two APPS has different ID. if the receiver for APPS1 recieves a return message that has id that does not belong to APPS1, MCU will also report error and output 0 torque.

#### Installation and code implementation
![image](https://hackmd.io/_uploads/BJf1P8SlR.png)

[data sheet](https://datasheet.octopart.com/AMT212A-V-CUI-datasheet-134027247.pdf)