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     bool pol;               
00081 
00082     adc_ch_t adc_ch;        
00083     adcread_t adc_max;      
00084     adcread_t adc_min;      
00085     mtime_t sample_delay;   
00086 
00087     bool dir;               
00088     int speed_trm_id;       
00089     dc_speed_t speed;       
00090 
00091 } DCMotorConfig;
00092 
00093 
00097 typedef struct DCMotor
00098 {
00099     const DCMotorConfig *cfg; 
00100     PidContext pid_ctx;       
00101 
00102     int index;                
00103     uint32_t status;          
00104     dc_speed_t tgt_speed;     
00105 
00106 } DCMotor;
00107 
00108 void dc_motor_setDir(int index, bool dir);
00109 void dc_motor_enable(int index, bool state);
00110 void dc_motor_setSpeed(int index, dc_speed_t speed);
00111 void dc_motor_setup(int index, DCMotorConfig *cfg);
00112 void dc_motor_init(void);
00113 
00114 #endif /* DRV_DC_MOTOR_H */