dc_motor.h

Go to the documentation of this file.
00001 
00045 #ifndef DRV_DC_MOTOR_H
00046 #define DRV_DC_MOTOR_H
00047 
00048 #include "hw/hw_dc_motor.h"
00049 
00050 #include "cfg/cfg_dc_motor.h"
00051 #include <cfg/macros.h>
00052 
00053 #include <algo/pid_control.h>
00054 
00055 #include <drv/pwm.h>
00056 #include <drv/timer.h>
00057 #include <drv/adc.h>
00058 
00059 
00063 #define DC_MOTOR_ACTIVE     BV(0)     
00064 #define DC_MOTOR_DIR        BV(1)     
00065 
00066 
00069 typedef uint16_t dc_speed_t;
00070 
00074 typedef struct DCMotorConfig
00075 {
00076     PidCfg pid_cfg;         
00077 
00078     PwmDev pwm_dev;         
00079     pwm_freq_t freq;        
00080 
00081     adc_ch_t adc_ch;        
00082     adcread_t adc_max;      
00083     adcread_t adc_min;      
00084     mtime_t sample_delay;   
00085 
00086     bool dir;               
00087 
00088 } DCMotorConfig;
00089 
00090 
00094 typedef struct DCMotor
00095 {
00096     const DCMotorConfig *cfg; 
00097     PidContext pid_ctx;       
00098 
00099     int index;                
00100     uint32_t status;          
00101     dc_speed_t tgt_speed;     
00102 
00103 } DCMotor;
00104 
00105 void dc_motor_setDir(int index, bool dir);
00106 void dc_motor_enable(int index, bool state);
00107 void dc_motor_setSpeed(int index, dc_speed_t speed);
00108 void dc_motor_setup(int index, DCMotorConfig *cfg);
00109 void dc_motor_init(void);
00110 
00111 #endif /* DRV_DC_MOTOR_H */