PDA

View Full Version : Output settings for 16F88



PICante
- 15th June 2008, 00:30
Hi all!

I run into a strange (or I made some stupid error) problem. I hope some of you guys can give me a clue here.
First the circuit, 16F88, LCD (not yet involved), two LED’s and a few resistors. One LED at pin 18 another one at pin 3. The circuit will eventually control a stepper motor via an UNC5804 (pin 18 for direction and pin 3 pulse) the LED’s are temporary for test of the outputs.

Now the problem, PORTA.1 set high the LED lit OK but as soon as PORTA.4 goes high the first one goes low. ?

The code:

'************************************************* ***************
'* Name : STEP2.BAS *
'* Date : 2008-06-14 *
'* Version : 1.0 *
'* Notes : 16F88 - LCD moved to portb *
'************************************************* ***************


define OSC 8
OSCCON =%01110000 ' INTRC = 8MHz
TRISB = %00000000 ' PORTB = outputs
TRISA = %00000000 ' PORTA = outputs
CMCON = 7 ' Compar. = off

gosub MOVELCD

A var word ' A = word variabel
DI var PORTA.1 ' direction - pin 18
ST var PORTA.4 ' step - pin 3



DI = 1
pause 500
DI = 0
pause 500
ST = 1
pause 500
ST = 0


MAIN:

DI = 1
pause 500
for a = 0 to 200
ST = 1
pause 2
ST = 0
next a


DI = 0
pause 500
for a = 200 to 0 step -1
ST = 1
pause 2
ST = 0
next a

pause 1000

goto main


end




MOVELCD:

define LCD_DREG PORTB
define LCD_DBIT 0
define LCD_RSREG PORTB
define LCD_RSBIT 5
define LCD_EREG PORTB
define LCD_EBIT 4
define LCD_BITS 4
define LCD_LINES 2
Pause 800

return




Thanks!

skimask
- 15th June 2008, 00:56
Exactly like you have the program written.
Put an extra pause in the middle of your loops and you'll see that it's doing exactly what you programmed it to do. You're eyes aren't good enough to see a 2ms delay in anything.

Bruce
- 15th June 2008, 02:13
Try adding ANSEL = 0 to disable A/D on pins used for digital.

PICante
- 15th June 2008, 11:50
You are correct my eyes are not capable of 2ms delay, it looks like the (ST) LED is constantly lit. However the (DI) LED should be on for the complete duration of the up counting loop which should be visible to the eye.

Adding “ANSEL % = 00000000” cured the problem!

I hooked up the stepper motor and noticed that I need the 2ms delay or more for it to run, 1ms just makes the motor hum without moving. The datasheet for the UCN5804B says minimum step input pulse width is 3.0us which indicates that the motor should be able to run much faster than about 1 rpm?
Is there any solution for this perhaps software mods or some filtering to make the pulses from the 16F88 look more like what the 5804 likes to see?

Thank Guys, for being here!

PICante
- 18th June 2008, 09:48
Any suggestions on how to speed up the stepper?

Thanks!

skimask
- 18th June 2008, 14:20
Any suggestions on how to speed up the stepper?
What's the clock speed on your PIC?
How many pauses do you have in your code that don't really need to be there?
What is the latest version of your 'code'?

PICante
- 18th June 2008, 15:17
What's the clock speed on your PIC?>

“OSCCON =%01110000 ' INTRC = 8MHz”



How many pauses do you have in your code that don't really need to be there?>


“I hooked up the stepper motor and noticed that I need the 2ms delay or more for it to run, 1ms just makes the motor hum without moving. The datasheet for the UCN5804B says minimum step input pulse width is 3.0us which indicates that the motor should be able to run much faster than about 1 rps? (edited) 
Is there any solution for this perhaps software mods or some filtering to make the pulses from the 16F88 look more like what the 5804 likes to see?”


What is the latest version of your 'code'?>

Like above + “ANSEL % = 00000000” as row #6.



Thanks skimask!

skimask
- 18th June 2008, 17:53
DEFINE OSC 8
define LCD_DREG PORTB
define LCD_DBIT 0
define LCD_RSREG PORTB
define LCD_RSBIT 5
define LCD_EREG PORTB
define LCD_EBIT 4
define LCD_BITS 4
define LCD_LINES 2
osccon=$70:trisb=0:trisa=0:cmcon=7:ansel=0:ansel=0 :A var word:di var porta.1
st var porta.4:di=1: pause 500:di=0: pause 500:st=1: pause 500:st=0: pause 1000
main: di=1:freqout st,500,625:di=0:freqout st,500,625:pause 1000:goto main

