From cd847e2f5a58d43df13c434ce7571be5488082ed Mon Sep 17 00:00:00 2001 From: Pierre Prot Date: Sat, 9 Feb 2008 16:44:52 +0100 Subject: Paramétrage des timers - PWM - Gestion du Vref pour la limitation de courant --- analog/motor-power-avr/src/avrconfig.h | 13 +++++++ analog/motor-power-avr/src/main.c | 2 + analog/motor-power-avr/src/mp_pwm_LR_.c | 65 +++++++++++++++++++++++---------- analog/motor-power-avr/src/mp_pwm_LR_.h | 12 ++++-- analog/motor-power-avr/src/mp_pwm_L_.c | 51 +++++++++++++++----------- analog/motor-power-avr/src/mp_pwm_L_.h | 2 + 6 files changed, 102 insertions(+), 43 deletions(-) (limited to 'analog/motor-power-avr/src') diff --git a/analog/motor-power-avr/src/avrconfig.h b/analog/motor-power-avr/src/avrconfig.h index 59a35393..eacd2b6b 100644 --- a/analog/motor-power-avr/src/avrconfig.h +++ b/analog/motor-power-avr/src/avrconfig.h @@ -61,6 +61,19 @@ * - PTS: use pseudo terminal. */ #define AC_UART0_HOST_DRIVER PTS +/** Same thing for secondary port. */ +#define AC_UART1_PORT -1 +#define AC_UART1_BAUDRATE 115200 +#define AC_UART1_SEND_MODE RING +#define AC_UART1_RECV_MODE RING +#define AC_UART1_CHAR_SIZE 8 +#define AC_UART1_PARITY EVEN +#define AC_UART1_STOP_BITS 1 +#define AC_UART1_SEND_BUFFER_SIZE 32 +#define AC_UART1_RECV_BUFFER_SIZE 32 +#define AC_UART1_SEND_BUFFER_FULL WAIT +#define AC_UART1_HOST_DRIVER PTS + /* proto - Protocol module. */ /** Maximum argument size. */ #define AC_PROTO_ARGS_MAX_SIZE 12 diff --git a/analog/motor-power-avr/src/main.c b/analog/motor-power-avr/src/main.c index 466bff91..a18c0add 100644 --- a/analog/motor-power-avr/src/main.c +++ b/analog/motor-power-avr/src/main.c @@ -22,10 +22,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ + #include "common.h" #include "modules/uart/uart.h" #include "modules/proto/proto.h" #include "modules/utils/utils.h" +#include "modules/utils/utils.avr.h" #include "modules/utils/byte.h" #include "modules/math/fixed/fixed.h" #include "io.h" diff --git a/analog/motor-power-avr/src/mp_pwm_LR_.c b/analog/motor-power-avr/src/mp_pwm_LR_.c index 3e12cf58..545aea38 100644 --- a/analog/motor-power-avr/src/mp_pwm_LR_.c +++ b/analog/motor-power-avr/src/mp_pwm_LR_.c @@ -1,4 +1,11 @@ +#include "common.h" +#include "mp_pwm_LR_.h" +#include "mp_pwm_L_.h" +// Variables for current limitation +static uint8_t curLim_temp; +static uint8_t curLim_bat; +static uint8_t curLim_soft; // This file contains general pwm routines for mp (motor-power) board // @@ -6,18 +13,28 @@ // Timer_L_ : timer dedicated to Left side void init_timer_LR_(void) { - Timer_L_ = 0x00; - state_L_ = 0x40; - Timer_R_ = 0x80; - state_R_ = 0x40; - // TODO : set interrupts - // TODO : set OCR to 0 - START_TIMER_L_; - START_TIMER_R_; + init_pwm_L_(); + //init_pwm_R_(); + + TCNT_L_ = 0x00; + TCNT_R_ = 0x80; // 180° phase shifted to TCNT_L + + OCR_L_ = PWM_MIN_LR_; + OCR_R_ = PWM_MIN_LR_; + + // set interrupts + TIMSK |= TIMSK_LR_CFG; + + // launch timers + TCCR_L_ = TCCR_LR_CFG; + TCCR_R_ = TCCR_LR_CFG; } void init_curLim (void) { // TODO : set interrupts + curLim_soft = 0x80; + curLim_bat = 0x00; + curLim_temp = 0x00; } uint8_t get_curLim_temp (uint8_t temperature) { @@ -30,17 +47,27 @@ uint8_t get_curLim_bat (uint8_t battery) { // this function shall be called after each adjustment of any current limit void update_curLim(void) { - uint8 curLim_tmp; - uint8 ret; + uint8_t curLim_tmp; + + // search for MIN(curLim_soft, curLim_temp, curLim_bat) + curLim_tmp = curLim_soft; - if (curLim_soft > curLim_temp) then - curLim_tmp = curLim_temp - else - curLim_tmp = curLim_soft; + if (curLim_tmp > curLim_temp) + { + curLim_tmp = curLim_temp; + } - if (curLim_tmp > curLim_bat) then + if (curLim_tmp > curLim_bat) + { curLim_tmp = curLim_bat; + } + + if (curLim_tmp > CURLIM_MAX) + { + curLim_tmp = CURLIM_MAX; + } + // set curlim for _L_ and _R_ channel OCR_CurLim_L_ = curLim_tmp; OCR_CurLim_R_ = curLim_tmp; } @@ -49,15 +76,15 @@ void update_curLim(void) { void launch_envTest(void) { // TODO : acquerir les donnees de batterie // TODO : acquerir les donnees de temperature - curLim_temp = 1; - curLim_bat = 2; + curLim_temp = 50; + curLim_bat = 60; - update_current_limit(); + update_curLim(); } // set the software-programmed current limit void setCurLim_soft(uint8_t curLim) { curLim_soft = curLim; - update_current_limit(); + update_curLim(); } diff --git a/analog/motor-power-avr/src/mp_pwm_LR_.h b/analog/motor-power-avr/src/mp_pwm_LR_.h index 62ffdc28..e7018918 100644 --- a/analog/motor-power-avr/src/mp_pwm_LR_.h +++ b/analog/motor-power-avr/src/mp_pwm_LR_.h @@ -71,17 +71,23 @@ // timer configuration // for 57.21kHz : prescaler = 0 : CSx2:0 = 0x01 // for 7.68kHz : prescaler = 8 : CSx2:0 = 0x02 -#define TCCR_CFG (regv (FOC0, WGM00, COM01, COM00, WGM01, CS02, CS01, CS00, \ - 0, 0, 0, 0, 0, 0, 1, 0)) +#define TCCR_LR_CFG (regv (FOC0, WGM00, COM01, COM00, WGM01, CS02, CS01, CS00, \ + 0, 0, 0, 0, 0, 0, 1, 0)) // timer interrupts configuration -#define TIMSK (regv (OCIE2 +#define TIMSK_LR_CFG (regv (OCIE2, TOIE2, TICIE1, OCIE1A, OCIE1B, OCIE0, TOIE0,\ + 1, 1, 0, 0, 0, 1, 1)) // PWM max, min, and offset values #define PWM_MIN_LR_ 0x10 #define PWM_MAX_LR_ 0xF0 #define PWM_OFFSET_LR_ 0x00 +// Current limitation +#define CURLIM_MAX 0x80 +#define OCR_CurLim_L_ OCR1A +#define OCR_CurLim_R_ OCR1B + // functions void init_timer_LR_(void); void init_curLim (void); diff --git a/analog/motor-power-avr/src/mp_pwm_L_.c b/analog/motor-power-avr/src/mp_pwm_L_.c index 5a1d999f..085f2bcc 100644 --- a/analog/motor-power-avr/src/mp_pwm_L_.c +++ b/analog/motor-power-avr/src/mp_pwm_L_.c @@ -1,26 +1,33 @@ +/* "mp_pwm_L_.c" + * this file contains routines for managing the _L_ channel of mp board + * the command sed -e 's/_L_/_R_/g' can be used for generating the _R_ file + */ + #include "mp_pwm_LR_.h" #include "mp_pwm_L_.h" #include "io.h" - -// Le PC, afin de faire le saut calculé -//#define PC PC_REG - // static variables static uint8_t state_L_; static uint8_t state_L_cmd = 0x03; static uint8_t pwm_L_; -// this file contains routines for managing the _L_ channel of mp board -// the command sed -e 's/_L_/_R_/g' can be used for generating the _R_ file -// +// Le PC, afin de faire le saut calculé +//#define PC PC_REG + +// init +void init_pwm_L_ (void) { + state_L_cmd = 0x40; + pwm_L_ = 0x00; +} + // rising edge = timer overflow = TOV interrupt (TODO : à programmer) -void rise_L_ (void) { +void rise (void) { // programs the state which is ordered by the core code state_L_ = state_L_cmd; // the falling of the other side may have delayed a few our IT - OCR_L_ = pwm_L_ + Timer_L_; // TODO: OCR_L_value shall be > than x% + OCR_L_ = pwm_L_ + TCNT_L_; // TODO: OCR_L_value shall be > than x% //PC = PC + state_L_; // j'aurais bien aimé faire un calculated jump @@ -71,7 +78,6 @@ void rise_L_ (void) { break; } - } // falling edge = timer crossing OCR : OCn interrupt (TODO : à programmer) @@ -82,6 +88,7 @@ void fall_L_ (void) { { case 0x00: // in the case we are in 0x00 direction + //fall_L_label0: _L_AH_0; _L_AL_1; sei(); // set back interrupts @@ -144,17 +151,19 @@ void start_motor_L_ (uint8_t pwmspeed, uint8_t direction) { state_L_cmd = 0x20; pwm_L_ = 0; } - else if (pwmspeed > PWM_MAX_LR_) - {// over PWM_MAX_LR_ - pwm_L_ = PWM_MAX_LR_ + PWM_OFFSET_LR_; - } - else if (pwmspeed < PWM_MIN_LR_) - {// under PWM_MIN_LR_ - pwm_L_ = PWM_MIN_LR_ + PWM_OFFSET_LR_; - } - else - {// correct PWM value - pwm_L_ = pwmspeed + PWM_OFFSET_LR_; + else + { + // adding offset + pwmspeed = pwmspeed + PWM_OFFSET_LR_; + + if (pwmspeed > PWM_MAX_LR_) + {// over PWM_MAX_LR_ + pwm_L_ = PWM_MAX_LR_; + } + else if (pwmspeed < PWM_MIN_LR_) + {// under PWM_MIN_LR_ + pwm_L_ = PWM_MIN_LR_; + } } } diff --git a/analog/motor-power-avr/src/mp_pwm_L_.h b/analog/motor-power-avr/src/mp_pwm_L_.h index dba1c09c..49b96fe2 100644 --- a/analog/motor-power-avr/src/mp_pwm_L_.h +++ b/analog/motor-power-avr/src/mp_pwm_L_.h @@ -25,6 +25,8 @@ * * }}} */ + +void init_pwm_L_ (void); void rise_L_ (void); void fall_L_ (void); void ovc_L_ (void); -- cgit v1.2.3