temp repo

Dependencies:   mbed

Fork of priustroller_2 by N K

Committer:
nki
Date:
Thu Mar 05 11:02:54 2015 +0000
Revision:
7:76d6ceb23e0d
Parent:
6:99ee0ce47fb2
uh what;

Who changed what in which revision?

UserRevisionLine numberNew 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 7:76d6ceb23e0d 35 *_pwm_a = 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 7:76d6ceb23e0d 41 *_pwm_b = 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 7:76d6ceb23e0d 47 *_pwm_c = 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 }