comments again
This commit is contained in:
parent
0bf2830b30
commit
8434c011c8
4
Makefile
4
Makefile
@ -60,5 +60,5 @@ ebin: $(PRG)_eeprom.bin
|
|||||||
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
|
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
|
||||||
|
|
||||||
install: text
|
install: text
|
||||||
uisp -dprog=avr910 -dserial=/dev/ttyS0 -dspeed=115200 -dpart=M8 --erase --upload if=$(PRG).hex
|
# 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
|
avrdude -p m8 -c butterfly -b 115200 -P /dev/ttyUSB1 -u -e -V -U flash:w:$(PRG).hex
|
||||||
|
16
blmc.c
16
blmc.c
@ -122,6 +122,9 @@ void next_phase(void)
|
|||||||
blmc.rpm_tmp++;
|
blmc.rpm_tmp++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* starts motor, must not run from interrupt
|
||||||
|
*/
|
||||||
void spinup(void)
|
void spinup(void)
|
||||||
{
|
{
|
||||||
uint16_t time = 1000;
|
uint16_t time = 1000;
|
||||||
@ -135,18 +138,23 @@ void spinup(void)
|
|||||||
time -= (time / 24 +1);
|
time -= (time / 24 +1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* manual spinup complete, analog comperator takes control */
|
||||||
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_NORMAL;
|
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_NORMAL;
|
||||||
next_phase();
|
next_phase();
|
||||||
|
|
||||||
for (time = 0; time < 10; time++)
|
for (time = 0; time < 10; time++)
|
||||||
_delay_ms(20);
|
_delay_ms(20);
|
||||||
|
|
||||||
|
/* switch to desired pwm value */
|
||||||
blmc.flags = FLAG_PWM_NORMAL | FLAG_COM_NORMAL;
|
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)
|
void setpwm(uint8_t pwm)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (pwm >= 8) {
|
if (pwm >= 8) {
|
||||||
if (blmc.pwm == 0)
|
if (blmc.pwm == 0)
|
||||||
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
|
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
|
||||||
@ -158,20 +166,24 @@ void setpwm(uint8_t pwm)
|
|||||||
blmc.pwm = 0;
|
blmc.pwm = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* do spinup with small pwm */
|
||||||
if (blmc.flags & FLAG_PWM_SPINUP)
|
if (blmc.flags & FLAG_PWM_SPINUP)
|
||||||
pwm = 0x0f;
|
pwm = 0x0f;
|
||||||
else
|
else
|
||||||
pwm = blmc.pwm;
|
pwm = blmc.pwm;
|
||||||
|
|
||||||
|
/* raise current limit, TODO: magic value */
|
||||||
if (blmc.current > 120)
|
if (blmc.current > 120)
|
||||||
blmc.pwm_limit++;
|
blmc.pwm_limit++;
|
||||||
|
|
||||||
|
/* lower current limit */
|
||||||
else if (blmc.pwm_limit > 0)
|
else if (blmc.pwm_limit > 0)
|
||||||
blmc.pwm_limit--;
|
blmc.pwm_limit--;
|
||||||
|
|
||||||
if (blmc.pwm_limit > pwm)
|
if (blmc.pwm_limit > pwm)
|
||||||
blmc.pwm_limit = pwm;
|
blmc.pwm_limit = pwm;
|
||||||
|
|
||||||
|
/* set new value */
|
||||||
pwm -= blmc.pwm_limit;
|
pwm -= blmc.pwm_limit;
|
||||||
OCR1A = pwm;
|
OCR1A = pwm;
|
||||||
OCR1B = pwm;
|
OCR1B = pwm;
|
||||||
@ -201,8 +213,6 @@ ISR(ADC_vect)
|
|||||||
if (blmc.flags & FLAG_COM_NORMAL)
|
if (blmc.flags & FLAG_COM_NORMAL)
|
||||||
ACSR |= (1<<ACIE) | (1<<ACI);
|
ACSR |= (1<<ACIE) | (1<<ACI);
|
||||||
|
|
||||||
sei();
|
|
||||||
|
|
||||||
if (channel == SENSE_CURRENT) {
|
if (channel == SENSE_CURRENT) {
|
||||||
current_tmp += value;
|
current_tmp += value;
|
||||||
current_cnt++;
|
current_cnt++;
|
||||||
|
1
main.c
1
main.c
@ -58,6 +58,7 @@ ISR(TIMER0_OVF_vect)
|
|||||||
if (diff < 0x8 && blmc.flags == (FLAG_PWM_NORMAL | FLAG_COM_NORMAL))
|
if (diff < 0x8 && blmc.flags == (FLAG_PWM_NORMAL | FLAG_COM_NORMAL))
|
||||||
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
|
blmc.flags = FLAG_PWM_SPINUP | FLAG_COM_SPINUP;
|
||||||
|
|
||||||
|
/* calc rpm every second */
|
||||||
timer0_cnt++;
|
timer0_cnt++;
|
||||||
if (timer0_cnt == 50) {
|
if (timer0_cnt == 50) {
|
||||||
timer0_cnt = 0;
|
timer0_cnt = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user