PWM with PIC16F88 controlling h-bridge


Results 1 to 9 of 9

Threaded View

  1. #2
    Join Date
    May 2010
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    One man in other forum told me to try this one, but still nothing :/ maybe here someone will have a clue.
    Code:
    MSpause var byte          ' Milliseconds between charging caps, suggest 10 to 50, even numbers 
    Ctr     var byte	  ' Used in loop for 50% pwm
    RunCt   var byte	  ' Used in loop
    Left   var PORTB.0        ' Don't know which is which, so declare one as left.
    Right  var PORTB.1        ' By default, the other is right.
    SD     var PORTB.2        ' Shutdown; low=run, high=off.
    
    ANSEL = %00000000 ' All pins changed from analogue to digital
    OSCCON = $60 ' Internal clock setted to 4Mhz
    TRISB = %00000000 ' All PORTB pins are outputs. 
    
    High SD                 ' Shut down MOSFET drivers
    MSpause = 50		' initialize MSPause; 50mS, this will result in about 5 seconds forwards, 
                            '   5 seconds stopped, 5 seconds reverse, 2 seconds stopped.
    
    Loop:
           ' Start the motor turning left.  Full speed ahead!
      
            High Left	 ' Start running left...
            Low  Right       ' Set them opposite
    	For RunCt = 1 to 100 ' We're going to loop 100 times, so run time will be MSpause * RunCt
               Low SD           ' Turn on MOSFET drivers
               Pause (MSpause-1) ' wait a bit...
               High SD          ' Turn off MOSFET drivers
               Pause 1          ' Charge MOSFET caps
            Next RunCt
    
           ' Stop the motor by giving it 50% PWM on both sides.
    
    	For RunCt = 1 to 100 ' We're going to loop 100 times, so run time will be MSpause * RunCt
               For Ctr = 1 to (MSpause >> 1)-2  '  
                  Low Right
                  High Left        ' Swap direction
                  Low SD           ' Turn on MOSFET drivers
                  Pause 1
                  High SD          ' Turn off MOSFET drivers
                  High Right       ' Swap direction
                  Low Left
                  Low SD           ' Turn on MOSFET drivers
                  Pause 1
                  High SD          ' Turn off MOSFET drivers
               next Ctr
            Next RunCt
    
            ' Run the motor in reverse
    
            High Right
            Low Left
            For RunCt = 1 to 100 ' We're going to loop 100 times, so run time will be MSpause * RunCt
               For Ctr = 1 to (MSpause >> 1)-2  '  
                  Low SD           ' Turn on MOSFET drivers
                  Pause MSpause    ' delay for a bit
                  High SD          ' Turn off MOSFET drivers
                  Pause 1
               next Ctr
            next RunCt
    
    	' Driver is shut down, let's just pause for 2 seconds
            Pause 1000
            Pause 1000
    
            goto Loop      ' do forever
    END
    But as i read this code and i dont get it why it dont work ;/ it looks everything logically. I meassured pins wile working, and it works good i think, RB0 - 5V after some time it drops to 2.5V and when to zero and RB1 opposite. But RB2 got only 0.12V all time.
    Last edited by deimantas; - 19th May 2010 at 21:06.

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