[tuxdroid-svn] r470 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2007-08-28 15:20:42
|
Author: Paul_R Date: 2007-08-28 17:19:53 +0200 (Tue, 28 Aug 2007) New Revision: 470 Modified: firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.h Log: Moved the code which controls the motors from main.c to the motors module. Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-08-28 12:59:08 UTC (rev 469) +++ firmware/tuxcore/trunk/main.c 2007-08-28 15:19:53 UTC (rev 470) @@ -71,7 +71,6 @@ uint8_t t4ms_tim; /* 4ms main tick timer */ uint8_t t100ms_tim; /* 100ms tick timer */ uint8_t t1s_tim; /* 1s tick timer */ -uint8_t pwm_tim; /* pwm timer */ #if (DBG_STACK) /* @@ -100,77 +99,8 @@ { t4ms_tim++; - /* Wings PWM - * Pulse is stopped here */ - if (pwm_tim == wingsPwm) - MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; + motor_control(); - /* Spin PWM - * Pulse is stopped here */ - if (pwm_tim == spinPwm) - MOT_SPIN_PT &= ~MOT_SPIN_MK; - - /* PWM motor management - * Pulse is set here when pwm_tim is at maximum and is - * reset when pwm_tim equals the PWM value set by the user - * */ - if (pwm_tim++ == 5) - { - pwm_tim = 0; - PORTB |= pwmMaskB; /* spin and wings */ - } - - /* Wings timer to stop the wings in any position */ - if (wings_tim) - { - wings_tim--; - if (!wings_tim) - { - stopWings(); - } - } - - /* Wings braking (motor reversed) delay */ - if (wingsStpCnt) - { - wingsStpCnt--; - if (!wingsStpCnt) - { - stopWings(); - } - } - - /* eyes braking (motor reversed) delay */ - if (eyesStpCnt) - { - eyesStpCnt--; - if (!eyesStpCnt) - { - stopEyes(); - } - } - - /* mouth braking (motor reversed) delay */ - if (mouthStpCnt) - { - mouthStpCnt--; - if (!mouthStpCnt) - { - stopMouth(); - } - } - - /* spin braking (motor reversed) delay */ - if (spinStpCnt) - { - spinStpCnt--; - if (!spinStpCnt) - { - spinPwmMask &= ~MOT_SPIN_MK; - stopSpinMot(); - } - } - /* Every 100ms, update status and send it to the computer */ if (t4ms_tim == 25) { Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-08-28 12:59:08 UTC (rev 469) +++ firmware/tuxcore/trunk/motors.h 2007-08-28 15:19:53 UTC (rev 470) @@ -36,9 +36,6 @@ extern uint8_t mouthStpCnt, mouthPosCnt, mouth_pos; extern uint8_t spinPosCnt, spinStpCnt, spinPwm; -/* counter to disable spin interrupts at PC int */ -extern volatile uint8_t intt_spin_cnt; - /* switches interrupts vector for timer debounce */ extern volatile uint8_t int_sw_flags; @@ -158,8 +155,12 @@ \brief Stop the spinning motor \ingroup primitives */ -#define stopSpinMot() (MOT_SPIN_PT &= ~MOT_SPIN_MK) - +static inline void stopSpinMot(void) __attribute__ ((always_inline)); +void stopSpinMot(void) +{ + spinPwmMask &= ~MOT_SPIN_MK; + MOT_SPIN_PT &= ~MOT_SPIN_MK; +} /** \brief Start spinning to the left \ingroup primitives @@ -171,5 +172,89 @@ \ingroup primitives */ #define runSpinRight() (MOT_SPIN_L_PT &= ~MOT_SPIN_L_MK); (MOT_SPIN_R_PT |= MOT_SPIN_R_MK) +/** + \brief Control the PWM of the spinning & flippers and motor braking. + \ingroup primitives + * XXX Change group name + * This function should be called from a timer interrupt that will fix the PWM + * resolution. + * The PWM period will be PWM_PERIOD times * the timer period. + * The braking time is dependant on the timer period too. + */ +#define PWM_PERIOD 5 +uint8_t static pwm_tim; + +static inline void motor_control(void) __attribute__ ((always_inline)); +void motor_control(void) +{ + /* Wings PWM + * Pulse is stopped here */ + if (pwm_tim == wingsPwm) + MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; + + /* Spin PWM + * Pulse is stopped here */ + if (pwm_tim == spinPwm) + MOT_SPIN_PT &= ~MOT_SPIN_MK; + + /* PWM motor management + * Pulse is set here when pwm_tim is at maximum and is + * reset when pwm_tim equals the PWM value set by the user + */ + if (pwm_tim++ == PWM_PERIOD) + { + pwm_tim = 0; + PORTB |= pwmMaskB; /* spin and wings */ + } + /* Wings timer to stop the wings in any position */ + if (wings_tim) + { + wings_tim--; + if (!wings_tim) + { + stopWings(); + } + } + + /* Wings braking (motor reversed) delay */ + if (wingsStpCnt) + { + wingsStpCnt--; + if (!wingsStpCnt) + { + stopWings(); + } + } + + /* eyes braking (motor reversed) delay */ + if (eyesStpCnt) + { + eyesStpCnt--; + if (!eyesStpCnt) + { + stopEyes(); + } + } + + /* mouth braking (motor reversed) delay */ + if (mouthStpCnt) + { + mouthStpCnt--; + if (!mouthStpCnt) + { + stopMouth(); + } + } + + /* spin braking (motor reversed) delay */ + if (spinStpCnt) + { + spinStpCnt--; + if (!spinStpCnt) + { + stopSpinMot(); + } + } +} #endif |