Silicon Laboratories Stepper Machine User Manual Page 30

  • Download
  • Add to my manuals
  • Print
  • Page
    / 36
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 29
AN155
30 Rev. 1.1
PatternIndex &= 0x07; // fix modulus 8 counter
Position--; // increment Position
}
// output step pattern, set bit 7 because it is an input
P0 = StepPattern[PatternIndex] | 0x80;
// determine motor state based on counter values
if (SlewCount == 0)
if (TableIndex == 0)
motorState = DONE;
else
motorState = DECELERATE;
else
if (TableIndex < MaxTableIndex)
motorState = ACCELERATE;
else
motorState = SLEWING;
if (motorState == DONE)
{
ET0 = 0; // disable T0 interrupts
TR0 = 0; // stop T0
LED = OFF; // turn off LED
doneFlag = 1; // display done message
}
else
{
// get value from table, multiply by T zero
TableValue = StepTable[TableIndex];
offset = MUL8x8(Tzero, TableValue);
TR0 = 0; // stop Timer0
time.b.lo = TL0; // read lo byte first
time.b.hi = TH0; // read hi byte second
time.w = time.w - offset; // calculate new time
TL0 = time.b.lo; // write lo byte first
TH0 = time.b.hi; // write hi byte second
TR0 = 1; // start Timer0
if (motorState == DECELERATE) // if decelerating
TableIndex--; // decrement table index
else if(motorState == ACCELERATE)// if accelerating
TableIndex++; // increment table index
else if (motorState == SLEWING) // if slewing
SlewCount--; // decrement slewCount
ET0 = 1; // enable Timer0 interrupts
}
}
//-----------------------------------------------------------------------------
unsigned int MUL8x8(unsigned char a, unsigned char b)
{
unsigned int ab;
ab = (unsigned int) a * b; // cast a to int to trick compiler
return ab; // return int
}
//-----------------------------------------------------------------------------
void puts(char *string) // puts a string into send buffer
{
while(*string) // while not null character
{
Page view 29
1 2 ... 25 26 27 28 29 30 31 32 33 34 35 36

Comments to this Manuals

No comments