00001
00009 #include "motorconfig3.h"
00010
00024 void update_motor_3(uint8 u8_motor, uint8 u8_direction, uint16 u16_duration) {
00025 if (u8_motor == MOTOR_3_1) {
00026 if (u8_direction == MOTOR_COAST) {
00027 OC1RS = 0;
00028 } else {
00029 MOTOR_3_1_DIR_PORT_1 = (u8_direction & 0b00000001);
00030 MOTOR_3_1_DIR_PORT_2 = ((u8_direction >> 1) & 0b00000001);
00031 ASSERT(u16_duration <= MOTOR_PULSE_PERIOD_3 && u16_duration > 0);
00032 OC1RS = u16_duration;
00033 }
00034 }
00035 #if (NUM_MOTORS_USED_3 >= 2)
00036 if (u8_motor == MOTOR_3_2) {
00037 if (u8_direction == MOTOR_COAST) {
00038 OC2RS = 0;
00039 } else {
00040 MOTOR_3_2_DIR_PORT_1 = (u8_direction & 0b00000001);
00041 MOTOR_3_2_DIR_PORT_2 = ((u8_direction >> 1) & 0b00000001);
00042 ASSERT(u16_duration <= MOTOR_PULSE_PERIOD_3 && u16_duration > 0);
00043 OC2RS = u16_duration;
00044 }
00045 }
00046 #endif
00047 #if (NUM_MOTORS_USED_3 >= 3)
00048 if (u8_motor == MOTOR_3_3) {
00049 if (u8_direction == MOTOR_COAST) {
00050 OC3RS = 0;
00051 } else {
00052 MOTOR_3_3_DIR_PORT_1 = (u8_direction & 0b00000001);
00053 MOTOR_3_3_DIR_PORT_2 = ((u8_direction >> 1) & 0b00000001);
00054 ASSERT(u16_duration <= MOTOR_PULSE_PERIOD_3 && u16_duration > 0);
00055 OC3RS = u16_duration;
00056 }
00057 }
00058 #endif
00059 #if (NUM_MOTORS_USED_3 >= 4)
00060 if (u8_motor == MOTOR_3_4) {
00061 if (u8_direction == MOTOR_COAST) {
00062 OC4RS = 0;
00063 } else {
00064 MOTOR_3_4_DIR_PORT_1 = (u8_direction & 0b00000001);
00065 MOTOR_3_4_DIR_PORT_2 = ((u8_direction >> 1) & 0b00000001);
00066 ASSERT(u16_duration <= MOTOR_PULSE_PERIOD_3 && u16_duration > 0);
00067 OC4RS = u16_duration;
00068 }
00069 }
00070 #endif
00071 #if (NUM_MOTORS_USED_3 >= 5)
00072 if (u8_motor == MOTOR_3_5) {
00073 if (u8_direction == MOTOR_COAST) {
00074 OC5RS = 0;
00075 } else {
00076 MOTOR_3_5_DIR_PORT_1 = (u8_direction & 0b00000001);
00077 MOTOR_3_5_DIR_PORT_2 = ((u8_direction >> 1) & 0b00000001);
00078 ASSERT(u16_duration <= MOTOR_PULSE_PERIOD_3 && u16_duration > 0);
00079 OC5RS = u16_duration;
00080 }
00081 }
00082 #endif
00083 #if (NUM_MOTORS_USED_3 >= 6)
00084 if (u8_motor == MOTOR_3_6) {
00085 if (u8_direction == MOTOR_COAST) {
00086 OC6RS = 0;
00087 } else {
00088 MOTOR_3_6_DIR_PORT_1 = (u8_direction & 0b00000001);
00089 MOTOR_3_6_DIR_PORT_2 = ((u8_direction >> 1) & 0b00000001);
00090 ASSERT(u16_duration <= MOTOR_PULSE_PERIOD_3 && u16_duration > 0);
00091 OC6RS = u16_duration;
00092 }
00093 }
00094 #endif
00095 #if (NUM_MOTORS_USED_3 >= 7)
00096 if (u8_motor == MOTOR_3_7) {
00097 if (u8_direction == MOTOR_COAST) {
00098 OC7RS = 0;
00099 } else {
00100 MOTOR_3_7_DIR_PORT_1 = (u8_direction & 0b00000001);
00101 MOTOR_3_7_DIR_PORT_2 = ((u8_direction >> 1) & 0b00000001);
00102 ASSERT(u16_duration <= MOTOR_PULSE_PERIOD_3 && u16_duration > 0);
00103 OC7RS = u16_duration;
00104 }
00105 }
00106 #endif
00107 #if (NUM_MOTORS_USED_3 >= 8)
00108 if (u8_motor == MOTOR_3_8) {
00109 if (u8_direction == MOTOR_COAST) {
00110 OC8RS = 0;
00111 } else {
00112 MOTOR_3_8_DIR_PORT_1 = (u8_direction & 0b00000001);
00113 MOTOR_3_8_DIR_PORT_2 = ((u8_direction >> 1) & 0b00000001);
00114 ASSERT(u16_duration <= MOTOR_PULSE_PERIOD_3 && u16_duration > 0);
00115 OC8RS = u16_duration;
00116 }
00117 }
00118 #endif
00119 else {
00120 ASSERT(FALSE);
00121 }
00122 }
00123
00129 void initialize_motor_3(void) {
00130 #if (NUM_MOTORS_USED_3 >= 1)
00131 CONFIG_MOTOR_3_1();
00132 OC1CONbits.OCM = 0b000;
00133 OC1R = 100;
00134 OC1RS = 100;
00135 OC1CONbits.OCTSEL = MOTOR_OCTSEL;
00136 OC1CONbits.OCM = 0b110;
00137 #endif
00138 #if (NUM_MOTORS_USED_3 >= 2)
00139 CONFIG_MOTOR_3_2();
00140 OC2CONbits.OCM = 0b000;
00141 OC2R = 100;
00142 OC2RS = 100;
00143 OC2CONbits.OCTSEL = MOTOR_OCTSEL;
00144 OC2CONbits.OCM = 0b110;
00145 #endif
00146 #if (NUM_MOTORS_USED_3 >= 3)
00147 CONFIG_MOTOR_3_3();
00148 OC3CONbits.OCM = 0b000;
00149 OC3R = 100;
00150 OCRS = 100;
00151 OC3CONbits.OCTSEL = MOTOR_OCTSEL;
00152 OC3CONbits.OCM = 0b110;
00153 #endif
00154 #if (NUM_MOTORS_USED_3 >= 4)
00155 CONFIG_MOTOR_3_4();
00156 OC4CONbits.OCM = 0b000;
00157 OC4R = 100;
00158 OC4RS = 100;
00159 OC4CONbits.OCTSEL = MOTOR_OCTSEL;
00160 OC4CONbits.OCM = 0b110;
00161 #endif
00162 #if (NUM_MOTORS_USED_3 >= 5)
00163 CONFIG_MOTOR_3_5();
00164 OC5CONbits.OCM = 0b000;
00165 OC5R = 100;
00166 OC5RS = 100;
00167 OC5CONbits.OCTSEL = MOTOR_OCTSEL;
00168 OC5CONbits.OCM = 0b110;
00169 #endif
00170 #if (NUM_MOTORS_USED_3 >= 6)
00171 CONFIG_MOTOR_3_6();
00172 OC6CONbits.OCM = 0b000;
00173 OC6R = 100;
00174 OC6RS = 100;
00175 OC6CONbits.OCTSEL = MOTOR_OCTSEL;
00176 OC6CONbits.OCM = 0b110;
00177 #endif
00178 #if (NUM_MOTORS_USED_3 >= 7)
00179 CONFIG_MOTOR_3_7();
00180 OC7CONbits.OCM = 0b000;
00181 OC7R = 100;
00182 OC7RS = 100;
00183 OC7CONbits.OCTSEL = MOTOR_OCTSEL;
00184 OC7CONbits.OCM = 0b110;
00185 #endif
00186 #if (NUM_MOTORS_USED_3 >= 8)
00187 CONFIG_MOTOR_3_8();
00188 OC8CONbits.OCM = 0b000;
00189 OC8R = 100;
00190 OC81RS = 100;
00191 OC8CONbits.OCTSEL = MOTOR_OCTSEL;
00192 OC8CONbits.OCM = 0b110;
00193 #endif
00194 #ifdef MOTOR_TIMER_USED_3 //do not templatize!
00195 T2CON = T2_32BIT_MODE_OFF;
00196
00197
00198 T3CON = T3_IDLE_CON + MOTOR_PRESCALER_BITFIELD_3 + T3_SOURCE_INT;
00199 #endif
00200 #ifdef MOTOR_TIMER_USED_2
00201
00202
00203 T2CON = T2_IDLE_CON + MOTOR_PRESCALER_BITFIELD_2 + T2_32BIT_MODE_OFF +
00204 T2_SOURCE_INT;
00205 #endif
00206 TMR3 = 0;
00207 PR3 = MOTOR_PULSE_PERIOD_3;
00208 T3CONbits.TON = 1;
00209 #ifdef ESOS_USE_IRQS
00210 ESOS_REGISTER_PIC24_USER_INTERRUPT(ESOS_IRQ_PIC24_T3, MOTOR_IRQ_3,
00211 _T3Interrupt);
00212 ESOS_ENABLE_PIC24_USER_INTERRUPT(ESOS_IRQ_PIC24_T3);
00213 #else
00214 _T3IP = MOTOR_IRQ_LEVEL_3;
00215 _T3IF = 0;
00216 _T3IE = 1;
00217 #endif
00218 }
00219
00223 ESOS_USER_INTERRUPT(ESOS_IRQ_PIC24_T3) {
00224 ESOS_MARK_PIC24_USER_INTERRUPT_SERVICED(ESOS_IRQ_PIC24_T3);
00225 }