temp repo

Dependencies:   mbed

Fork of priustroller_2 by N K

Committer:
nki
Date:
Sat Mar 14 18:51:36 2015 +0000
Revision:
27:846c08fb3697
Parent:
25:0003b824dd7d
Child:
33:e7b132029bae
NONWORKING: debugging native ADC reading

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
nki 27:846c08fb3697 23 TIM2->CR1 &= ~(TIM_CR1_CEN); //disable tim2
nki 27:846c08fb3697 24 //TIM2->CR1 |= TIM_CR1_CMS; //set bits 5 and 6 of the CR1 to 1. (TIM_CR1_CMS == 96)
nki 27:846c08fb3697 25 TIM2->CR1 |= (1 << 5); //by only enabling bit 5, "Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register)
nki 27:846c08fb3697 26 //are set only when the counter is counting down" (p.342)
nki 27:846c08fb3697 27 //These lines do nothing so they are commented out. They should do something..
nki 27:846c08fb3697 28 /*
nki 27:846c08fb3697 29 TIM2->CR1 &= ~(1 << 6);
nki 27:846c08fb3697 30 //hmm, not sure what's going on there. It's set to only trigger when counting down, however it triggers at both underflow and overflow
bwang 0:54cf32d35f4d 31
nki 27:846c08fb3697 32 TIM2->CR1 &= ~(1 << 1); //Set bit 1 (update disable) to 0. we want the timer overflow to trigger an interrupt
nki 27:846c08fb3697 33 //TIM2->CR1 |= (1 << 2); //Set bit 2 (update request source) to 1. Only want under/overflow to trigger an interrupt.
nki 27:846c08fb3697 34 */
nki 27:846c08fb3697 35
nki 27:846c08fb3697 36 TIM2->DIER |= 1; // set bit 0 equal to 1. this enables interrupts
nki 27:846c08fb3697 37 TIM2->CR1 |= TIM_CR1_CEN; //enable tim2
bwang 0:54cf32d35f4d 38 Enable();
bwang 0:54cf32d35f4d 39 }
bwang 0:54cf32d35f4d 40
bwang 0:54cf32d35f4d 41 void Inverter::SetDtcA(float dtc) {
bwang 0:54cf32d35f4d 42 if (dtc < 0) dtc = 0.0f;
bwang 0:54cf32d35f4d 43 if (dtc > 1.0f) dtc = 1.0f;
bwang 11:dccbaa9274c5 44 *_pwm_a = dtc;
bwang 0:54cf32d35f4d 45 }
bwang 0:54cf32d35f4d 46
bwang 0:54cf32d35f4d 47 void Inverter::SetDtcB(float dtc) {
bwang 0:54cf32d35f4d 48 if (dtc < 0) dtc = 0.0f;
bwang 0:54cf32d35f4d 49 if (dtc > 1.0f) dtc = 1.0f;
nki 25:0003b824dd7d 50 *_pwm_b = dtc;
bwang 0:54cf32d35f4d 51 }
bwang 0:54cf32d35f4d 52
bwang 0:54cf32d35f4d 53 void Inverter::SetDtcC(float dtc) {
bwang 0:54cf32d35f4d 54 if (dtc < 0) dtc = 0.0f;
bwang 0:54cf32d35f4d 55 if (dtc > 1.0f) dtc = 1.0f;
bwang 11:dccbaa9274c5 56 *_pwm_c = dtc;
bwang 0:54cf32d35f4d 57 }
bwang 0:54cf32d35f4d 58
bwang 0:54cf32d35f4d 59 void Inverter::Enable() {
nki 25:0003b824dd7d 60 *_en = 1;
bwang 0:54cf32d35f4d 61 }
bwang 0:54cf32d35f4d 62
bwang 0:54cf32d35f4d 63 void Inverter::Disable() {
nki 25:0003b824dd7d 64 *_en = 0;
bwang 0:54cf32d35f4d 65 }
bwang 0:54cf32d35f4d 66
bwang 11:dccbaa9274c5 67 float Inverter::GetVbus() {
bwang 11:dccbaa9274c5 68 return _sense_bus->GetVoltage();
bwang 0:54cf32d35f4d 69 }
bwang 0:54cf32d35f4d 70
bwang 11:dccbaa9274c5 71 float Inverter::GetTemp() {
bwang 11:dccbaa9274c5 72 return _sense_t->GetTemp();
bwang 0:54cf32d35f4d 73 }