PWM with PIC16F88 controlling h-bridge


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2010
    Posts
    11

    Default PWM with PIC16F88 controlling h-bridge

    Hello everyone. I am new one here so don't be hard on me

    Ok, let's start with main problem, i have h-bridge and its controlled by pwm. Here is circuit:


    My program is here:
    ' RB0 and RB1 are for PWM
    ' RB2 is for SD

    ANSEL = %00000000 ' All pins changed from analogue to digital
    OSCCON = $60 ' Internal clock setted to 4Mhz
    TRISB = %00000000 ' All PORTB pins are outputs.
    HIGH PORTB.2 ' Turn on sd pin to shutdown ir2110

    start:
    Pause 100 ' Delay for 100ms waiting for mosfets to settle
    low PORTB.2 ' Turned off sd pin
    Pause 100 ' delay 100ms
    PWM PORTB.0,242,255 ' Pulse sent to PORTB.0 at a duty 'value of 242(95% duty cycle) for 255 cycles.
    PWM PORTB.1,012,255 ' Pulse sent to PORTB.0 at a duty 'value of 12(5% duty cycle) for 255 cycles.
    PAUSE 100
    PWM PORTB.0,127,255 ' 50%
    PWM PORTB.1,127,255 ' 50%
    PAUSE 100
    PWM PORTB.0,012,255 ' 5%
    PWM PORTB.1,242,255 ' 95%
    PAUSE 100
    PWM PORTB.0,127,255 '50%
    PWM PORTB.1,127,255 '50%
    PAUSE 100
    GOTO start
    END
    I am quite new with picbasic either, so if enyone could help me i would be very grateful.

  2. #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.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi,
    That schematic looks a bit strange to me.....

    First, there doesn't seem to be any low side supply voltage (Vcc) as pin 3 seems to not be connected to anything except the bootstrap capacitor and diode. Only the logic supply (Vdd) seems to actually be connected to any supply rail.

    Second, even if pin 3(Vcc) and 9(Vdd) ARE connected they are both connected to +5V while the datasheet for the IR2110 calls for a Vcc of 10-20V. The undervoltage protection for the low the side supply (Vcc) kicks in at around 8V which means the bridge drivers aren't even operating.

    /Henrik.

  4. #4
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Welcome!

    HIGH PORTB.2 ' Turn on sd pin to shutdown ir2110
    But RB2 got only 0.12V all time.
    This pin is made HIGH before the main loop then made LOW within the loop but never serviced again if you are wanting to Shut Down again sometime. That's why it's always LOW.
    Louie

  5. #5
    Join Date
    May 2010
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    That schematic looks a bit strange to me.....

    First, there doesn't seem to be any low side supply voltage (Vcc) as pin 3 seems to not be connected to anything except the bootstrap capacitor and diode. Only the logic supply (Vdd) seems to actually be connected to any supply rail.

    Second, even if pin 3(Vcc) and 9(Vdd) ARE connected they are both connected to +5V while the datasheet for the IR2110 calls for a Vcc of 10-20V. The undervoltage protection for the low the side supply (Vcc) kicks in at around 8V which means the bridge drivers aren't even operating.

    /Henrik.
    So if i understand correctly i need pin3 connect to 12V supply, y ? Sorry my mistake, its everything okay, just i didn't draw that... pin 3 is connected to 12V supply.

    This pin is made HIGH before the main loop then made LOW within the loop but never serviced again if you are wanting to Shut Down again sometime. That's why it's always LOW.
    The main point of getting SD low is to make sure that MOSFETS are off at the start. In the loop he used Low sd / high SD for modulating signal and i think i should see that different in tester, or its making turn off/on SD to fast to get that information ? (Sorry for pure language).
    Last edited by deimantas; - 19th May 2010 at 23:44.

  6. #6
    Join Date
    May 2010
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Anyone ? sorry for my impatience, but i have reason for it i need to get this thing work as soon as possible, because it's for my graduation and it slows me from doing other parts.
    Last edited by deimantas; - 20th May 2010 at 11:30.

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Have you disconnected the hardware from the PIC and verified with a scope or whatever that what you think is a software bug really is a software bug and not a problem with your hardware.

    If PortB.2 doesn't go high then try something simple, connect a LED to it and do something like:
    Code:
    TRISB.2 = 0    'PortB.2 as output
    
    Main:
     PortB.2 = 1
     Pause 100
     PortB.2 = 0
     Pause 100
    Goto Main
    Now, does it toggle? If not, double check the ADC and comparator settings in case you have some other functions multiplexed on PortB.2 (I haven't checked). If it still doesn't work, try another pin, perhaps you've fried PortB.2....

    Then, when you have that going, move on to the PWM part and get that going - THEN when you know that the software is doing what you think you want (which usually isn't what you really need....), go on and connect the bridge.

    /Henrik.

  8. #8
    Join Date
    May 2010
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    Have you disconnected the hardware from the PIC and verified with a scope or whatever that what you think is a software bug really is a software bug and not a problem with your hardware.

    If PortB.2 doesn't go high then try something simple, connect a LED to it and do something like:
    Code:
    TRISB.2 = 0    'PortB.2 as output
    
    Main:
     PortB.2 = 1
     Pause 100
     PortB.2 = 0
     Pause 100
    Goto Main
    Now, does it toggle? If not, double check the ADC and comparator settings in case you have some other functions multiplexed on PortB.2 (I haven't checked). If it still doesn't work, try another pin, perhaps you've fried PortB.2....

    Then, when you have that going, move on to the PWM part and get that going - THEN when you know that the software is doing what you think you want (which usually isn't what you really need....), go on and connect the bridge.

    /Henrik.
    Yeah thank you for advice. Led's are blinking as i want. But i don't get it why my h-bridge show nosenses, everything is okay but one thing, all 4 drains are high, don't get it why.

  9. #9
    Join Date
    May 2009
    Location
    USA
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    I always thought the output of 7805 needed a capacitor as well? Anyway I would repace the IR2110 with something easier to use like UCC27322.

    You are using just a regular motor right? Not a stepper motor? An oscilloscope will be a great tool to have here to see the pulses at each output.

    To be honest, it's easier for me to look at a schematic, try to understand what is going on and then rebuild it as to how I understood it. Takes a little longer but I learn a lot more by thinking about it rather than just putting stuff together and hoping it works.
    Why is the email address verification case sensitive?

Members who have read this thread : 1

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