Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Nigle's Tutorial #8 (PWM for Stepper Motor)

Status
Not open for further replies.

aljamri

Member
Hi everybody,

I'm doing Nigle's Tutorial #8, which is PWM for stepper motor control. I'm using PM20S stepper motor with 12v supply.

https://www.electro-tech-online.com/custompdfs/2010/06/pm20s020.pdf

I did Nigle's "Stepper Motor Driver Board"



But when connected both using PIC16F876a board, motor did not move, although it got stuck.

My question is: Do I need to use driver IC such as UNL3001 or not ?

Thanks
 
Last edited by a moderator:
Hi everybody,

I'm doing Nigle's Tutorial #8, which is PWM for stepper motor control. I'm using PM20S stepper motor with 12v supply.

https://www.electro-tech-online.com/custompdfs/2010/06/pm20s020-1.pdf

I did Nigle's "Stepper Motor Driver Board"



But when connected both using PIC16F876a board, motor did not move, although it got stuck.

My question is: Do I need to use driver IC such as UNL3001 or not ?

No you don't, but the PWM tutorial is nothing to do with the stepper motor board, I never got round to writing the stepper motor tutorial, so just left the board layout as an example of how to drive a stepper. The PWM 'tutorial' is just an example of how to use the PWM, and came about because I was getting repeated questions about PWM.
 
Last edited by a moderator:
Thanks for reply.

So I've change a little in Tutorial 1.1 ( LED ON/OFF ), I've added the following:


Code:
Loop
	
	bsf	PORTB,0	;turn on RB0 only!
	call    Delay	;this waits for a while!
	bcf	PORTB,0	;turn off RB0 only!.
	
	bsf	PORTB,1	;turn on RB1 only!
	call    Delay	;this waits for a while!
	bcf	PORTB,1	;turn off RB1 only!.

	bsf	PORTB,2	;turn on RB2 only!
	call    Delay	;this waits for a while!
	bcf	PORTB,2	;turn off RB2 only!.

	bsf	PORTB,3	;turn on RB3 only!
	call    Delay	;this waits for a while!
	bcf	PORTB,3	;turn off RB3 only!.

	goto	Loop	;go back and do it again


keeping the same delay of 250ms, I've no any result, even no stuck in the motor.

Is this enough to control the stepper motor.
 
Last edited:
Post all your code. Even if you messed up the connections your motor should be "stuck".

Mike.
 
My motor is working fine.

I re-define my motor coils as per this web site:

**broken link removed**

