Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of priustroller_2 by
core/inverter.cpp
- Committer:
- nki
- Date:
- 2015-03-14
- Revision:
- 27:846c08fb3697
- Parent:
- 25:0003b824dd7d
- Child:
- 33:e7b132029bae
File content as of revision 27:846c08fb3697:
#include "includes.h" #include "core.h" #include "sensors.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); //disable tim2 //TIM2->CR1 |= TIM_CR1_CMS; //set bits 5 and 6 of the CR1 to 1. (TIM_CR1_CMS == 96) TIM2->CR1 |= (1 << 5); //by only enabling bit 5, "Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) //are set only when the counter is counting down" (p.342) //These lines do nothing so they are commented out. They should do something.. /* TIM2->CR1 &= ~(1 << 6); //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 TIM2->CR1 &= ~(1 << 1); //Set bit 1 (update disable) to 0. we want the timer overflow to trigger an interrupt //TIM2->CR1 |= (1 << 2); //Set bit 2 (update request source) to 1. Only want under/overflow to trigger an interrupt. */ TIM2->DIER |= 1; // set bit 0 equal to 1. this enables interrupts TIM2->CR1 |= TIM_CR1_CEN; //enable tim2 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 = 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 = 1; } void Inverter::Disable() { *_en = 0; } float Inverter::GetVbus() { return _sense_bus->GetVoltage(); } float Inverter::GetTemp() { return _sense_t->GetTemp(); }