fixed synchronization problem with spindle_control

This commit is contained in:
Simen Svale Skogsrud 2011-02-25 13:30:03 +01:00
parent a18a89c779
commit 4cac11ec86

View File

@ -25,24 +25,28 @@
#include <avr/io.h>
static int current_direction;
void spindle_init()
{
SPINDLE_ENABLE_DDR |= 1<<SPINDLE_ENABLE_BIT;
spindle_run(0, 0);
}
void spindle_run(int direction, uint32_t rpm)
{
st_synchronize();
if(direction >= 0) {
SPINDLE_DIRECTION_PORT &= ~(1<<SPINDLE_DIRECTION_BIT);
} else {
SPINDLE_DIRECTION_PORT |= 1<<SPINDLE_DIRECTION_BIT;
if (direction != current_direction) {
st_synchronize();
if(direction >= 0) {
SPINDLE_DIRECTION_PORT &= ~(1<<SPINDLE_DIRECTION_BIT);
} else {
SPINDLE_DIRECTION_PORT |= 1<<SPINDLE_DIRECTION_BIT;
}
SPINDLE_ENABLE_PORT |= 1<<SPINDLE_ENABLE_BIT;
current_direction = direction;
}
SPINDLE_ENABLE_PORT |= 1<<SPINDLE_ENABLE_BIT;
}
void spindle_stop()
{
st_synchronize();
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
spindle_run(0, 0);
}