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.

PIC Delay question

Status
Not open for further replies.

Trevors

New Member
Hello everybody,
I'm trying to drive a stepper motor that I got from a faulty flatbed scanner. I am driving it via a ULN2004. The ULN2004 is being driven from the outputs of a 4154(4 to 16 decoder) I,m using RB1,2,3,4. I had this set up for another project and chose to use the same code. I've managed to get it to step but cannot generate a delay short enough to make it run continuosly. If I use two loops and load both registers with 01h the delay is too long. If I use one loop and load the register with FFh ,the delay is too short and the motor doesn't run at all. Please help with my code. See attached file. Help appreciated
 

Attachments

  • Stepper2.asm
    1.9 KB · Views: 147
Trevors said:
Hello everybody,
I'm trying to drive a stepper motor that I got from a faulty flatbed scanner. I am driving it via a ULN2004. The ULN2004 is being driven from the outputs of a 4154(4 to 16 decoder) I,m using RB1,2,3,4. I had this set up for another project and chose to use the same code. I've managed to get it to step but cannot generate a delay short enough to make it run continuosly. If I use two loops and load both registers with 01h the delay is too long. If I use one loop and load the register with FFh ,the delay is too short and the motor doesn't run at all. Please help with my code. See attached file. Help appreciated

Hi Tervor,
Does this help.?
 
hi trevor,

Just a thought, did you delete the delays you had in the 4514 mux, when driving the LED's???

If you have a spare analog pin, its easy to connect a pot and control the stepper rate by using the pot.;)
 
Standardize your delays. Make a set for micro seconds, milli seconds, and seconds similar to my code below.
Code:
Set LED
Call usec100
Call usec100
Clear LED
Call usec100
Call usec100
Loop

movlw .50
movw milli_time        ; Load milli_time only once because it is persisted into milli_time_temp.
Set LED                ; A.K.A non-volatile.
Call milli_delay
Clear LED
Call milli_delay
Loop



Code:
USEC_10:
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	RETURN
USEC_20:
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	RETURN
USEC_100:			;----FORMULA--4MHZ CLOCK---------
	MOVLW	.31		;  [3(CNTJ-1)+2] + CHANGE
	MOVWF	CNTJ		;  CHANGE = 8 USEC
	DECFSZ	CNTJ, F		;  [3(CNTJ-1)+2] + 8
	GOTO	$ - 1	        ;--------------------------------
	NOP
	NOP
	RETURN

MS_DELAY:
	MOVF	MILLI_TIME, W    ;---------------------------------------
        MOVW    MILLI_TIME_TEMP  ;MILLI SECOND DELAY
MS_LOOP	MOVLW	0XA4             ;DELAY = X MILLI-SECOND (4MHZ CLOCK).
	MOVWF	CNTJ             ;---------------------------------------
	DECFSZ	CNTJ, F
	GOTO	$ - 1
	MOVLW	0XA4
	MOVWF	CNTJ
	DECFSZ	CNTJ, F
	GOTO	$ - 1

	DECFSZ	MS_TIME_TEMP, F	;IF COUNTER ENDS,
	GOTO	MS_LOOP		;ELSE- REPEAT
	RETURN			;THEN- EXIT LOOP
 
Hi Eric,
Yes, I still have the same delays. Don't have any analog pins though. Using a 16F84a, but I have purchased a 16F628a. Going to start using that soon. How would I implement the pot idea?

Txs for those delays Donniedj. I'm sure those will come in handy.
 
Trevors said:
Hi Eric,
Yes, I still have the same delays. Don't have any analog pins though. Using a 16F84a, but I have purchased a 16F628a. Going to start using that soon. How would I implement the pot idea?

Txs for those delays Donniedj. I'm sure those will come in handy.

hi Trevors,
Connect a variable resistor say a 5K0, one end of the pot to 0V and the other to the +5V rail, wiper to the analog pin of the PIC.

Use the ADC value as right justified to get 0 thru d'1023,, call the value say Dv.

To get a 'useful' value of Dv and to set the 'minimum' delay value of Dv do this:

Delay= (Dv * multiplier) + shortest delay required.

Assume for explanation that Dv is 0 from the ADC registers.
then Delay = shortest delay time required

Assume that Dv is 1023 from the ADC registers
then Delay = (1023 * multiplier) + shortest delay === Longest delay time.

You will have to determine the values of the 'multipler' and 'shortest delay required' to suit your motor and application.

I would start with values of 'multiplier' = 1 and 'shortest delay' =1000

Once you have determined the max and min value, as the speed pot is adjusted, the ADC output is read and the Delay calculated from this formula and loaded into a 'DELAY' subr.

I hope you can follow this.?:)
 
Hi Eric,
I understand what you've done. I need to get a little more familiar with the 628 though.

Txs again for your feedback / advice
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top