temp repo

Dependencies:   mbed

Fork of priustroller_2 by N K

Revision:
0:54cf32d35f4d
Child:
1:1f58bdcf2956
diff -r 000000000000 -r 54cf32d35f4d inverter.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inverter.cpp	Sun Mar 01 06:16:01 2015 +0000
@@ -0,0 +1,63 @@
+#include "includes.h"
+#include "classes.h"
+
+Inverter::Inverter(PinName ph_a, PinName ph_b, PinName ph_c, PinName en, VoltageSensor *sense_bus, TempSensor *sense_t) {
+    _en = new DigitalOut(en);
+    Disable();
+    
+    _pwm_a = new PwmOut(ph_a);
+    _pwm_b = new PwmOut(ph_b);
+    _pwm_c = new PwmOut(ph_c);
+    _pwm_a->period_us(100);
+    _pwm_b->period_us(100);
+    _pwm_c->period_us(100);
+    
+    _sense_bus = sense_bus;
+    _sense_t = sense_t;
+    
+    SetDtcA(0);
+    SetDtcB(0);
+    SetDtcC(0);
+    
+    TIM2->CR1 &= ~(TIM_CR1_CEN);
+    TIM2->CR1 |= TIM_CR1_CMS;
+    TIM2->CR1 |= TIM_CR1_CEN;
+    
+    UpdateVbus();
+    UpdateTemp();
+    Enable();
+}
+
+void Inverter::SetDtcA(float dtc) {
+    if (dtc < 0) dtc = 0.0f;
+    if (dtc > 1.0f) dtc = 1.0f;
+    *_pwm_a = dtc;
+} 
+
+void Inverter::SetDtcB(float dtc) {
+    if (dtc < 0) dtc = 0.0f;
+    if (dtc > 1.0f) dtc = 1.0f;
+    *_pwm_b = 1.0f - dtc;
+} 
+
+void Inverter::SetDtcC(float dtc) {
+    if (dtc < 0) dtc = 0.0f;
+    if (dtc > 1.0f) dtc = 1.0f;
+    *_pwm_c = dtc;
+}
+
+void Inverter::Enable() {
+    *_en = 0;
+}
+
+void Inverter::Disable() {
+    *_en = 1;
+}
+
+float Inverter::UpdateVbus() {
+    return v_bus = _sense_bus->GetVoltage();
+}
+
+float Inverter::UpdateTemp() {
+    return temp = _sense_t->GetTemp();
+}
\ No newline at end of file