|
|
@ -23,9 +23,10 @@ |
|
|
|
* No Error, Motor running SLOW - |
|
|
|
* Current Limit - ON |
|
|
|
* i2c Timeout - ON (not implemented yet) |
|
|
|
* Undervoltage OFF SLOW (not implemented yet) |
|
|
|
* Overcurrent (Hard Limit) OFF FAST (not implemented yet) |
|
|
|
* SELFTEST failed SLOW SLOW (not implemented yet) |
|
|
|
* Undervoltage OFF SLOW |
|
|
|
* Overcurrent (Hard Limit) OFF FAST |
|
|
|
* SELFTEST failed FAST FAST (not implemented yet) |
|
|
|
* EEPROM invalid SLOW SLOW |
|
|
|
*/ |
|
|
|
|
|
|
|
#include <avr/io.h> |
|
|
@ -133,43 +134,54 @@ int main(void) |
|
|
|
/* I2C Init: keep Address from bootloader, Auto ACKs with Interrupts */ |
|
|
|
TWCR = (1<<TWEA) | (1<<TWEN) | (1<<TWIE); |
|
|
|
|
|
|
|
read_parameters(); |
|
|
|
blmc.flags = 0x00; |
|
|
|
if (read_parameters()) |
|
|
|
blmc.flags |= FLAG_INVALIDEEPROM; |
|
|
|
|
|
|
|
sei(); |
|
|
|
|
|
|
|
while (1) { |
|
|
|
uint8_t ledX[2] = { 0x00, 0x00 }; |
|
|
|
|
|
|
|
/* get motor status: spinup, running or off */ |
|
|
|
if (blmc.flags & FLAG_RUN_MASK) { |
|
|
|
if (blmc.flags & (FLAG_COM_SPINUP | FLAG_PWM_SPINUP)) |
|
|
|
led[0] = LED_FAST; |
|
|
|
ledX[0] = LED_FAST; |
|
|
|
else |
|
|
|
led[0] = LED_SLOW; |
|
|
|
ledX[0] = LED_SLOW; |
|
|
|
} else { |
|
|
|
led[0] = LED_ON; |
|
|
|
ledX[0] = LED_ON; |
|
|
|
} |
|
|
|
|
|
|
|
/* soft errors (current limit, i2c timeout) */ |
|
|
|
if (blmc.flags & FLAG_SOFTERR_MASK) |
|
|
|
led[1] = LED_ON; |
|
|
|
ledX[1] = LED_ON; |
|
|
|
|
|
|
|
/* hard errors */ |
|
|
|
if (blmc.flags & FLAG_HARDERR_MASK) { |
|
|
|
led[0] = LED_OFF; |
|
|
|
if (blmc.flags & FLAG_CURRENTLIMIT) { |
|
|
|
led[1] = LED_FAST; |
|
|
|
ledX[0] = LED_OFF; |
|
|
|
ledX[1] = LED_FAST; |
|
|
|
|
|
|
|
} else if (blmc.flags & FLAG_UNDERVOLTAGE) { |
|
|
|
led[1] = LED_SLOW; |
|
|
|
ledX[0] = LED_OFF; |
|
|
|
ledX[1] = LED_SLOW; |
|
|
|
|
|
|
|
} else if (blmc.flags & FLAG_SELFTESTFAILED) { |
|
|
|
led[0] = LED_SLOW; |
|
|
|
led[1] = LED_SLOW; |
|
|
|
ledX[0] = LED_FAST; |
|
|
|
ledX[1] = LED_FAST; |
|
|
|
|
|
|
|
} else if (blmc.flags & FLAG_INVALIDEEPROM) { |
|
|
|
ledX[0] = LED_SLOW; |
|
|
|
ledX[1] = LED_SLOW; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!(blmc.flags & (FLAG_SOFTERR_MASK | FLAG_HARDERR_MASK))) |
|
|
|
led[1] = LED_OFF; |
|
|
|
ledX[1] = LED_OFF; |
|
|
|
|
|
|
|
led[0] = ledX[0]; |
|
|
|
led[1] = ledX[1]; |
|
|
|
|
|
|
|
/* do a spinup from main loop (blocking for > 200ms) */ |
|
|
|
if (blmc.flags & FLAG_COM_SPINUP) |
|
|
|