Modified Motor Driver Firmware to include Flash + Thermal

Dependencies:   FastPWM3 mbed-dev-STM-lean

Committer:
benkatz
Date:
Fri Feb 19 04:13:06 2016 +0000
Revision:
2:8724412ad628
Parent:
1:b8bceb4daed5
Child:
3:6a0015d88d06
now uses TIM1 for PWM - makes layout for micro-on-board version much easier

Who changed what in which revision?

UserRevisionLine numberNew contents of line
benkatz 0:4e1c4df6aabd 1 #include "mbed.h"
benkatz 0:4e1c4df6aabd 2 #include "PositionSensor.h"
benkatz 0:4e1c4df6aabd 3 #include "Inverter.h"
benkatz 0:4e1c4df6aabd 4 #include "SVM.h"
benkatz 0:4e1c4df6aabd 5 #include "FastMath.h"
benkatz 0:4e1c4df6aabd 6 #include "Transforms.h"
benkatz 0:4e1c4df6aabd 7 #include "CurrentRegulator.h"
benkatz 0:4e1c4df6aabd 8
benkatz 0:4e1c4df6aabd 9 PositionSensorEncoder encoder(8192,0);
benkatz 2:8724412ad628 10 //Inverter inverter(PA_5, PB_10, PB_3, PB_7, 0.02014160156, 0.00005);
benkatz 2:8724412ad628 11 Inverter inverter(PA_8, PA_9, PA_10, PB_7, 0.02014160156, 0.00005);
benkatz 0:4e1c4df6aabd 12 CurrentRegulator foc(&inverter, &encoder, .005, .5);
benkatz 0:4e1c4df6aabd 13
benkatz 0:4e1c4df6aabd 14 Ticker testing;
benkatz 0:4e1c4df6aabd 15
benkatz 2:8724412ad628 16
benkatz 0:4e1c4df6aabd 17 using namespace FastMath;
benkatz 0:4e1c4df6aabd 18 using namespace Transforms;
benkatz 0:4e1c4df6aabd 19
benkatz 1:b8bceb4daed5 20 //float offset = 0;//-0.24;
benkatz 0:4e1c4df6aabd 21
benkatz 1:b8bceb4daed5 22 // Current Sampling IRQ
benkatz 2:8724412ad628 23 /*
benkatz 0:4e1c4df6aabd 24 extern "C" void TIM2_IRQHandler(void) {
benkatz 0:4e1c4df6aabd 25 // flash on update event
benkatz 0:4e1c4df6aabd 26 if (TIM2->SR & TIM_SR_UIF & TIM2->CNT>0x465) {
benkatz 0:4e1c4df6aabd 27 inverter.SampleCurrent();
benkatz 0:4e1c4df6aabd 28 }
benkatz 0:4e1c4df6aabd 29 TIM2->SR = 0x0; // reset the status register
benkatz 0:4e1c4df6aabd 30 }
benkatz 2:8724412ad628 31 */
benkatz 2:8724412ad628 32 extern "C" void TIM1_UP_TIM10_IRQHandler(void) {
benkatz 2:8724412ad628 33 // toggle on update event
benkatz 2:8724412ad628 34 if (TIM1->SR & TIM_SR_UIF ) {
benkatz 2:8724412ad628 35 inverter.SampleCurrent();
benkatz 2:8724412ad628 36 }
benkatz 2:8724412ad628 37 TIM1->SR = 0x0; // reset the status register
benkatz 2:8724412ad628 38 //GPIOC->ODR ^= (1 << 4); //Toggle pin for debugging
benkatz 2:8724412ad628 39 }
benkatz 0:4e1c4df6aabd 40
benkatz 0:4e1c4df6aabd 41
benkatz 0:4e1c4df6aabd 42 void Loop(void){
benkatz 0:4e1c4df6aabd 43 foc.Commutate();
benkatz 0:4e1c4df6aabd 44 }
benkatz 0:4e1c4df6aabd 45 /*
benkatz 0:4e1c4df6aabd 46 void voltage_foc(void){
benkatz 0:4e1c4df6aabd 47 theta = encoder.GetElecPosition() + offset;
benkatz 0:4e1c4df6aabd 48 InvPark(v_d, v_q, theta, &v_alpha, &v_beta);
benkatz 0:4e1c4df6aabd 49 spwm.Update_DTC(v_alpha, v_beta);
benkatz 0:4e1c4df6aabd 50 //output.write(theta/6.28318530718f);
benkatz 0:4e1c4df6aabd 51 }
benkatz 0:4e1c4df6aabd 52 */
benkatz 1:b8bceb4daed5 53
benkatz 0:4e1c4df6aabd 54
benkatz 0:4e1c4df6aabd 55 int main() {
benkatz 0:4e1c4df6aabd 56 wait(1);
benkatz 0:4e1c4df6aabd 57
benkatz 0:4e1c4df6aabd 58 testing.attach(&Loop, .0001);
benkatz 2:8724412ad628 59 //inverter.SetDTC(.2, .5, .97);
benkatz 0:4e1c4df6aabd 60 //inverter.EnableInverter();
benkatz 0:4e1c4df6aabd 61
benkatz 0:4e1c4df6aabd 62 while(1) {
benkatz 2:8724412ad628 63
benkatz 0:4e1c4df6aabd 64 }
benkatz 0:4e1c4df6aabd 65 }