Run that and see what happens. I'll explain later... I think I know what the deal is, but I'm not sure.

PICante
- 18th June 2008, 19:07
Well, this freaks me out! :-)

Actually that was even worse, the motor shaft just shatters back and forth makes no full turns. I tried by lowering the frequency in steps all the way down to 10Hz (from 625Hz), below 100Hz it moves but there’s no torque! I can stop it just by touching the shaft.

With the output on/off loop (first try) 2ms (and higher) delay the motor runs fine and there’s lots of torque. I only wish it was possible to run it faster.

Consulting the PBP manual I read;

”FREQOUT works best with a 20 or 40 MHz oscillator. It can also work with a 10 MHz osc and even at 4 MHz, although it will start to get very hard to filter and be of fairly low amplitude. Any other frequency will cause FREQOUT to generate a frequency that is a ratio of the actual osc used and 20 MHz.”

The last part didn’t really translate very well in the old brain; “a ratio of the actual osc used and 20 MHz.”.

Does this mean lots of harmonics and “dirt”, I do not have access to a scope where I am right now or I would have performed a ECG on it!


Thanks skimask!

skimask
- 18th June 2008, 21:24
Actually that was even worse, the motor shaft just shatters back and forth makes no full turns
I expected all of the above...


Does this mean lots of harmonics and “dirt”, I do not have access to a scope where I am right now or I would have performed a ECG on it!
Basically, yes, FREQOUT is a bit ugly.

I think the problem in your code is here (and other places that look a lot like it):


DI = 1 : pause 500
for a = 0 to 200 : ST = 1 : pause 2 : ST = 0 : next a

Reading thru the code out loud:
- Step On
- Wait 2ms
- Step Off
- NO WAITing for 2ms
Repeat...

So basically what you end up with is a nice long 'go ahead and step' pulse, with practically no wait between pulses.

That might help you out. I don't know. I'm guessing here. Couldn't find the datasheet for that '5804 chip and didn't feel like doing any hard searching for it either :)

PICante
- 22nd June 2008, 11:15
I’m back, after some fiddling I realized that without any delay it doesn’t work. Instead I removed the PAUSE and replaced it with a loop. Now, this part of the code looks like this:

for a = 0 to 2000 ‘ ten turns
ST = 1 ‘ start pulse
for b=0 to 59:next b
ST = 0 ‘ end pulse
next a ‘ loop

This runs the motor slightly faster, however if b < than 59 the motor loses all torque and just hums. At about b = 65 or higher the torque is acceptable and I really do not understand why it can't run faster.

UCN5804B: http://www.taomc.com/bits2bots/5804.pdf

Thanks!

skimask
- 22nd June 2008, 11:27
This runs the motor slightly faster, however if b < than 59 the motor loses all torque and just hums. At about b = 65 or higher the torque is acceptable and I really do not understand why it can't run faster.
Because that's the nature of stepper motors.
Low speed / High torque
High speed / lower torque

And you still missed my point about the code above...
You've got a pause on one end of the step, but not the other end. The motor/electronics probably have to catch up with each other.


for a = 0 to 2000 ‘ ten turns
ST = 1 ‘ start pulse
for b=0 to 59:next b <-pause here ok
ST = 0 ‘ end pulse
might want a pause here, probably not the same length as above, but a pause nonetheless
next a ‘ loop

At 8Mhz, ST is low for maybe 4us, give or take.
And if you look at the datasheet, there's a turn-on and turn-off delay of 10us.

PICante
- 22nd June 2008, 12:45
Thanks skimask!

Yes I did miss your point; of curse the "squarewave" must look better to the 5804 if the duty is more like 50/50!
New code:

for a = 0 to 2000 ‘ ten turns
ST = 1 ‘ start pulse
for b=0 to 28:next b ‘ on time
ST = 0 ‘ end pulse
for b=0 to 28:next b ‘ off time
next a ‘ loop

The motor runs at the same speed as before, perhaps with a little less noise. If I try to go below 28 it loses torque and I do not help to use different on and off times. I have tried both ways, shorter on time and shorter off time.
S**t, I really thought this was the solution!

tenaja
- 22nd June 2008, 14:03
You *might* get a little more speed out of it if you ramp up to speed (i.e. set an acceleration rate) rather than instantly hitting the full speed.

But, as Skimask said, steppers are designed for low speed, and once you hit their top speed in the circuit, the motor will stall...which is a nice way to stay stop.