Bayley Wang
/
priustroller_3
temp repo
Fork of priustroller_2 by
core/inverter.cpp@33:e7b132029bae, 2015-03-16 (annotated)
- Committer:
- nki
- Date:
- Mon Mar 16 03:09:48 2015 +0000
- Revision:
- 33:e7b132029bae
- Parent:
- 27:846c08fb3697
New working set - reverted to synchronous current sensor reads
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 "core.h" |
bwang | 1:1f58bdcf2956 | 3 | #include "sensors.h" |
bwang | 0:54cf32d35f4d | 4 | |
bwang | 0:54cf32d35f4d | 5 | Inverter::Inverter(PinName ph_a, PinName ph_b, PinName ph_c, PinName en, VoltageSensor *sense_bus, TempSensor *sense_t) { |
bwang | 0:54cf32d35f4d | 6 | _en = new DigitalOut(en); |
bwang | 0:54cf32d35f4d | 7 | Disable(); |
bwang | 0:54cf32d35f4d | 8 | |
bwang | 0:54cf32d35f4d | 9 | _pwm_a = new PwmOut(ph_a); |
bwang | 0:54cf32d35f4d | 10 | _pwm_b = new PwmOut(ph_b); |
bwang | 0:54cf32d35f4d | 11 | _pwm_c = new PwmOut(ph_c); |
bwang | 0:54cf32d35f4d | 12 | _pwm_a->period_us(100); |
bwang | 0:54cf32d35f4d | 13 | _pwm_b->period_us(100); |
bwang | 0:54cf32d35f4d | 14 | _pwm_c->period_us(100); |
bwang | 0:54cf32d35f4d | 15 | |
bwang | 0:54cf32d35f4d | 16 | _sense_bus = sense_bus; |
bwang | 0:54cf32d35f4d | 17 | _sense_t = sense_t; |
bwang | 0:54cf32d35f4d | 18 | |
bwang | 0:54cf32d35f4d | 19 | SetDtcA(0); |
bwang | 0:54cf32d35f4d | 20 | SetDtcB(0); |
bwang | 0:54cf32d35f4d | 21 | SetDtcC(0); |
bwang | 0:54cf32d35f4d | 22 | |
nki | 33:e7b132029bae | 23 | TIM2->CR1 &= ~(TIM_CR1_CEN); |
nki | 33:e7b132029bae | 24 | TIM2->CR1 |= TIM_CR1_CMS; |
nki | 33:e7b132029bae | 25 | TIM2->CR1 |= TIM_CR1_CEN; |
bwang | 0:54cf32d35f4d | 26 | |
bwang | 0:54cf32d35f4d | 27 | Enable(); |
bwang | 0:54cf32d35f4d | 28 | } |
bwang | 0:54cf32d35f4d | 29 | |
bwang | 0:54cf32d35f4d | 30 | void Inverter::SetDtcA(float dtc) { |
bwang | 0:54cf32d35f4d | 31 | if (dtc < 0) dtc = 0.0f; |
bwang | 0:54cf32d35f4d | 32 | if (dtc > 1.0f) dtc = 1.0f; |
bwang | 11:dccbaa9274c5 | 33 | *_pwm_a = dtc; |
bwang | 0:54cf32d35f4d | 34 | } |
bwang | 0:54cf32d35f4d | 35 | |
bwang | 0:54cf32d35f4d | 36 | void Inverter::SetDtcB(float dtc) { |
bwang | 0:54cf32d35f4d | 37 | if (dtc < 0) dtc = 0.0f; |
bwang | 0:54cf32d35f4d | 38 | if (dtc > 1.0f) dtc = 1.0f; |
nki | 25:0003b824dd7d | 39 | *_pwm_b = dtc; |
bwang | 0:54cf32d35f4d | 40 | } |
bwang | 0:54cf32d35f4d | 41 | |
bwang | 0:54cf32d35f4d | 42 | void Inverter::SetDtcC(float dtc) { |
bwang | 0:54cf32d35f4d | 43 | if (dtc < 0) dtc = 0.0f; |
bwang | 0:54cf32d35f4d | 44 | if (dtc > 1.0f) dtc = 1.0f; |
bwang | 11:dccbaa9274c5 | 45 | *_pwm_c = dtc; |
bwang | 0:54cf32d35f4d | 46 | } |
bwang | 0:54cf32d35f4d | 47 | |
bwang | 0:54cf32d35f4d | 48 | void Inverter::Enable() { |
nki | 25:0003b824dd7d | 49 | *_en = 1; |
bwang | 0:54cf32d35f4d | 50 | } |
bwang | 0:54cf32d35f4d | 51 | |
bwang | 0:54cf32d35f4d | 52 | void Inverter::Disable() { |
nki | 25:0003b824dd7d | 53 | *_en = 0; |
bwang | 0:54cf32d35f4d | 54 | } |
bwang | 0:54cf32d35f4d | 55 | |
bwang | 11:dccbaa9274c5 | 56 | float Inverter::GetVbus() { |
bwang | 11:dccbaa9274c5 | 57 | return _sense_bus->GetVoltage(); |
bwang | 0:54cf32d35f4d | 58 | } |
bwang | 0:54cf32d35f4d | 59 | |
bwang | 11:dccbaa9274c5 | 60 | float Inverter::GetTemp() { |
bwang | 11:dccbaa9274c5 | 61 | return _sense_t->GetTemp(); |
bwang | 0:54cf32d35f4d | 62 | } |