From 792161793c7ebed6e8ba46e0c080b495289bb272 Mon Sep 17 00:00:00 2001 From: Pierre Prot Date: Thu, 7 Feb 2008 22:19:32 +0100 Subject: Modifs sur les timers, les ADC, la génération de PWM Corrections, ajout de defines, etc... --- analog/motor-power-avr/src/mp_pwm_LR_.h | 54 +++++++++++++++++++++++++--- analog/motor-power-avr/src/mp_pwm_L_.c | 62 ++++++++++++++------------------- 2 files changed, 76 insertions(+), 40 deletions(-) (limited to 'analog/motor-power-avr') diff --git a/analog/motor-power-avr/src/mp_pwm_LR_.h b/analog/motor-power-avr/src/mp_pwm_LR_.h index 3aaf3672..62ffdc28 100644 --- a/analog/motor-power-avr/src/mp_pwm_LR_.h +++ b/analog/motor-power-avr/src/mp_pwm_LR_.h @@ -26,17 +26,63 @@ * }}} */ #include "common.h" +#include "io.h" -#define OCR_L_ OCR0 -#define OCR_R_ OCR2 +// Control outputs of H-bridges +// _L_/_R_ : Left or Right bridge +// A/B : bridge leg +// H/L : High or Low side -#define Timer_L_ TOCNT -#define Timer_R_ T2CNT +// _L_AH : PORTC6 +#define _L_AH_1 PORTC |= 0x40 +#define _L_AH_0 PORTC &= ~0x40 +// _L_AL : PORTC7 +#define _L_AL_1 PORTC |= 0x80 +#define _L_AL_0 PORTC &= ~0x80 +// _L_BH : PORTC4 +#define _L_BH_1 PORTC |= 0x10 +#define _L_BH_0 PORTC &= ~0x10 +// _L_BL : PORTC5 +#define _L_BL_1 PORTC |= 0x20 +#define _L_BL_0 PORTC &= ~0x20 + +// _R_AH : PORTD6 +#define _R_AH_1 PORTD |= 0x40 +#define _R_AH_0 PORTD &= ~0x40 +// _R_AL : PORTD7 +#define _R_AL_1 PORTD |= 0x80 +#define _R_AL_0 PORTD &= ~0x80 +// _R_BH : PORTC2 +#define _R_BH_1 PORTC |= 0x04 +#define _R_BH_0 PORTC &= ~0x04 +// _R_BL : PORTC3 +#define _R_BL_1 PORTC |= 0x08 +#define _R_BL_0 PORTC &= ~0x08 + +// Timer for _L_ and _R_ control +#define TCNT_L_ TCNT0 +#define TCNT_R_ TCNT2 +#define OCR_L_ OCR0 +#define OCR_R_ OCR2 +#define TCCR_L_ TCCR0 +#define TCCR_R_ TCCR2 + +// 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)) + +// timer interrupts configuration +#define TIMSK (regv (OCIE2 + +// PWM max, min, and offset values #define PWM_MIN_LR_ 0x10 #define PWM_MAX_LR_ 0xF0 #define PWM_OFFSET_LR_ 0x00 +// functions void init_timer_LR_(void); void init_curLim (void); uint8_t get_curLim_temp (uint8_t temperature); diff --git a/analog/motor-power-avr/src/mp_pwm_L_.c b/analog/motor-power-avr/src/mp_pwm_L_.c index b7ef3732..5a1d999f 100644 --- a/analog/motor-power-avr/src/mp_pwm_L_.c +++ b/analog/motor-power-avr/src/mp_pwm_L_.c @@ -1,26 +1,16 @@ #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 - -// Les sorties de contrôdu pont en H -// A/B : branche du pont -// H/L : High ou Low -// _L_ : pont Left -#define _L_AL // TODO ! à conpléter ! -#define _L_AH // TODO ! à conpléter ! -#define _L_BL // TODO ! à conpléter ! -#define _L_BH // TODO ! à conpléter ! +//#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 // @@ -39,10 +29,10 @@ void rise_L_ (void) { case 0x00: // dir 0 //rise_L_label0: - _L_BH = 0; - _L_BL = 1; - _L_AL = 0; - _L_AH = 1; + _L_BH_0; + _L_BL_1; + _L_AL_0; + _L_AH_1; sei(); // set back interrupts return; break; @@ -50,10 +40,10 @@ void rise_L_ (void) { case 0x01: // dir 1 //org rise_L_label0 + 0x10 - _L_AH = 0; - _L_AL = 1; - _L_BL = 0; - _L_BH = 1; + _L_AH_0; + _L_AL_1; + _L_BL_0; + _L_BH_1; sei(); // set back interrupts return; break; @@ -61,10 +51,10 @@ void rise_L_ (void) { case 0x02: // switch to forced low steady state //org rise_L_label0 + 0x20 - _L_AH = 0; - _L_AL = 1; - _L_BH = 0; - _L_BL = 1; + _L_AH_0; + _L_AL_1; + _L_BH_0; + _L_BL_1; sei(); // set back interrupts return; break; @@ -72,10 +62,10 @@ void rise_L_ (void) { case 0x03: // switch to high impedance steady state //org rise_L_label0 + 0x30 - _L_AL = 0; - _L_AH = 0; - _L_BL = 0; - _L_BH = 0; + _L_AL_0; + _L_AH_0; + _L_BL_0; + _L_BH_0; sei(); // set back interrupts return; break; @@ -92,8 +82,8 @@ void fall_L_ (void) { { case 0x00: // in the case we are in 0x00 direction - _L_AH = 0; - _L_AL = 1; + _L_AH_0; + _L_AL_1; sei(); // set back interrupts return; break; @@ -101,8 +91,8 @@ void fall_L_ (void) { case 0x01: // in the case we are in 0x10 direction //org fall_L_label0 + 0x10 - _L_BH = 0; - _L_BL = 1; + _L_BH_0; + _L_BL_1; sei(); // set back interrupts return; break; @@ -126,10 +116,10 @@ void fall_L_ (void) { // overcurrent detected by comparators void ovc_L_ (void) { - _L_AL = 0; - _L_AH = 0; - _L_BL = 0; - _L_BH = 0; + _L_AL_0; + _L_AH_0; + _L_BL_0; + _L_BH_0; sei(); // set back interrupts // following line orders to keep high Z state when faling edge will arrive state_L_ = 0x30; -- cgit v1.2.3