Output settings for 16F88


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73

    Smile Output settings for 16F88

    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!

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Try adding ANSEL = 0 to disable A/D on pins used for digital.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Smile

    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!

  5. #5
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Unhappy

    Any suggestions on how to speed up the stepper?

    Thanks!

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PICante View Post
    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'?

  7. #7
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Default

    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!

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    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.

  9. #9
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Default

    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!

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PICante View Post
    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):
    Code:
    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

  11. #11
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Default

    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!

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PICante View Post
    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.
    Code:
    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.
    Last edited by skimask; - 22nd June 2008 at 11:32.

  13. #13
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Red face

    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!

  14. #14
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. Bit Banging input to output on PIC16F876A
    By Bronurstomp in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th June 2008, 19:50
  2. PIC 16F684 Configuration Settings
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th April 2007, 15:18
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  4. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19
  5. HSEROUT Newbie question/problem
    By Mark Scotford in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 11th July 2006, 14:44

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts