para el ventilador

Dependencies:   QEI FastPWM

stepper_motor_driver.h

Committer:
miguelangel_2511
Date:
2020-04-20
Revision:
7:f4e248182d31
Parent:
6:d38287621cca
Child:
10:b2d87404309a

File content as of revision 7:f4e248182d31:

#ifndef STEPPER_MOTOR_DRIVER_H_
#define STEPPER_MOTOR_DRIVER_H_

#include "mbed.h"
#include "FastPWM.h"

#define STEPPER_PULSE_DUTY_CYCLE    0.5f
#define STEPPER_MOTOR_TOTAL_STEPS   6000

#define STEPPER_MOTOR_GO_HOME       0
#define STEPPER_MOTOR_GO_AHEAD      0


/* Type definition */

typedef enum{
    Stepper_Stand_By = 0,
    Stepper_Inspiration_Rising_Ramp,
    Stepper_Inspiration,
    Stepper_Inspiration_Falling_Ramp,
    Stepper_Inspiration_Finish,
    Stepper_Expiration_Rising_Ramp,
    Stepper_Expiration,
    Stepper_Expiration_Falling_Ramp,
    Stepper_Expiration_Finish,
    Stepper_Limit_Sensor_Error    
}Stepper_Driver_State_t;


/* Object declaration */
extern InterruptIn stepper_pulse_feedback;
extern FastPWM stepper_pulse;
extern DigitalOut stepper_en;
extern DigitalOut stepper_dir;


/* Variable declaration */

extern volatile uint8_t stepper_parameters_update_flag;


// Tables for calculations
extern const float sigma_ramp[RAMP_STEPS];
extern const  float short_sigma_ramp[SHORT_RAMP_STEPS];
extern uint32_t calibration_period_rise_ramp_us[RAMP_STEPS];
extern uint32_t inspiration_period_rise_ramp_us[RAMP_STEPS];
extern uint32_t expiration_period_rise_ramp_us[RAMP_STEPS];
extern uint32_t expiration_period_short_rise_ramp_us[SHORT_RAMP_STEPS];

// These parameters are configurer through the graphic interface */
extern uint32_t inspiration_stepper_pulses_setpoint;
//uint32_t expiration_stepper_pulses_setpoint; // Not used in this version
extern uint32_t inspiration_stepper_pulse_period_us;
extern uint32_t expiration_stepper_pulse_period_us;
extern uint32_t calibration_stepper_pulse_period_us;
//extern uint32_t min_inspiration_ramp_period_us;
//extern uint32_t min_expiration_ramp_period_us;
extern uint32_t volume_in_steps[VOLUME_SETPOINT_INDEX_LIMIT];

// Variables used in every state of the stepper motor driver */
extern volatile uint32_t stepper_pulse_counter;
extern volatile uint32_t stepper_ramp_pulse_counter;

extern volatile Stepper_Driver_State_t stepper_driver_state;

/* Function declaration */
void Stepper_Driver_Init(void);
//void Stepper_Calculate_Period_Ramp(void);
float Stepper_Calculate_Insp_Period_Ramp(float max_freq);
float Stepper_Calculate_Exp_Period_Ramp(float max_freq);
float Stepper_Calculate_Exp_Short_Period_Ramp(float max_freq);
void Stepper_Go_Home_Position(void);
void Stepper_Driver_State_Machine(void);
void Stepper_Driver_Pulse_Signal_Update(void);

#endif