new i2c commands: get/set parameters
This commit is contained in:
parent
447c7ae484
commit
ad0d837355
12
blmc.c
12
blmc.c
@ -145,14 +145,16 @@ void spinup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* manual spinup complete, analog comperator takes control */
|
/* 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();
|
next_phase();
|
||||||
|
|
||||||
for (time = 0; time < params.spinup_wait; time++)
|
for (time = 0; time < params.spinup_wait; time++)
|
||||||
_delay_ms(20);
|
_delay_ms(20);
|
||||||
|
|
||||||
/* switch to desired pwm value */
|
/* 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 */
|
/* run motor *only* if there are no hard errors */
|
||||||
if (pwm >= params.pwm_min && !(blmc.flags & FLAG_HARDERR_MASK)) {
|
if (pwm >= params.pwm_min && !(blmc.flags & FLAG_HARDERR_MASK)) {
|
||||||
/* do a spinup */
|
/* do a spinup */
|
||||||
if (blmc.pwm == 0)
|
if (blmc.pwm == 0) {
|
||||||
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
|
blmc.flags &= ~(FLAG_RUN_MASK);
|
||||||
|
blmc.flags |= FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
blmc.flags &= ~FLAG_RUN_MASK;
|
blmc.flags &= ~FLAG_RUN_MASK;
|
||||||
|
27
i2c-slave.c
27
i2c-slave.c
@ -22,15 +22,17 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "blmc.h"
|
#include "blmc.h"
|
||||||
|
#include "eeprom.h"
|
||||||
|
|
||||||
extern struct blmc_ blmc;
|
extern struct blmc_ blmc;
|
||||||
|
extern struct ee_param params;
|
||||||
|
|
||||||
#define CMD_WAIT 0x00
|
#define CMD_WAIT 0x00
|
||||||
#define CMD_GET_INFO 0x10
|
#define CMD_GET_INFO 0x10
|
||||||
#define CMD_SET_PWM 0x21
|
#define CMD_SET_PWM 0x21
|
||||||
#define CMD_GET_STATUS 0x22
|
#define CMD_GET_STATUS 0x22
|
||||||
// #define CMD_SET_PARAM 0x23
|
#define CMD_SET_PARAM 0x23
|
||||||
// #define CMD_GET_PARAM 0x24
|
#define CMD_GET_PARAM 0x24
|
||||||
#define CMD_BOOT_LOADER 0x2F
|
#define CMD_BOOT_LOADER 0x2F
|
||||||
|
|
||||||
const static uint8_t info[16] = "blctrl m8-v1.1";
|
const static uint8_t info[16] = "blctrl m8-v1.1";
|
||||||
@ -58,6 +60,8 @@ ISR(TWI_vect)
|
|||||||
case CMD_GET_INFO:
|
case CMD_GET_INFO:
|
||||||
case CMD_SET_PWM:
|
case CMD_SET_PWM:
|
||||||
case CMD_GET_STATUS:
|
case CMD_GET_STATUS:
|
||||||
|
case CMD_SET_PARAM:
|
||||||
|
case CMD_GET_PARAM:
|
||||||
bcnt++;
|
bcnt++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -67,12 +71,17 @@ ISR(TWI_vect)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (bcnt == 1) {
|
} else if (cmd == CMD_SET_PWM) {
|
||||||
if (cmd == CMD_SET_PWM)
|
setpwm(TWDR);
|
||||||
setpwm(TWDR);
|
|
||||||
|
|
||||||
bcnt = 0;
|
bcnt = 0;
|
||||||
|
|
||||||
|
} else if (cmd == CMD_SET_PARAM) {
|
||||||
|
((uint8_t *)¶ms)[bcnt++ -1] = TWDR;
|
||||||
|
if (bcnt > sizeof(params)) {
|
||||||
|
write_parameters();
|
||||||
|
bcnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bcnt = 0;
|
bcnt = 0;
|
||||||
}
|
}
|
||||||
@ -124,6 +133,12 @@ ISR(TWI_vect)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CMD_GET_PARAM:
|
||||||
|
TWDR = ((uint8_t *)¶ms)[bcnt++];
|
||||||
|
if (bcnt > sizeof(params))
|
||||||
|
bcnt = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
TWDR = 0xFF;
|
TWDR = 0xFF;
|
||||||
break;
|
break;
|
||||||
|
6
main.c
6
main.c
@ -58,8 +58,10 @@ ISR(TIMER0_OVF_vect)
|
|||||||
blmc.rpm_tmp_old = blmc.rpm_tmp;
|
blmc.rpm_tmp_old = blmc.rpm_tmp;
|
||||||
|
|
||||||
/* too few commutations while running -> do a spinup */
|
/* too few commutations while running -> do a spinup */
|
||||||
if (diff < 0x8 && (blmc.flags & FLAG_RUN_MASK) == (FLAG_PWM_NORMAL | FLAG_COM_NORMAL))
|
if (diff < 0x8 && (blmc.flags & FLAG_RUN_MASK) == (FLAG_PWM_NORMAL | FLAG_COM_NORMAL)) {
|
||||||
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
|
blmc.flags &= ~(FLAG_RUN_MASK);
|
||||||
|
blmc.flags |= FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
|
||||||
|
}
|
||||||
|
|
||||||
/* set pwm again (adjust current limit) */
|
/* set pwm again (adjust current limit) */
|
||||||
setpwm(blmc.pwm);
|
setpwm(blmc.pwm);
|
||||||
|
Loading…
Reference in New Issue
Block a user