HPWM problem .. pls help!


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Samuel's Avatar
    Samuel Guest

    Default HPWM problem .. pls help!

    I'm using PIC16F877A to control two motors using an H-Bridge (L293D). Its a robot project for my engineering thesis design project. The ocsillator im using is 20Mhz. The following is my picbasic pro code. If i define my osc as 20Mhz, my motors run at FULL power and DO NOT change direction as per the code below. They just keep going forward. But if i have it as below, they run at a very good speed, and go thro each subroutine perfectly (ie: forward>stop>reverse>stop>main). One problem with this is when the motors are turning forward and revers, i get this high pitch sound. How can i fix this? Also if i wanna change the speed do i change dutcycle (150) or frequency (400)? And what about my DEFINE OSC value?? 4 or 20? Because my serial code (SERIN with T9600) seems to work well with DEFINE OSC 4. Should i sjust change my actualy osc to 4Mhz?!

    Any help will be gratly appreciated!!
    Thanks so much!
    Samuel.


    DEFINE OSC 4
    TRISC = %00000000

    HPWM 1, 150, 400
    HPWM 2, 150, 400

    TRISB = %00000000

    main:

    gosub fwd
    pause 5000
    gosub halt
    pause 5000
    gosub rever
    pause 5000
    gosub halt
    pause 5000

    goto main
    end

  2. #2
    anj's Avatar
    anj Guest


    Did you find this post helpful? Yes | No

    Default

    Problem one. At 20MHz, as per the manual, min HPWM freq you can get is 1221Hz
    You are trying to run at 400, so its probably screwing up the internal math.

    To change motor speed you change duty cycle.

    As to noise, The motor windings are vibrating at roughly the PWM freq and this is what you hear. To get rid of the whine, you need to use a freq that is out of hearing range ( so above 16KHz or below 50Hz ).

    As to oscillator, try using yr 20MHz first ( with Define OSC 20 )
    then use
    HPWM 1, 150, 16000
    HPWM 2, 150, 16000
    see how that runs.
    Andrew

  3. #3
    Samuel's Avatar
    Samuel Guest


    Did you find this post helpful? Yes | No

    Default HPWM frequency

    Thanks a lot anj!! I did that, i.e OSC 20 and HPWM 1 150 16000, but the motors were turning alternatively.. i.e one wud turn, and then the other and this keeps going in a loop as per my code. But they didnt turn together as they should be. (see code above) I then bumped the frequency down to 5000 and both motors worked well and at a good speed and went thro the subroutines well. i.e forward>halt>rev>halt>main. But now my robot is not going straight!!! it seems like both wheels are not going at the same speed or not starting at the same instant. Is this because HPWM 1 starts and is "followed" by HPWM 2 so there is a delay? but it doesnt seem to be just the start time .. i feel the actual speeds differ ... in the forward direction, one motor goes slower, and in the revers direction the other goes slower .. get it? playing with the frequency seems to affect this .. how do find the right frequency? Trial and error?

    Thanks a lot for your help!

  4. #4
    Samuel's Avatar
    Samuel Guest


    Did you find this post helpful? Yes | No

    Default

    someone help! HPWM duty cycle of 110 and frequency 1400 is giving me good results but my hbridge (L293D, motor driver) is getting HOT! and i'm hearing the high pitch sound!

    If i increase the frequency to above 16000, the sound is gone but then both motors dunt turn together, they turn alternatively!

  5. #5
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    The frequency limit for the L293D is 5kHz !!

    see Datasheet !
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  6. #6
    Samuel's Avatar
    Samuel Guest


    Did you find this post helpful? Yes | No

    Default

    ohh thanks! i just checked the L293D data sheet and it doesnt talk about the limit of 5KHz .. But i guess it makes sense.

    A duty cycle of anything below 100 doesnt push my motors. So the range for my duty cycle would be between 100 and 255? And the PIC with a 20Mhz OSC cannot go below 1221Hz, and my L293D doesnt go above 5KHz. So my frequency range would be between 1221Hz and 5000Hz? Much better .. now that i've narrowed down to something ...

    I like ure signature "There are only 10 types of people: Those who understand binary, and those who don't ..."!!

Similar Threads

  1. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  2. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  3. MCSP Loader Problem pls help
    By Nestyplus in forum General
    Replies: 5
    Last Post: - 17th February 2006, 04:07
  4. problem ont hpwm on the pic16f767!!
    By oscar in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th May 2005, 10:41
  5. HPWM Problem
    By Mark Scotford in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th September 2004, 10:40

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