Bayley Wang
/
priustroller
Prius IPM controller
Fork of analoghalls5_5 by
sensors/tempsensors.cpp@35:83cf9564bd0c, 2015-03-16 (annotated)
- Committer:
- bwang
- Date:
- Mon Mar 16 15:40:07 2015 +0000
- Revision:
- 35:83cf9564bd0c
- Parent:
- 33:e7b132029bae
Set for 3A Iq, 0A Id, Ki = 1e-3, Kp = Kd = 0, loop still oscillates but is passable
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 0:54cf32d35f4d | 1 | #include "includes.h" |
bwang | 1:1f58bdcf2956 | 2 | #include "sensors.h" |
bwang | 0:54cf32d35f4d | 3 | |
bwang | 0:54cf32d35f4d | 4 | NtcTempSensor::NtcTempSensor(PinName pin, float r_25, float ntc_b, float r_divider) { |
nki | 33:e7b132029bae | 5 | _in = new AnalogIn(pin); |
bwang | 0:54cf32d35f4d | 6 | _ntc_b = ntc_b; |
bwang | 0:54cf32d35f4d | 7 | _ntc_a = r_25 / exp(_ntc_b / 298.0f); |
bwang | 0:54cf32d35f4d | 8 | _r_divider = r_divider; |
bwang | 0:54cf32d35f4d | 9 | } |
bwang | 0:54cf32d35f4d | 10 | |
bwang | 0:54cf32d35f4d | 11 | float NtcTempSensor::GetTemp() { |
bwang | 0:54cf32d35f4d | 12 | float v = (float) *_in * 3.3f; |
bwang | 0:54cf32d35f4d | 13 | float r_n = v * _r_divider / (1.0f + v); |
bwang | 0:54cf32d35f4d | 14 | return _ntc_b / log (r_n / _ntc_a); |
bwang | 0:54cf32d35f4d | 15 | } |