summaryrefslogtreecommitdiff
path: root/analog/motor-power-avr/src/mp_pwm_LR_.c
diff options
context:
space:
mode:
authorGuillaume Chevillot2008-03-13 10:34:32 +0100
committerGuillaume Chevillot2008-03-13 10:34:32 +0100
commit65baffda4311b55c9d4026d84c1c1544d0ee7aa4 (patch)
treecef12af16ced96358a4cbf163db674d8ba8a4f14 /analog/motor-power-avr/src/mp_pwm_LR_.c
parent7e1e72e29349a8248901d4d4f466d1c9b556344d (diff)
- Add current limitation management (not tested yet !) :
- Add current limitation PWM generation - Add external current limitation interrupts management - Update current limitation software part - Update TODO list (try to reduce it...)
Diffstat (limited to 'analog/motor-power-avr/src/mp_pwm_LR_.c')
-rw-r--r--analog/motor-power-avr/src/mp_pwm_LR_.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/analog/motor-power-avr/src/mp_pwm_LR_.c b/analog/motor-power-avr/src/mp_pwm_LR_.c
index e3ec252c..c35dc5df 100644
--- a/analog/motor-power-avr/src/mp_pwm_LR_.c
+++ b/analog/motor-power-avr/src/mp_pwm_LR_.c
@@ -13,6 +13,7 @@ static uint8_t curLim_soft;
// state_L_ : x - Inhib - changeDir - Dir - x - x - x - x
// Timer_L_ : timer dedicated to Left side
+/** Initialize timers for left and right side PWM generation */
void init_timer_LR_(void) {
init_pwm_L_();
init_pwm_R_();
@@ -31,11 +32,22 @@ void init_timer_LR_(void) {
TCCR_R_ = TCCR_LR_CFG;
}
+/** Initialize the timer for left and right current limitation */
void init_curLim (void) {
- // TODO : set interrupts
- curLim_soft = 0x80;
- curLim_bat = 0x00;
- curLim_temp = 0x00;
+ curLim_soft = CURLIM_MAX;
+ curLim_bat = CURLIM_MAX;
+ curLim_temp = CURLIM_MAX;
+
+ // Configure and run current limit PWM
+ TCCR1A = TCCRA_LR_CFG;
+ TCCR1B = TCCRB_LR_CFG;
+
+ // Configure and enable INT0 and INT1
+ MCUCR |= MCUCR_LR_CFG;
+ GICR |= GICR_LR_CFG;
+
+ // Apply the current limitation
+ update_curLim();
}
uint8_t get_curLim_temp (uint8_t temperature) {
@@ -46,13 +58,15 @@ uint8_t get_curLim_bat (uint8_t battery) {
return (battery - 40) >> 2; // TODO : ajuster la fonction de transfert
}
-// this function shall be called after each adjustment of any current limit
-void update_curLim(void) {
+/** Update the current limitation PWM
+ * this function shall be called after each adjustment of any current limit */
+inline void update_curLim(void) {
uint8_t curLim_tmp;
// search for MIN(curLim_soft, curLim_temp, curLim_bat)
curLim_tmp = curLim_soft;
+ /* TODO: implement curLim_temp and curLim_bat
if (curLim_tmp > curLim_temp)
{
curLim_tmp = curLim_temp;
@@ -62,6 +76,7 @@ void update_curLim(void) {
{
curLim_tmp = curLim_bat;
}
+ */
if (curLim_tmp > CURLIM_MAX)
{
@@ -83,7 +98,7 @@ void launch_envTest(void) {
update_curLim();
}
-// set the software-programmed current limit
+/* Set the software-programmed current limitation */
void setCurLim_soft(uint8_t curLim) {
curLim_soft = curLim;
update_curLim();