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.
Dependencies: mbed
main.cpp
- Committer:
- Marcelocostanzo
- Date:
- 2020-06-25
- Revision:
- 0:24b2f1c78160
- Child:
- 1:08226e87671c
File content as of revision 0:24b2f1c78160:
#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;
}