Bayley Wang
/
priustroller_3
temp repo
Fork of priustroller_2 by
inverter.cpp@6:99ee0ce47fb2, 2015-03-04 (annotated)
- Committer:
- nki
- Date:
- Wed Mar 04 15:33:32 2015 +0000
- Revision:
- 6:99ee0ce47fb2
- Parent:
- 1:1f58bdcf2956
- Child:
- 7:76d6ceb23e0d
3/4;
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 | |
bwang | 0:54cf32d35f4d | 23 | TIM2->CR1 &= ~(TIM_CR1_CEN); |
bwang | 0:54cf32d35f4d | 24 | TIM2->CR1 |= TIM_CR1_CMS; |
bwang | 0:54cf32d35f4d | 25 | TIM2->CR1 |= TIM_CR1_CEN; |
bwang | 0:54cf32d35f4d | 26 | |
bwang | 0:54cf32d35f4d | 27 | UpdateVbus(); |
bwang | 0:54cf32d35f4d | 28 | UpdateTemp(); |
bwang | 0:54cf32d35f4d | 29 | Enable(); |
bwang | 0:54cf32d35f4d | 30 | } |
bwang | 0:54cf32d35f4d | 31 | |
bwang | 0:54cf32d35f4d | 32 | void Inverter::SetDtcA(float dtc) { |
bwang | 0:54cf32d35f4d | 33 | if (dtc < 0) dtc = 0.0f; |
bwang | 0:54cf32d35f4d | 34 | if (dtc > 1.0f) dtc = 1.0f; |
nki | 6:99ee0ce47fb2 | 35 | *_pwm_a = dtcA = dtc; |
bwang | 0:54cf32d35f4d | 36 | } |
bwang | 0:54cf32d35f4d | 37 | |
bwang | 0:54cf32d35f4d | 38 | void Inverter::SetDtcB(float dtc) { |
bwang | 0:54cf32d35f4d | 39 | if (dtc < 0) dtc = 0.0f; |
bwang | 0:54cf32d35f4d | 40 | if (dtc > 1.0f) dtc = 1.0f; |
nki | 6:99ee0ce47fb2 | 41 | *_pwm_b = dtcB = 1.0f - dtc; |
bwang | 0:54cf32d35f4d | 42 | } |
bwang | 0:54cf32d35f4d | 43 | |
bwang | 0:54cf32d35f4d | 44 | void Inverter::SetDtcC(float dtc) { |
bwang | 0:54cf32d35f4d | 45 | if (dtc < 0) dtc = 0.0f; |
bwang | 0:54cf32d35f4d | 46 | if (dtc > 1.0f) dtc = 1.0f; |
nki | 6:99ee0ce47fb2 | 47 | *_pwm_c = dtcC = dtc; |
bwang | 0:54cf32d35f4d | 48 | } |
bwang | 0:54cf32d35f4d | 49 | |
bwang | 0:54cf32d35f4d | 50 | void Inverter::Enable() { |
bwang | 0:54cf32d35f4d | 51 | *_en = 0; |
bwang | 0:54cf32d35f4d | 52 | } |
bwang | 0:54cf32d35f4d | 53 | |
bwang | 0:54cf32d35f4d | 54 | void Inverter::Disable() { |
bwang | 0:54cf32d35f4d | 55 | *_en = 1; |
bwang | 0:54cf32d35f4d | 56 | } |
bwang | 0:54cf32d35f4d | 57 | |
bwang | 0:54cf32d35f4d | 58 | float Inverter::UpdateVbus() { |
bwang | 0:54cf32d35f4d | 59 | return v_bus = _sense_bus->GetVoltage(); |
bwang | 0:54cf32d35f4d | 60 | } |
bwang | 0:54cf32d35f4d | 61 | |
bwang | 0:54cf32d35f4d | 62 | float Inverter::UpdateTemp() { |
bwang | 0:54cf32d35f4d | 63 | return temp = _sense_t->GetTemp(); |
bwang | 0:54cf32d35f4d | 64 | } |