new i2c commands: get/set parameters

This commit is contained in:
Olaf Rempel 2008-02-19 15:59:59 +01:00
parent 447c7ae484
commit ad0d837355
3 changed files with 33 additions and 12 deletions

12
blmc.c
View File

@ -145,14 +145,16 @@ void spinup(void)
}
/* manual spinup complete, analog comperator takes control */
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_NORMAL;
blmc.flags &= ~(FLAG_RUN_MASK);
blmc.flags |= FLAG_PWM_SPINUP | FLAG_COM_NORMAL;
next_phase();
for (time = 0; time < params.spinup_wait; time++)
_delay_ms(20);
/* switch to desired pwm value */
blmc.flags = FLAG_PWM_NORMAL | FLAG_COM_NORMAL;
blmc.flags &= ~(FLAG_RUN_MASK);
blmc.flags |= FLAG_PWM_NORMAL | FLAG_COM_NORMAL;
}
/*
@ -164,8 +166,10 @@ void setpwm(uint8_t pwm)
/* run motor *only* if there are no hard errors */
if (pwm >= params.pwm_min && !(blmc.flags & FLAG_HARDERR_MASK)) {
/* do a spinup */
if (blmc.pwm == 0)
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
if (blmc.pwm == 0) {
blmc.flags &= ~(FLAG_RUN_MASK);
blmc.flags |= FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
}
} else {
blmc.flags &= ~FLAG_RUN_MASK;

View File

@ -22,15 +22,17 @@
#include "main.h"
#include "blmc.h"
#include "eeprom.h"
extern struct blmc_ blmc;
extern struct ee_param params;
#define CMD_WAIT 0x00
#define CMD_GET_INFO 0x10
#define CMD_SET_PWM 0x21
#define CMD_GET_STATUS 0x22
// #define CMD_SET_PARAM 0x23
// #define CMD_GET_PARAM 0x24
#define CMD_SET_PARAM 0x23
#define CMD_GET_PARAM 0x24
#define CMD_BOOT_LOADER 0x2F
const static uint8_t info[16] = "blctrl m8-v1.1";
@ -58,6 +60,8 @@ ISR(TWI_vect)
case CMD_GET_INFO:
case CMD_SET_PWM:
case CMD_GET_STATUS:
case CMD_SET_PARAM:
case CMD_GET_PARAM:
bcnt++;
break;
@ -67,12 +71,17 @@ ISR(TWI_vect)
break;
}
} else if (bcnt == 1) {
if (cmd == CMD_SET_PWM)
setpwm(TWDR);
} else if (cmd == CMD_SET_PWM) {
setpwm(TWDR);
bcnt = 0;
} else if (cmd == CMD_SET_PARAM) {
((uint8_t *)&params)[bcnt++ -1] = TWDR;
if (bcnt > sizeof(params)) {
write_parameters();
bcnt = 0;
}
} else {
bcnt = 0;
}
@ -124,6 +133,12 @@ ISR(TWI_vect)
}
break;
case CMD_GET_PARAM:
TWDR = ((uint8_t *)&params)[bcnt++];
if (bcnt > sizeof(params))
bcnt = 0;
break;
default:
TWDR = 0xFF;
break;

6
main.c
View File

@ -58,8 +58,10 @@ ISR(TIMER0_OVF_vect)
blmc.rpm_tmp_old = blmc.rpm_tmp;
/* too few commutations while running -> do a spinup */
if (diff < 0x8 && (blmc.flags & FLAG_RUN_MASK) == (FLAG_PWM_NORMAL | FLAG_COM_NORMAL))
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
if (diff < 0x8 && (blmc.flags & FLAG_RUN_MASK) == (FLAG_PWM_NORMAL | FLAG_COM_NORMAL)) {
blmc.flags &= ~(FLAG_RUN_MASK);
blmc.flags |= FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
}
/* set pwm again (adjust current limit) */
setpwm(blmc.pwm);