Stepper motor MOSFET drive

Introduction
Demonstration of the 'Stepper
motor MOSFET drive' sub-circuit. This sub-circuit
can produce three different step patterns for
a unipolar 6 or 8 wire stepper motor.
The target is a PIC16F84 running at
4Mhz.
Operation
Drive stepper motor clock-wise 50 steps, then anti-clockwise
100 steps. Repeat for each step mode.
Application code
Below is the application code for this project. To
use it, select and copy (ctr-insert) the code below
and past it into a text editor and save as a 'C' file
in your working directory. You may also need to change
the build output path using 'Project | Options'
///////////////////////////////////////////////////////////////////////
//// ASTEP1.C ////
//// ////
//// Demonstration of 'Stepper motor MOSFET drive' sub-circuit. ////
//// Performs stepper functions in 3 step modes. ////
//// More of the same sub-circuit can be added to produce a ////
//// multi axis stepper drive. ////
//// ////
//// This program is an example of how your application code is ////
//// is organised. Note the #include "astep1.c", this include ////
//// file was generated by QuickBuilder and contains all ////
//// driver code. ////
//// ////
//// This demo is intended for a PIC16F84. ////
//// Compiled using CCS 'C' visit www.quickbuilder.co.uk/qb/ccs ////
//// for more information. ////
///////////////////////////////////////////////////////////////////////
#include <16f84.H>
#fuses hs,nowdt,noprotect,put
#case
#define PORTA 5
#define PORTB 6
#define TRISA 0x85
#define TRISB 0x86
#include "step1.c"
#int_rtcc
void RTCC_ISR()
{
STEP_1DO();
}
main() {
// initialise sub-circuits and rtcc interrupts
//--------------------------------------------
INIT_SUB_CIRCUITS();
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_2);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
// main loop
//----------
while(1) {
STEP_1SPEEDT = 50;
// step clock wise 50 steps followed by 1 seccond pause
STEP_1DIR = 0;
STEP_1STEPS = 50;
while(STEP_1STEPS);
delay_ms(1000);
// step anti-clock wise 100 steps followed by 0.5 seccond pause
STEP_1DIR = -1;
STEP_1STEPS = 100;
while(STEP_1STEPS);
delay_ms(3000);
// demo next step mode
if (++STEP_1MODE > 2)
STEP_1MODE =0;
}
}
|