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:
- 1:08226e87671c
- Parent:
- 0:24b2f1c78160
- Child:
- 2:d42e168b0fa7
File content as of revision 1:08226e87671c:
#include "mbed.h"
#include "L6230_BLDC.h"
#include "reScale.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);
AnalogIn pot(PB_1);
DigitalOut myled(LED1);
DigitalIn sw(PC_13);
Serial pc(USBTX, USBRX);
reScale _scale(0, 1, 800, 5000); 
float read_current(char);
int prevStep;
float speed;
float adc;
int main() 
{
    pc.baud(115200);   
            
    pc.printf("Started\r");
    
    while(1) 
    {
            adc = pot.read();
            speed =_scale.from(adc);  
            motor.one_step(1, speed, &prevStep);
    }
}
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;
}