/*! \brief Move the stepper motor one step. * * Makes the stepcounter inc/dec one value and outputs this to the * steppermotor. * This function works like a stepper motor controller, a call to the function * is the stepping pulse, and parameter 'inc' is the direction signal. * * \param inc Direction to move. * \return Stepcounter value. */ unsigned char sm_driver_StepCounter(signed char inc) { // Counts 0-1-...-6-7 in halfstep, 0-2-4-6 in fullstep static unsigned char counter = 0; // Update if(inc == CCW){ stepPosition--; } else{ stepPosition++; } #ifdef HALFSTEPS if(inc){ counter++; } else{ counter--; } #else if(inc){ counter += 2; } else{ counter -= 2; } #endif // Stay within the steptab counter &= 0x07; sm_driver_StepOutput(counter); return(counter); }
/*! \brief Init of peripheral devices. * * Setup IO, uart, stepper, timer and interrupt. */ void Init(void) { // Init of IO pins sm_driver_Init_IO(); // Init of uart InitUART(); // Set stepper motor driver output sm_driver_StepOutput(0); // Init of Timer/Counter1 speed_cntr_Init_Timer1(); __enable_interrupt(); }