customizing code for Aliexpress 14 bit version with MA702

Dependencies:   mbed FastPWM3

Committer:
benkatz
Date:
Fri Feb 05 01:04:57 2016 +0000
Revision:
1:b8bceb4daed5
Parent:
0:4e1c4df6aabd
Child:
2:8724412ad628
Added some comments, cleaned things up a bit

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 0:4e1c4df6aabd 10 Inverter inverter(PA_5, PB_10, PB_3, PB_7, 0.02014160156, 0.00005);
benkatz 0:4e1c4df6aabd 11 CurrentRegulator foc(&inverter, &encoder, .005, .5);
benkatz 0:4e1c4df6aabd 12
benkatz 0:4e1c4df6aabd 13 Ticker testing;
benkatz 0:4e1c4df6aabd 14
benkatz 0:4e1c4df6aabd 15 using namespace FastMath;
benkatz 0:4e1c4df6aabd 16 using namespace Transforms;
benkatz 0:4e1c4df6aabd 17
benkatz 1:b8bceb4daed5 18 //float offset = 0;//-0.24;
benkatz 0:4e1c4df6aabd 19
benkatz 1:b8bceb4daed5 20 // Current Sampling IRQ
benkatz 0:4e1c4df6aabd 21 extern "C" void TIM2_IRQHandler(void) {
benkatz 0:4e1c4df6aabd 22 // flash on update event
benkatz 0:4e1c4df6aabd 23 if (TIM2->SR & TIM_SR_UIF & TIM2->CNT>0x465) {
benkatz 0:4e1c4df6aabd 24 inverter.SampleCurrent();
benkatz 0:4e1c4df6aabd 25 }
benkatz 0:4e1c4df6aabd 26 TIM2->SR = 0x0; // reset the status register
benkatz 0:4e1c4df6aabd 27 }
benkatz 0:4e1c4df6aabd 28
benkatz 0:4e1c4df6aabd 29
benkatz 0:4e1c4df6aabd 30 void Loop(void){
benkatz 0:4e1c4df6aabd 31 foc.Commutate();
benkatz 0:4e1c4df6aabd 32 }
benkatz 0:4e1c4df6aabd 33 /*
benkatz 0:4e1c4df6aabd 34 void voltage_foc(void){
benkatz 0:4e1c4df6aabd 35 theta = encoder.GetElecPosition() + offset;
benkatz 0:4e1c4df6aabd 36 InvPark(v_d, v_q, theta, &v_alpha, &v_beta);
benkatz 0:4e1c4df6aabd 37 spwm.Update_DTC(v_alpha, v_beta);
benkatz 0:4e1c4df6aabd 38 //output.write(theta/6.28318530718f);
benkatz 0:4e1c4df6aabd 39 }
benkatz 0:4e1c4df6aabd 40 */
benkatz 1:b8bceb4daed5 41
benkatz 0:4e1c4df6aabd 42
benkatz 0:4e1c4df6aabd 43 int main() {
benkatz 0:4e1c4df6aabd 44 wait(1);
benkatz 0:4e1c4df6aabd 45
benkatz 0:4e1c4df6aabd 46 testing.attach(&Loop, .0001);
benkatz 0:4e1c4df6aabd 47 //inverter.EnableInverter();
benkatz 0:4e1c4df6aabd 48
benkatz 0:4e1c4df6aabd 49 while(1) {
benkatz 0:4e1c4df6aabd 50
benkatz 0:4e1c4df6aabd 51 }
benkatz 0:4e1c4df6aabd 52 }