diff --git a/Makefile b/Makefile index d7e3aaa..14a644e 100644 --- a/Makefile +++ b/Makefile @@ -60,5 +60,5 @@ ebin: $(PRG)_eeprom.bin $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ install: text - uisp -dprog=avr910 -dserial=/dev/ttyS0 -dspeed=115200 -dpart=M8 --erase --upload if=$(PRG).hex -# avrdude -p m8 -c butterfly -b 19200 -P /dev/ttyUSB0 -u -e -V -U flash:w:$(PRG).hex +# uisp -dprog=avr910 -dserial=/dev/ttyS0 -dspeed=115200 -dpart=M8 --erase --upload if=$(PRG).hex + avrdude -p m8 -c butterfly -b 115200 -P /dev/ttyUSB1 -u -e -V -U flash:w:$(PRG).hex diff --git a/blmc.c b/blmc.c index d1ee713..03d801c 100644 --- a/blmc.c +++ b/blmc.c @@ -122,6 +122,9 @@ void next_phase(void) blmc.rpm_tmp++; } +/* + * starts motor, must not run from interrupt + */ void spinup(void) { uint16_t time = 1000; @@ -135,18 +138,23 @@ void spinup(void) time -= (time / 24 +1); } + /* manual spinup complete, analog comperator takes control */ blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_NORMAL; next_phase(); for (time = 0; time < 10; time++) _delay_ms(20); + /* switch to desired pwm value */ blmc.flags = FLAG_PWM_NORMAL | FLAG_COM_NORMAL; } +/* + * sets new pwm value + * called from i2c-slave (set new value) and from timer (recalc current limit) + */ void setpwm(uint8_t pwm) { - if (pwm >= 8) { if (blmc.pwm == 0) blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_SPINUP; @@ -158,20 +166,24 @@ void setpwm(uint8_t pwm) blmc.pwm = 0; } + /* do spinup with small pwm */ if (blmc.flags & FLAG_PWM_SPINUP) pwm = 0x0f; else pwm = blmc.pwm; + /* raise current limit, TODO: magic value */ if (blmc.current > 120) blmc.pwm_limit++; + /* lower current limit */ else if (blmc.pwm_limit > 0) blmc.pwm_limit--; if (blmc.pwm_limit > pwm) blmc.pwm_limit = pwm; + /* set new value */ pwm -= blmc.pwm_limit; OCR1A = pwm; OCR1B = pwm; @@ -201,8 +213,6 @@ ISR(ADC_vect) if (blmc.flags & FLAG_COM_NORMAL) ACSR |= (1<