Go to the source code of this file.
Defines | |
#define | MAX_NUM_MOTORS_USED_3 8 |
#define | MOTOR_TIMER_USED_3 |
Motor References | |
This group of "#defines" are meant to uniquely identify each motor for ease of use in code, specifically with update_motor_3().
| |
#define | MOTOR_3_1 0x31 |
#define | MOTOR_3_2 0x32 |
#define | MOTOR_3_3 0x33 |
#define | MOTOR_3_4 0x34 |
#define | MOTOR_3_5 0x35 |
#define | MOTOR_3_6 0x36 |
#define | MOTOR_3_7 0x37 |
#define | MOTOR_3_8 0x38 |
Motor States | |
Motor states are predefined for ease of use and are to be used in conjunction with update_motor_3(). Except for MOTOR_COAST, the LSB toggles the first direction port and the second LSB toggles the second direction port. Basically, a bit mask is applied to them. | |
#define | MOTOR_COAST 0b00000100 |
#define | MOTOR_FORWARD 0b00000001 |
#define | MOTOR_REVERSE 0b00000010 |
#define | MOTOR_BRAKEL 0b00000000 |
#define | MOTOR_BRAKEH 0b00000011 |
Functions | |
void | update_motor_3 (uint8 u8_motor, uint8 u8_direction, uint16 u16_duration) |
void | initialize_motor_3 (void) |
ESOS_USER_INTERRUPT (ESOS_IRQ_PIC24_T3) |
Definition in file motor3.h.
#define MAX_NUM_MOTORS_USED_3 8 |
#define MOTOR_TIMER_USED_3 |
MOTOR_TIMER_USED_<n> should reflect which Timer is being used. This does not belong in motorconfig3.h because it should be templatized (in the event that this library is templatized).
ESOS_USER_INTERRUPT | ( | ESOS_IRQ_PIC24_T3 | ) |
void initialize_motor_3 | ( | void | ) |
Initializes the selected motors. Each motor is associated with an output compare, and each output compare is initialized to a 100 count duration until update_motor_3() is called.
This function is used to update each motor with a new direction and PWM duration. The motor (see Motor References) and direction (see Motor States) parameters are already defined, and the duration parameter is in terms of Timer ticks, which can be easily calculated with usToU16Ticks(). This function will ASSERT() if an invalid duration or motor is passed. Also, a bit mask is applied to the direction parameter so any editing of Motor States should be done with care.
As an example, to set motor 2 to 90% speed in reverse:
update_motor_3(MOTOR_3_2, MOTOR_REVERSE, usToU16Ticks(360, MOTOR_PRESCALER_3));