![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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
__________________ "Better to have tried and failed, than to have failed to try" | |
| |
| | #2 | |
| Quote:
Does this help.? http://www.piclist.com/techref/picli...egen/delay.htm
__________________ Eric " Good enough is Perfect " I will NOT answer PM's requesting technical help, please use the Forum PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/ | ||
| |
| | #3 |
|
Txs Eric, Will take a look at it.
__________________ "Better to have tried and failed, than to have failed to try" | |
| |
| | #4 |
|
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.
__________________ Eric " Good enough is Perfect " I will NOT answer PM's requesting technical help, please use the Forum PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/ | |
| |
| | #5 |
|
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
| |
| |
| | #6 |
|
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.
__________________ "Better to have tried and failed, than to have failed to try" | |
| |
| | #7 | |
| Quote:
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.?
__________________ Eric " Good enough is Perfect " I will NOT answer PM's requesting technical help, please use the Forum PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/ | ||
| |
| | #8 |
|
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
__________________ "Better to have tried and failed, than to have failed to try" | |
| |
|
| Tags |
| delay, pic, question |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| PIC question from a PIC Virgin | bigal_scorpio | General Electronics Chat | 9 | 21st March 2008 05:45 PM |
| Atmel, assembly:displaying on lcd | Haidy | Micro Controllers | 13 | 11th February 2008 09:13 PM |
| Motor Controllers and serial comm? | RedCore | Micro Controllers | 18 | 3rd July 2007 02:27 AM |
| Delay routine not working | gregmcc | Micro Controllers | 6 | 18th September 2005 06:23 PM |
| Effects | stephenpic | Micro Controllers | 6 | 19th January 2004 12:57 PM |