robotics/include/motor3.h File Reference

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().

Note:
For those wanting to expand on this library, the naming convention is MOTOR_<T>_<n> = 0xTn. 'T' is associated with which Timer the motors are running on, and 'n' is the motor number.


#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)


Detailed Description

Author:
Thomas Donaldson
This file contains function declarations and proprietary "#defines" for the motor library. It is not meant to be directly edited, and all library configuration should be done through motorconfig3.h.

Definition in file motor3.h.


Define Documentation

#define MAX_NUM_MOTORS_USED_3   8

This defines the maximum number of motors that are supported in the library and should not be edited unless you make changes in the code so that more motors can be supported.

Definition at line 55 of file motor3.h.

#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).

Definition at line 62 of file motor3.h.


Function Documentation

ESOS_USER_INTERRUPT ( ESOS_IRQ_PIC24_T3   ) 

Since the timer is being used solely for PWM, the ISR only needs to clear the interrupt flag.

Definition at line 223 of file motor3.c.

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.

Definition at line 129 of file motor3.c.

void update_motor_3 ( uint8  u8_motor,
uint8  u8_direction,
uint16  u16_duration 
)

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)); 

Definition at line 24 of file motor3.c.


Generated on Sun Mar 15 11:14:22 2009 for PIC24 Support Libraries by  doxygen 1.5.8