L6230
Dependencies: L6230_BLDC mbed reScale
Diff: main.cpp
- Revision:
- 0:24b2f1c78160
- Child:
- 1:08226e87671c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jun 25 17:25:06 2020 +0000 @@ -0,0 +1,64 @@ +#include "mbed.h" +#include "L6230_BLDC.h" + +L6230_BLDC motor(PC_10, PC_11, PC_12, PA_8, PA_9, PA_10); + +AnalogIn feedback_phase_A(PA_0); +AnalogIn feedback_phase_B(PC_1); +AnalogIn feedback_phase_C(PC_0); + +DigitalOut myled(LED1); + +DigitalIn sw(PC_13); + +Serial pc(USBTX, USBRX); + +float read_current(char); + +int prevStep; + +int main() +{ + pc.baud(115200); + + pc.printf("Started\r"); + + while(1) + { + //motor.one_step(1, 5000, &prevStep); + + if(sw == 0) + { + + motor.turn_n_steps(1, 10000 , 100); + motor.turn_n_steps(1, 9000 , 200); + motor.turn_n_steps(1, 8000 , 300); + motor.turn_n_steps(1, 7000 , 400); + motor.turn_n_steps(1, 6000 , 500); + motor.turn_n_steps(1, 5000 , 600); + motor.turn_n_steps(1, 4000 , 700); + motor.turn_n_steps(1, 3000 , 800); + motor.turn_n_steps(1, 2000 , 900); + motor.turn_n_steps(1, 1000 , 2000); + motor.turn_n_steps(1, 800 , 10000); + + motor.stop(); + } + } +} + +float read_current(char PHASE) +{ + float ADC_VALUE; + + switch (PHASE) + { + case 1: ADC_VALUE = feedback_phase_A.read() * 3.3f; break; //convert to volts + case 2: ADC_VALUE = feedback_phase_B.read() * 3.3f; break; //convert to volts + case 3: ADC_VALUE = feedback_phase_C.read() * 3.3f; break; //convert to volts + } + + float CURRENT = ADC_VALUE / 0.33f; // U = R*I, I = U/R (R = 330mOhm) + + return CURRENT; +} \ No newline at end of file