BeRTOS
dc_motor.h
Go to the documentation of this file.
00001 
00043 #ifndef DRV_DC_MOTOR_H
00044 #define DRV_DC_MOTOR_H
00045 
00046 #include "hw/hw_dc_motor.h"
00047 
00048 #include "cfg/cfg_dc_motor.h"
00049 #include "cfg/cfg_pwm.h"
00050 #include <cfg/macros.h>
00051 
00052 #include <algo/pid_control.h>
00053 
00054 #include <drv/pwm.h>
00055 #include <drv/timer.h>
00056 #include <drv/adc.h>
00057 
00058 #define DC_MOTOR_NO_EXPIRE        -1  ///< The DC motor runs do not expire, so it runs forever.
00059 #define DC_MOTOR_NO_DEV_SPEED     -1  ///< Disable the speed acquire from device (like trimmer, etc.).
00060 
00064 typedef uint16_t dc_speed_t;
00065 
00069 typedef struct DCMotorConfig
00070 {
00071     PidCfg pid_cfg;         
00072     bool pid_enable;        
00073 
00074     unsigned pwm_dev;       
00075     pwm_freq_t freq;        
00076 
00077     adc_ch_t adc_ch;        
00078     adcread_t adc_max;      
00079     adcread_t adc_min;      
00080 
00081     bool dir;               
00082     bool braked;            
00083 
00084     dc_speed_t speed;       
00085 
00086     int speed_dev_id;       
00087 
00088 } DCMotorConfig;
00089 
00090 
00094 typedef struct DCMotor
00095 {
00096     const DCMotorConfig *cfg; // All configuration for select DC motor.
00097     PidContext pid_ctx;       // Pid control.
00098 
00099 #if !CFG_PWM_ENABLE_OLD_API
00100     Pwm pwm;                  // Pwm context
00101 #endif
00102 
00103     int index;                // DC motor id.
00104     uint32_t status;          // Status of select DC motor
00105     dc_speed_t tgt_speed;     // Target speed for select DC motor
00106 
00107     ticks_t expire_time;      // Amount of time that  dc motor run
00108 
00109 } DCMotor;
00110 
00111 void dc_motor_setDir(int index, bool dir);
00112 void dc_motor_enable(int index, bool state);
00113 void dc_motor_setSpeed(int index, dc_speed_t speed);
00114 void dc_motor_startTimer(int index, mtime_t on_time);
00115 void dc_motor_waitStop(int index);
00116 void dc_motor_setup(int index, DCMotorConfig *dcm_conf);
00117 dc_speed_t dc_motor_readTargetSpeed(int index);
00118 void dc_motor_setPriority(int priority);
00119 void dc_motor_init(void);
00120 
00121 
00127 int dc_motor_testSetUp(void);
00128 void dc_motor_testRun(void);
00129 int dc_motor_testTearDown(void);
00130 
00131 #endif /* DRV_DC_MOTOR_H */