Bayley Wang
/
priustroller_3
temp repo
Fork of priustroller_2 by
inverter.cpp@0:54cf32d35f4d, 2015-03-01 (annotated)
- Committer:
- bwang
- Date:
- Sun Mar 01 06:16:01 2015 +0000
- Revision:
- 0:54cf32d35f4d
- Child:
- 1:1f58bdcf2956
first publish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 0:54cf32d35f4d | 1 | #include "includes.h" |
bwang | 0:54cf32d35f4d | 2 | #include "classes.h" |
bwang | 0:54cf32d35f4d | 3 | |
bwang | 0:54cf32d35f4d | 4 | Inverter::Inverter(PinName ph_a, PinName ph_b, PinName ph_c, PinName en, VoltageSensor *sense_bus, TempSensor *sense_t) { |
bwang | 0:54cf32d35f4d | 5 | _en = new DigitalOut(en); |
bwang | 0:54cf32d35f4d | 6 | Disable(); |
bwang | 0:54cf32d35f4d | 7 | |
bwang | 0:54cf32d35f4d | 8 | _pwm_a = new PwmOut(ph_a); |
bwang | 0:54cf32d35f4d | 9 | _pwm_b = new PwmOut(ph_b); |
bwang | 0:54cf32d35f4d | 10 | _pwm_c = new PwmOut(ph_c); |
bwang | 0:54cf32d35f4d | 11 | _pwm_a->period_us(100); |
bwang | 0:54cf32d35f4d | 12 | _pwm_b->period_us(100); |
bwang | 0:54cf32d35f4d | 13 | _pwm_c->period_us(100); |
bwang | 0:54cf32d35f4d | 14 | |
bwang | 0:54cf32d35f4d | 15 | _sense_bus = sense_bus; |
bwang | 0:54cf32d35f4d | 16 | _sense_t = sense_t; |
bwang | 0:54cf32d35f4d | 17 | |
bwang | 0:54cf32d35f4d | 18 | SetDtcA(0); |
bwang | 0:54cf32d35f4d | 19 | SetDtcB(0); |
bwang | 0:54cf32d35f4d | 20 | SetDtcC(0); |
bwang | 0:54cf32d35f4d | 21 | |
bwang | 0:54cf32d35f4d | 22 | TIM2->CR1 &= ~(TIM_CR1_CEN); |
bwang | 0:54cf32d35f4d | 23 | TIM2->CR1 |= TIM_CR1_CMS; |
bwang | 0:54cf32d35f4d | 24 | TIM2->CR1 |= TIM_CR1_CEN; |
bwang | 0:54cf32d35f4d | 25 | |
bwang | 0:54cf32d35f4d | 26 | UpdateVbus(); |
bwang | 0:54cf32d35f4d | 27 | UpdateTemp(); |
bwang | 0:54cf32d35f4d | 28 | Enable(); |
bwang | 0:54cf32d35f4d | 29 | } |
bwang | 0:54cf32d35f4d | 30 | |
bwang | 0:54cf32d35f4d | 31 | void Inverter::SetDtcA(float dtc) { |
bwang | 0:54cf32d35f4d | 32 | if (dtc < 0) dtc = 0.0f; |
bwang | 0:54cf32d35f4d | 33 | if (dtc > 1.0f) dtc = 1.0f; |
bwang | 0:54cf32d35f4d | 34 | *_pwm_a = dtc; |
bwang | 0:54cf32d35f4d | 35 | } |
bwang | 0:54cf32d35f4d | 36 | |
bwang | 0:54cf32d35f4d | 37 | void Inverter::SetDtcB(float dtc) { |
bwang | 0:54cf32d35f4d | 38 | if (dtc < 0) dtc = 0.0f; |
bwang | 0:54cf32d35f4d | 39 | if (dtc > 1.0f) dtc = 1.0f; |
bwang | 0:54cf32d35f4d | 40 | *_pwm_b = 1.0f - dtc; |
bwang | 0:54cf32d35f4d | 41 | } |
bwang | 0:54cf32d35f4d | 42 | |
bwang | 0:54cf32d35f4d | 43 | void Inverter::SetDtcC(float dtc) { |
bwang | 0:54cf32d35f4d | 44 | if (dtc < 0) dtc = 0.0f; |
bwang | 0:54cf32d35f4d | 45 | if (dtc > 1.0f) dtc = 1.0f; |
bwang | 0:54cf32d35f4d | 46 | *_pwm_c = dtc; |
bwang | 0:54cf32d35f4d | 47 | } |
bwang | 0:54cf32d35f4d | 48 | |
bwang | 0:54cf32d35f4d | 49 | void Inverter::Enable() { |
bwang | 0:54cf32d35f4d | 50 | *_en = 0; |
bwang | 0:54cf32d35f4d | 51 | } |
bwang | 0:54cf32d35f4d | 52 | |
bwang | 0:54cf32d35f4d | 53 | void Inverter::Disable() { |
bwang | 0:54cf32d35f4d | 54 | *_en = 1; |
bwang | 0:54cf32d35f4d | 55 | } |
bwang | 0:54cf32d35f4d | 56 | |
bwang | 0:54cf32d35f4d | 57 | float Inverter::UpdateVbus() { |
bwang | 0:54cf32d35f4d | 58 | return v_bus = _sense_bus->GetVoltage(); |
bwang | 0:54cf32d35f4d | 59 | } |
bwang | 0:54cf32d35f4d | 60 | |
bwang | 0:54cf32d35f4d | 61 | float Inverter::UpdateTemp() { |
bwang | 0:54cf32d35f4d | 62 | return temp = _sense_t->GetTemp(); |
bwang | 0:54cf32d35f4d | 63 | } |