BeRTOS
|
DC motor driver (implementation) More...
#include "dc_motor.h"
#include "hw/hw_dc_motor.h"
#include "cfg/cfg_pwm.h"
#include <cfg/log.h>
#include <cfg/debug.h>
#include <algo/pid_control.h>
#include <drv/timer.h>
#include <kern/proc.h>
#include <cpu/power.h>
#include <string.h>
Go to the source code of this file.
Defines | |
#define | DC_MOTOR_ACTIVE BV(0) |
Define status bit for DC motor device. | |
#define | DC_MOTOR_DIR BV(1) |
Spin direction of DC motor. | |
Functions | |
dc_speed_t | dc_motor_readTargetSpeed (int index) |
Read the target speed from select device. | |
static void NORETURN | dc_motor_poll (void) |
Process to poll DC motor status. | |
void | dc_motor_setDir (int index, bool dir) |
Set spin direction of DC motor. | |
void | dc_motor_setSpeed (int index, dc_speed_t speed) |
Set DC motor speed. | |
void | dc_motor_startTimer (int index, mtime_t on_time) |
Set among of time that dc motor should run. | |
void | dc_motor_enable (int index, bool state) |
Enable or disable dc motor. | |
void | dc_motor_setup (int index, DCMotorConfig *dcm_conf) |
Apply a confinguration to select DC motor. | |
void | dc_motor_setPriority (int priority) |
If we had enabled the priority scheduling, we can adjust the DC motor poll process priority. | |
void | dc_motor_init (void) |
Init DC motor. | |
Variables | |
static DCMotor | dcm_all [CONFIG_NUM_DC_MOTOR] |
DC motor definition. |
DC motor driver (implementation)
Thi module provide a simple api to controll a DC motor in direction and speed, to allow this we use a Back-EMF technique. This technique is based, on the capability of the DC motor to become a generator of voltage when we turn off its supply. This happen every time we turn off the DC motor supply, and it continues to rotate for a short time thanks to its mechanical energy. Using this idea we can turn off the motor for a very short time, and we read the volage value from DC motor supply pins. This voltage say to us the actual speed of the motor.
Definition in file dc_motor.c.
#define DC_MOTOR_ACTIVE BV(0) |
Define status bit for DC motor device.
DC motor enable or disable flag.
Definition at line 83 of file dc_motor.c.
void dc_motor_init | ( | void | ) |
Init DC motor.
priority: sets the dc motor process priority.
Definition at line 490 of file dc_motor.c.
static void NORETURN dc_motor_poll | ( | void | ) | [static] |
Process to poll DC motor status.
To use a Back-EMF technique (see brief for more details), we turn off a motor for CONFIG_DC_MOTOR_SAMPLE_DELAY, that value are stored in each DC motor config. For this implementation we assume that have a common CONFIG_DC_MOTOR_SAMPLE_DELAY, choose among a max delay to all DC motor configuration. The DC motor off time is choose to allow the out signal to be stable, so we can read and process this value for feedback controll loop. The period (CONFIG_DC_MOTOR_SAMPLE_PERIOD - CONFIG_DC_MOTOR_SAMPLE_DELAY) that every time we turn off a DC motor is choose to have a feedback controll more responsive or less responsive.
Definition at line 289 of file dc_motor.c.
void dc_motor_setDir | ( | int | index, |
bool | dir | ||
) |
Set spin direction of DC motor.
index number of DC motor dir direction of DC motor
Definition at line 347 of file dc_motor.c.