L6230

Dependencies:   L6230_BLDC mbed reScale

Committer:
Marcelocostanzo
Date:
Thu Jun 25 17:25:06 2020 +0000
Revision:
0:24b2f1c78160
Child:
1:08226e87671c
Girando ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Marcelocostanzo 0:24b2f1c78160 1 #include "mbed.h"
Marcelocostanzo 0:24b2f1c78160 2 #include "L6230_BLDC.h"
Marcelocostanzo 0:24b2f1c78160 3
Marcelocostanzo 0:24b2f1c78160 4 L6230_BLDC motor(PC_10, PC_11, PC_12, PA_8, PA_9, PA_10);
Marcelocostanzo 0:24b2f1c78160 5
Marcelocostanzo 0:24b2f1c78160 6 AnalogIn feedback_phase_A(PA_0);
Marcelocostanzo 0:24b2f1c78160 7 AnalogIn feedback_phase_B(PC_1);
Marcelocostanzo 0:24b2f1c78160 8 AnalogIn feedback_phase_C(PC_0);
Marcelocostanzo 0:24b2f1c78160 9
Marcelocostanzo 0:24b2f1c78160 10 DigitalOut myled(LED1);
Marcelocostanzo 0:24b2f1c78160 11
Marcelocostanzo 0:24b2f1c78160 12 DigitalIn sw(PC_13);
Marcelocostanzo 0:24b2f1c78160 13
Marcelocostanzo 0:24b2f1c78160 14 Serial pc(USBTX, USBRX);
Marcelocostanzo 0:24b2f1c78160 15
Marcelocostanzo 0:24b2f1c78160 16 float read_current(char);
Marcelocostanzo 0:24b2f1c78160 17
Marcelocostanzo 0:24b2f1c78160 18 int prevStep;
Marcelocostanzo 0:24b2f1c78160 19
Marcelocostanzo 0:24b2f1c78160 20 int main()
Marcelocostanzo 0:24b2f1c78160 21 {
Marcelocostanzo 0:24b2f1c78160 22 pc.baud(115200);
Marcelocostanzo 0:24b2f1c78160 23
Marcelocostanzo 0:24b2f1c78160 24 pc.printf("Started\r");
Marcelocostanzo 0:24b2f1c78160 25
Marcelocostanzo 0:24b2f1c78160 26 while(1)
Marcelocostanzo 0:24b2f1c78160 27 {
Marcelocostanzo 0:24b2f1c78160 28 //motor.one_step(1, 5000, &prevStep);
Marcelocostanzo 0:24b2f1c78160 29
Marcelocostanzo 0:24b2f1c78160 30 if(sw == 0)
Marcelocostanzo 0:24b2f1c78160 31 {
Marcelocostanzo 0:24b2f1c78160 32
Marcelocostanzo 0:24b2f1c78160 33 motor.turn_n_steps(1, 10000 , 100);
Marcelocostanzo 0:24b2f1c78160 34 motor.turn_n_steps(1, 9000 , 200);
Marcelocostanzo 0:24b2f1c78160 35 motor.turn_n_steps(1, 8000 , 300);
Marcelocostanzo 0:24b2f1c78160 36 motor.turn_n_steps(1, 7000 , 400);
Marcelocostanzo 0:24b2f1c78160 37 motor.turn_n_steps(1, 6000 , 500);
Marcelocostanzo 0:24b2f1c78160 38 motor.turn_n_steps(1, 5000 , 600);
Marcelocostanzo 0:24b2f1c78160 39 motor.turn_n_steps(1, 4000 , 700);
Marcelocostanzo 0:24b2f1c78160 40 motor.turn_n_steps(1, 3000 , 800);
Marcelocostanzo 0:24b2f1c78160 41 motor.turn_n_steps(1, 2000 , 900);
Marcelocostanzo 0:24b2f1c78160 42 motor.turn_n_steps(1, 1000 , 2000);
Marcelocostanzo 0:24b2f1c78160 43 motor.turn_n_steps(1, 800 , 10000);
Marcelocostanzo 0:24b2f1c78160 44
Marcelocostanzo 0:24b2f1c78160 45 motor.stop();
Marcelocostanzo 0:24b2f1c78160 46 }
Marcelocostanzo 0:24b2f1c78160 47 }
Marcelocostanzo 0:24b2f1c78160 48 }
Marcelocostanzo 0:24b2f1c78160 49
Marcelocostanzo 0:24b2f1c78160 50 float read_current(char PHASE)
Marcelocostanzo 0:24b2f1c78160 51 {
Marcelocostanzo 0:24b2f1c78160 52 float ADC_VALUE;
Marcelocostanzo 0:24b2f1c78160 53
Marcelocostanzo 0:24b2f1c78160 54 switch (PHASE)
Marcelocostanzo 0:24b2f1c78160 55 {
Marcelocostanzo 0:24b2f1c78160 56 case 1: ADC_VALUE = feedback_phase_A.read() * 3.3f; break; //convert to volts
Marcelocostanzo 0:24b2f1c78160 57 case 2: ADC_VALUE = feedback_phase_B.read() * 3.3f; break; //convert to volts
Marcelocostanzo 0:24b2f1c78160 58 case 3: ADC_VALUE = feedback_phase_C.read() * 3.3f; break; //convert to volts
Marcelocostanzo 0:24b2f1c78160 59 }
Marcelocostanzo 0:24b2f1c78160 60
Marcelocostanzo 0:24b2f1c78160 61 float CURRENT = ADC_VALUE / 0.33f; // U = R*I, I = U/R (R = 330mOhm)
Marcelocostanzo 0:24b2f1c78160 62
Marcelocostanzo 0:24b2f1c78160 63 return CURRENT;
Marcelocostanzo 0:24b2f1c78160 64 }