Silicon Laboratories Stepper Machine Bedienungsanleitung Seite 29

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 36
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 28
AN155
Rev. 1.1 29
{
if (target > Position)
{
Forward = 1; // set forward flag
length = target - Position; // subtract smaller (position)
}
else
{
Forward = 0; // clear forward flag
length = Position - target; // subtract smaller (target)
}
if (length < 1024) // if short move
MaxTableIndex = length>>2; // divide length by 4
else
MaxTableIndex = 0xff; // else max is 255
SlewCount = length; // build value in SlewCount
SlewCount -= MaxTableIndex; // subtract MaxTableIndex twice
SlewCount -= MaxTableIndex;
SlewCount--; // Subtract one to account first step
TableIndex = 0; // init table index
motorState = ACCELERATE; // init motor state
TL0 = -100; // move starts in 100 ticks
TH0 = 0xFF; // extend sign
LED = ON; // turn on LED
ET0 = 1; // enable Timer0 interrupts
TR0 = 1; // start Timer0
}
else
{
doneFlag=1; // if done display message
}
}
//-----------------------------------------------------------------------------
// Timer_ISR()
// This is the timer interrupt service routine for the stepper motor.
// First the PatternIndex and Position are incremented or decremented
// depending on the direction of the motor. Then the new pattern is
// output to the stepper motor. Nested if..else statements are used to
// determine the if the motor is in the acceleration, slewing, or
// deceleration phase. The TableIndex and SlewCount are modified
// accordingly. When the move is complete, further output compares and
// interrupts are disabled.
//
void Timer_ISR (void) interrupt 1
{
unsigned char TableValue;
unsigned int offset;
udblbyte time;
if (Forward) // if forward
{
PatternIndex++; // increment step pattern
PatternIndex &= 0x07; // fix modulus 8 counter
Position++; // increment Position
}
else
{
PatternIndex--; // decrement step pattern
Seitenansicht 28
1 2 ... 24 25 26 27 28 29 30 31 32 33 34 35 36

Kommentare zu diesen Handbüchern

Keine Kommentare