then used the following code( from Nigel's tutorial 1.3 ):

Code:
;Tutorial 1.3 - Nigel Goodwin 2002
	LIST	p=16F628		;tell assembler what chip we are using
	include "P16F628.inc"		;include the defaults for the chip
	__config 0x3D18			;sets the configuration settings (oscillator type etc.)

	cblock 	0x20 			;start of general purpose registers
		count1 			;used in delay routine
		counta 			;used in delay routine 
		countb 			;used in delay routine
	endc
	
	org	0x0000			;org sets the origin, 0x0000 for the 16F628,
						;this is where the program starts running	
	movlw	0x07
	movwf	CMCON		;turn comparators off (make it like a 16F84)

   	bsf 	STATUS,RP0	;select bank 1
   	movlw 	b'00000000'	;set PortB all outputs
   	movwf 	TRISB
	movwf	TRISA		;set PortA all outputs
	bcf		STATUS,RP0	;select bank 0
	clrf	PORTA
	clrf	PORTB		;set all outputs low

Loop
	
	bsf		PORTB,0			;turn on RB0 only!
	call	Delay			;this waits for a while!
	bcf		PORTB,0			;turn off RB0 only!.
	
	bsf		PORTB,1			;turn on RB1 only!
	call	Delay			;this waits for a while!
	bcf		PORTB,1			;turn off RB1 only!.

	bsf		PORTB,2			;turn on RB2 only!
	call	Delay			;this waits for a while!
	bcf		PORTB,2			;turn off RB2 only!.

	bsf		PORTB,3			;turn on RB3 only!
	call	Delay			;this waits for a while!
	bcf		PORTB,3			;turn off RB3 only!.

	goto	Loop			;go back and do it again

Delay
	movlw	d'250'			;delay 250 ms (4 MHz clock)
	movwf	count1
d1	movlw	0xC7			;delay 1mS
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00

	end


Now I'll play with the delay and hope for smoother operation and then I'll try the switch board.

Thank for all, and for you Nigle for your useful tutorials. :D
 
Last edited:
changing the Delay to 10ms, the rotation is smooth.
 
I sorted out my stepper connections using a simple battery, and found which order they need to be in for rotation.
I've did the same for my Motor, and found that they are not aranged as per what is in the motor small PCB.

know I'm trying to combine YOUR switch Tutorial with it to control two motors, each with two switches to be able to control the stand of my friedn's Vedio Camera.

I'll post if any progress achived, sure if a problem is arised.

Thanks Nigel.
 
here I'm again with something:

I've made some combination between NG's LED and Switch Tutorials and came out with the following code:

Code:
	LIST	p=16F628	;tell assembler what chip we are using
	include "P16F628.inc"	;include the defaults for the chip
	__config 0x3D18	;sets the configuration settings

	cblock 	0x20 		;start of general purpose registers
		count
		count1 		;used in delay routine
		counta 		;used in delay routine 
		countb 		;used in delay routine
	endc
		MOTPORT	Equ	PORTB	;set constant MOTPORT = 'PORTA'
		SWPORT	Equ	PORTB	;set constant SWPORT = 'PORTA'
		MOTTRIS	Equ	TRISB	;set constant for TRIS register
		SW1		Equ	7	;set constants for the switches
		SW2		Equ	6
		SW3		Equ	5
		SW4		Equ	4
		LED1	Equ	3		;and for the LED's
		LED2	Equ	2
		LED3	Equ	1
		LED4	Equ	0

		SWDel	Set	Del50	;set the de-bounce delay (has to use 'Set' and not 'Equ')
		MTDel	Set	Del250	;set the Stepper Motor delay 


	;end of defines

		
	org	0x0000			;org sets the origin, 0x0000 for the 16F628,
					;this is where the program starts running	
	movlw	0x07
	movwf	CMCON		            ;turn comparators off (make it like a 16F84)
	
	   bsf 	             STATUS,RP0      ;select bank 1
	   movlw 	b'11110000'	;set PortA 4 inputs, 4 outputs
	   movwf 	MOTTRIS
	   bcf	            STATUS,RP0	;select bank 0
	   clrf	MOTPORT		;set all outputs low
	

Loop	
	btfss	SWPORT,SW1
	call	Switch1
	btfss	SWPORT,SW2
	call	Switch2
	btfss	SWPORT,SW3
	call	Switch3
	btfss	SWPORT,SW4
	call	Switch4
	goto	Loop

Switch1
	call	SWDel		;give switch time to stop bouncing
	btfsc	SWPORT,SW1	;check it's still pressed
	retlw	0x00		;return is not
	btfss	SWPORT,LED1	;see if LED1 is already lit
	goto	LED1ON


LED1ON
	
Start	clrf	count		;set counter register to zero
Read	movf	count,w		;put counter value in W
	call	TableF	
	movwf	MOTPORT
	call	Del250
	incf	count,w
	xorlw	d'4'		;check for last (4th) entry
	btfsc	STATUS,Z
	goto	Switch1		;if start from beginning
	incf	count,f		;else do next
	goto	Read

Switch2
	call	SWDel		;give switch time to stop bouncing
	btfsc	SWPORT,SW2	;check it's still pressed
	retlw	0x00		;return is not
	btfss	SWPORT,LED2	;see if LED2 is already lit
	goto	LED2ON


LED2ON
	
Start2	clrf	count		;set counter register to zero
Read2	movf	count,w		;put counter value in W
	call	TableR	
	movwf	MOTPORT
	call	Del250
	incf	count,w
	xorlw	d'4'		;check for last (4th) entry
	btfsc	STATUS,Z
	goto	Switch2		;if start from beginning
	incf	count,f		;else do next
	goto	Read2	


Switch3
	call	SWDel		;give switch time to stop bouncing
	btfsc	SWPORT,SW3	;check it's still pressed
	retlw	0x00		;return is not
	btfss	SWPORT,LED3	;see if LED3 is already lit
	goto	LED3ON


LED3ON
	
Start3	clrf	count		;set counter register to zero
Read3	movf	count,w		;put counter value in W
	call	TableF	
	movwf	MOTPORT
	call	Del250
	incf	count,w
	xorlw	d'4'		;check for last (4th) entry
	btfsc	STATUS,Z
	goto	Switch3		;if start from beginning
	incf	count,f		;else do next
	goto	Read3	


Switch4
	call	SWDel		;give switch time to stop bouncing
	btfsc	SWPORT,SW4	;check it's still pressed
	retlw	0x00		;return is not
	btfss	SWPORT,LED4	;see if LED4 is already lit
	goto	LED4ON

LED4ON
Start4	clrf	count		;set counter register to zero
Read4	movf	count,w		;put counter value in W
	call	TableR	
	movwf	MOTPORT
	call	Del250
	incf	count,w
	xorlw	d'4'		;check for last (4th) entry
	btfsc	STATUS,Z
	goto	Switch4		;if start from beginning
	incf	count,f		;else do next
	goto	Read4	


;;;; Forward Rotation Table

TableF	ADDWF   PCL,f		;data table for bit pattern
	retlw	b'00001000'
             retlw   b'00000100'
             retlw   b'00000010'
             retlw   b'00000001'

;;;; Reverse Rotation Table

TableR	ADDWF   PCL,f		;data table for bit pattern
	retlw	b'00000001'
        retlw   b'00000010'
        retlw   b'00000100'
        retlw   b'00001000'

;modified Delay routine, direct calls for specified times
;or load W and call Delay for a custom time.

Del0	retlw	0x00	;delay 0mS - return immediately
Del1	movlw	d'1'	;delay 1mS
	goto	Delay
Del5	movlw	d'5'	;delay 5mS
	goto	Delay
Del10	movlw	d'10'	;delay 10mS
	goto	Delay
Del20	movlw	d'20'	;delay 20mS
	goto	Delay
Del50	movlw	d'50'	;delay 50mS
	goto	Delay
Del100	movlw	d'100'	;delay 100mS
	goto	Delay
Del250	movlw	d'250'	;delay 250 ms
Delay	movwf	count1
d1	movlw	0xC7	;delay 1mS
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0
	
	decfsz	count1	,f
	goto	d1
	retlw	0x00
	end


when simulated using NG Switch Board:
,
this resulted in perfect working except that the last LED stays ON when the push button released. At the beginning I've tried to change this, but after a thought, although this will consume power, but it will hold the stand in its place regardless the wight of the camera, so I kept it as it is.

But when tried to change the Switch Port into Port A, Nothing is working.
 
Last edited:
Have you got pullup resistors on the port?.

I'm using your 16F628 board and connected the switch board to Port B connector, and the stepper motor board to Port B second connector, both LED and Motor rotates correctly. When connected switch board to Port A connector, no motion in neither LED nor Motor.

Do I have to hve Pullup resistor?
 
I'm using your 16F628 board and connected the switch board to Port B connector, and the stepper motor board to Port B second connector, both LED and Motor rotates correctly. When connected switch board to Port A connector, no motion in neither LED nor Motor.

Do I have to hve Pullup resistor?

If you're using the switch board, then it has pullup resistors built-in.
 
Status
Not open for further replies.

Latest threads

Back
Top