Bi Polar step motor / Linux CNC

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,681
Hi.

I've been designing a bi polar step motor controller, based on the PIC 16F628 and the L293DNE IC. The plan is to control it with Linux CNC.

http://www.linuxcnc.org/


The output from Linux CNC's LPT is step and direction. One puls for each step. Direction is held LOW/HIGH.

I've made it on a breadboard, and need some feedback/thoughts/comments, before I start etching.

The program run through the steps according to the input. No "softstart" or PWM.

Rich (BB code):
// Program		: main_v3.c
// Description	: Program to control bi polar step motor
// Compiler		: Hi Tech C
// IDE			: MPLAB v8.83
// Date			: June 2012
// Author		: nerdegutta
// WEB			: www.nerdegutta.org


#include <htc.h>

#define _XTAL_FREQ 4000000

#define step1 5
#define step2 4
#define step3 6
#define step4 2
#define step5 10
#define step6 8
#define step7 9
#define step8 1

#define step RA0
#define dir RA1

#define stepDelay 7000

unsigned char stepPosition;

__CONFIG (FOSC_HS &
WDTE_ON &
PWRTE_ON &
MCLRE_OFF &
BOREN_OFF &
LVP_OFF &
CPD_OFF &
CP_OFF);


void main()
{
CMCON = 0x07;

TRISA = 0b00000011;
TRISB = 0b00000000;

PORTA = 0b00000000;
PORTB = 0b00000000;

stepPosition = 0;

while (1)
{
if (!dir)		// check if dir pin is high, 
{				// if it's high, go counterclockwise

if (step)
{
	stepPosition++;
	if (stepPosition > 8)
		{
		stepPosition = 1;
		}
	if (stepPosition == 1)
		{
		PORTB = step1;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 2)
		{
		PORTB = step2;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 3)
		{
		PORTB = step3;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 4)
		{
		PORTB = step4;
		__delay_us(stepDelay);
		PORTB = 0;
		}

	if (stepPosition == 5)
		{
		PORTB = step5;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 6)
		{
		PORTB = step6;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 7)
		{
		PORTB = step7;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 8)
		{
		PORTB = step8;
		__delay_us(stepDelay);
		PORTB = 0;
		}

} // end if step
} // end if dir

if (dir)		// check if dir pin is high
{				// if not high, go clockwise
if (step)
{
	stepPosition--;
	if (stepPosition < 1)
		{
		stepPosition = 8;
		}

	if (stepPosition == 8)
		{
		PORTB = step8;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 7)
		{
		PORTB = step7;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 6)
		{
		PORTB = step6;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 5)
		{
		PORTB = step5;
		__delay_us(stepDelay);
		PORTB = 0;
		}


	if (stepPosition == 4)
		{
		PORTB = step4;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 3)
		{
		PORTB = step3;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 2)
		{
		PORTB = step2;
		__delay_us(stepDelay);
		PORTB = 0;
		}
	if (stepPosition == 1)
		{
		PORTB = step1;
		__delay_us(stepDelay);
		PORTB = 0;
		}


} // end if step
} // end if !dir
	
} // end while
} // end main
 

Attachments

Top