PIC16F88 problem controlling hbridge

SgtWookie

Joined Jul 17, 2007
22,230
Why don't you just try waiting 1mS to charge the cap?

Don't forget that you will need to wait between changing states of any of the MOSFETs.

Btw, what are the values of your gate resistors? I don't think you mentioned that before.

They should be around 2.2 to 4.7 Ohms.
 

Thread Starter

aGpLT

Joined Jan 21, 2010
128
Why don't you just try waiting 1mS to charge the cap?

Don't forget that you will need to wait between changing states of any of the MOSFETs.

Btw, what are the values of your gate resistors? I don't think you mentioned that before.

They should be around 2.2 to 4.7 Ohms.
When i change any of mosfet state i need to w8 for cap to charge y ?

ammm i am using 330 Ohm :>
 

R!f@@

Joined Apr 2, 2009
9,918
Ummmm!! This may not be a right time to mention..but I think I have a thought.
U see I tried what the OP is trying to do and I stopped after learning that an H Bridge as Sgt said should have two opposite MOSFET's PWM simultaneously in opposite polarity.
If that is the case then should the circuit need a PIC with two CCCP modules, while 16F88 has only one. Or am I wrong.
I think this is why OP is blowing MOSFET's
 

SgtWookie

Joined Jul 17, 2007
22,230
When i change any of mosfet state i need to w8 for cap to charge y ?

ammm i am using 330 Ohm :>
330 Ohms is way, way too much.

Drop it down to somewhere between 2.2 and 4.7 Ohms. The resistors should be as close to the MOSFET gates as possible, with very short leads.

The idea here is that the trace/wiring between the IR2110 and the MOSFET gate is effectively an inductor; at a rate of about 15nH per 10mm (0.40"), or 450nH per foot. The gate is effectively a capacitor. When the IR2110 "snaps" the gate high or low, it's like plucking a guitar string; the C of the gate and the L of the wire/trace is effectively a LC resonant circuit. Your gate will "ring" for a good while if there is no resistance at all. The idea of the low-value resistor is to not impede the flow too much, but to "snub" the ringing quickly.

Using a 330 Ohm resistor in the gate charge/discharge circuit is like trying to fill a bathtub through a straw; you can do it, but it'll take a long, long time.
 

SgtWookie

Joined Jul 17, 2007
22,230
Ummmm!! This may not be a right time to mention..but I think I have a thought.
U see I tried what the OP is trying to do and I stopped after learning that an H Bridge as Sgt said should have two opposite MOSFET's PWM simultaneously in opposite polarity.
If that is the case then should the circuit need a PIC with two CCCP modules, while 16F88 has only one. Or am I wrong.
I think this is why OP is blowing MOSFET's
You're right, you're coming in late. ;)

The PWM idea had to be abandoned entirely, as our OP really has to turn off the high side MOSFET, wait a bit for it to turn off, and then turn on the low-side MOSFET to re-charge the boost cap.

He can leave the other side alone as long as the high side is off and the low side is on; that side's boost cap will remain charged.
 

Thread Starter

aGpLT

Joined Jan 21, 2010
128
Ummmm!! This may not be a right time to mention..but I think I have a thought.
U see I tried what the OP is trying to do and I stopped after learning that an H Bridge as Sgt said should have two opposite MOSFET's PWM simultaneously in opposite polarity.
If that is the case then should the circuit need a PIC with two CCCP modules, while 16F88 has only one. Or am I wrong.
I think this is why OP is blowing MOSFET's
CCP module if i think correctly is HPWM. And what means OP ? :)

Heh as i see, i messed quite with resistors value.
 
Last edited:

R!f@@

Joined Apr 2, 2009
9,918
I was also fiddling with an H-bridge circuit together with a MC33035. For my Winder. I think I blew the 33035 :D.
So I though I'd check in AAC...for a time out :p.
So will the F88 suffice?
 

SgtWookie

Joined Jul 17, 2007
22,230
Yes, the 88 should be fine.

He could save a lot of coding by making up standard routines or functions for recharging the cap on the side that has HIN up.

OP = Original Poster, the person who started the thread originally.
 

R!f@@

Joined Apr 2, 2009
9,918
So I am wrong to give up and I thought 2 CCCP modules are needed. I think we need an explanation on the coding on how to switch the H Bridge with proper timing duration.
I said we cause seeing that it could be done with that PIC I think I will follow with you two too.
Sgt. Could u please elaborate on the coding sequence. I can start to code too then we will see how we end up together
 

SgtWookie

Joined Jul 17, 2007
22,230
Well, this is aGpLT's thread; so it has to stay with his original topic.

Now that I'm thinking about it some more ... I've decided that since the load is inductive, he CAN get away with using PWM on the high side. I was using a resistive load in my simulation tied to 6v; were it inductive I would have seen that disconnecting the high-side MOSFET results in the inductor current flow trying to pull the now-disconnected end of the inductor negative; but it's stopped by the flywheel diodes. This can serve as a ground to charge the boost caps - as long as there is current flowing through the inductor in the correct direction.

The basic sequence of events is:

1) Disable the bridge by raising SD.

2) Turn OFF both high-side MOSFETs.

3) Turn ON both low-side MOSFETs.

4) Wait a moment to ensure that the propagation delay through the H-bridge controller has been satisfied.

5) Enable both bridge drivers by lowering SD.

6) Wait a moment to ensure that the low-side MOSFETs are on.

7) Wait at least 1mS to charge the boost caps. Your mileage will vary, depending on the ESR of the caps you chose, the boost cap charging diodes, the caps you have across Vcc and GND, etc. I suggest that the caps across Vcc/GND be 10x as large as the boost caps. Otherwise, you may wind up with a low charge on the boost caps; as the power supply may be a ways away.

8) Turn OFF the low-side MOSFET that you want to do the PWM on.

9) wait a moment for it to turn off.

10) Apply PWM to the high side MOSFET on the same side that you turned off the low side in step 8. Keep the PWM below about 95% so that the caps have a chance to get recharged, and keep the PRT (1/PWM_frequency) under 50mS or so.

11) Instead of slamming the motor to a stop, or slamming it to full-throttle, use a series of for-next loops to slowly increase the PWM rate, then hold it at a fixed rate for a period, and finally decrease the PWM rate slowly.

12) If you wish to stop the motor more quickly, you can turn OFF the high-side MOSFET, wait a moment, and then turn ON the low side MOSFET (same side). This will effectively short the motor terminals together.
 

R!f@@

Joined Apr 2, 2009
9,918
that did shed some light on how to code, but I am not using IR2110..So I don't think even if I code my ckt will work. But this gives me an idea on how to go abt it using the H bridge IC's that I have. I'll continue on my own winder thread after trying.
Thanks Sgt.
 

Thread Starter

aGpLT

Joined Jan 21, 2010
128
Sorry i didn't understand quite well, it's because of my pure English skills :|
Rich (BB 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
LHIN  var PORTB.0 ' left HIN
LLIN  VAR PORTB.1 ' left LIN 
RHIN VAR PORTB.2 ' right HIN 
RLIN VAR PORTB.3 ' right LIN
SD var PORTB.4 ' 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 SD ' 1) SD drivers at start
    LOW LHIN ' 2-3) Turn off HIGH side and turn on LOW side mosfets
    LOW RHIN
    HIGH LLIN
    HIGH RLIN
    Pause 1 ' 4) w8 some time for everything to settle
    LOW SD ' 5) Turn on SD drivers
    Pause 1  ' 6-7) w8 some time
    LOW LLIN '8) turn off one low side mosfet
    Pause 1 '8-9) w8 a bit to settle
loop: 
    PWM LHIN,230,255 '10) send pwm signal to same side as turned low side mosfet (90%~ PWM signal PRT - 39ms)
    GOTO loop '10) do it forever
 

SgtWookie

Joined Jul 17, 2007
22,230
Try this one:

Rich (BB 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
LHIN     var PORTB.0 ' left HIN
LLIN     VAR PORTB.1 ' left LIN 
RHIN     VAR PORTB.2 ' right HIN 
RLIN     VAR PORTB.3 ' right LIN
SD       var PORTB.4 ' Shut down; when high, driver is disabled, when low driver is enabled

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 ' 1) SD drivers at start
    LOW LHIN ' 2-3) Turn off HIGH side and turn on LOW side mosfets
    LOW RHIN
    HIGH LLIN
    HIGH RLIN
    Pause 1 ' 4) wait some time for everything to settle
    LOW SD ' 5) Turn on SD drivers
    Pause 5  ' 6-7) w8 some time
    LOW LLIN '8) turn off one low side mosfet
    Pause 1 '8-9) wait a bit to settle
loop: 
    ' RLIN is high, all others are off.

    ' Slowly increase spead of motor by PWMing LHIN
    FOR Ctr = 5 to 250 step 5 (5 is roughly 2% duty cycle, 250 is roughly 98% duty cycle)
       PWM LHIN,Ctr,200 '10)
    NEXT Ctr

    ' Ctr should be 250 here; we'll continue to use that for our PWM % for the next loop

    FOR RunCt = 1 to 100 ' Let's maintain top speed for awhile
       PWM LHIN,Ctr,200 '10)
    NEXT RunCt

    ' Now let's slow the motor down
    FOR Ctr = 250 to 5 step -5 (5 is roughly 2% duty cycle, 250 is roughly 98% duty cycle)
       PWM LHIN,Ctr,200 '10)
    NEXT Ctr
    LOW LHIN ' It should be off, but let's make certain.
    PAUSEUS 100 ' Ensure the MOSFET has turned off.

    ' Now, let's make sure the motor is stopped
    HIGH LLIN  ' Both low side MOSFETs being on will act as a brake
    PAUSE 1000 ' Brake for one full second

    LOW RLIN   ' Start setting up for running the other way.
    PAUSEUS 100 ' Ensure the MOSFET has turned off.

    ' Slowly increase spead of motor by PWMing RHIN
    FOR Ctr = 5 to 250 step 5 (5 is roughly 2% duty cycle, 250 is roughly 98% duty cycle)
       PWM RHIN,Ctr,200 '10)
    NEXT Ctr

    ' Ctr should be 250 here; we'll continue to use that for our PWM % for the next loop

    FOR RunCt = 1 to 100 ' Let's maintain top speed for awhile
       PWM RHIN,Ctr,200 '10)
    NEXT RunCt

    ' Now let's slow the motor down
    FOR Ctr = 250 to 5 step -5 (5 is roughly 2% duty cycle, 250 is roughly 98% duty cycle)
       PWM RHIN,Ctr,200 '10)
    NEXT Ctr
    LOW RHIN ' It should be off, but let's make certain.
    PAUSEUS 100 ' Ensure the MOSFET has turned off.

    ' Now, let's make sure the motor is stopped
    HIGH LLIN  ' Both low side MOSFETs being on will act as a brake
    PAUSE 1000 ' Brake for one full second
    LOW LLIN '8) turn off one low side mosfet
    Pause 1 '8-9) wait a bit to settle
    GOTO loop '10) do it forever
 
Last edited:

Thread Starter

aGpLT

Joined Jan 21, 2010
128
Try this one:

Rich (BB 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
LHIN     var PORTB.0 ' left HIN
LLIN     VAR PORTB.1 ' left LIN 
RHIN     VAR PORTB.2 ' right HIN 
RLIN     VAR PORTB.3 ' right LIN
SD       var PORTB.4 ' Shut down; when high, driver is disabled, when low driver is enabled

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 ' 1) SD drivers at start
    LOW LHIN ' 2-3) Turn off HIGH side and turn on LOW side mosfets
    LOW RHIN
    HIGH LLIN
    HIGH RLIN
    Pause 1 ' 4) wait some time for everything to settle
    LOW SD ' 5) Turn on SD drivers
    Pause 5  ' 6-7) w8 some time
    LOW LLIN '8) turn off one low side mosfet
    Pause 1 '8-9) wait a bit to settle
loop: 
    ' RLIN is high, all others are off.

    ' Slowly increase spead of motor by PWMing LHIN
    FOR Ctr = 5 to 250 step 5 (5 is roughly 2% duty cycle, 250 is roughly 98% duty cycle)
       PWM LHIN,Ctr,200 '10)
    NEXT Ctr

    ' Ctr should be 250 here; we'll continue to use that for our PWM % for the next loop

    FOR RunCt = 1 to 100 ' Let's maintain top speed for awhile
       PWM LHIN,Ctr,200 '10)
    NEXT RunCt

    ' Now let's slow the motor down
    FOR Ctr = 250 to 5 step -5 (5 is roughly 2% duty cycle, 250 is roughly 98% duty cycle)
       PWM LHIN,Ctr,200 '10)
    NEXT Ctr
    LOW LHIN ' It should be off, but let's make certain.
    PAUSEUS 100 ' Ensure the MOSFET has turned off.

    ' Now, let's make sure the motor is stopped
    HIGH LLIN  ' Both low side MOSFETs being on will act as a brake
    PAUSE 1000 ' Brake for one full second

    LOW RLIN   ' Start setting up for running the other way.
    PAUSEUS 100 ' Ensure the MOSFET has turned off.

    ' Slowly increase spead of motor by PWMing RHIN
    FOR Ctr = 5 to 250 step 5 (5 is roughly 2% duty cycle, 250 is roughly 98% duty cycle)
       PWM RHIN,Ctr,200 '10)
    NEXT Ctr

    ' Ctr should be 250 here; we'll continue to use that for our PWM % for the next loop

    FOR RunCt = 1 to 100 ' Let's maintain top speed for awhile
       PWM RHIN,Ctr,200 '10)
    NEXT RunCt

    ' Now let's slow the motor down
    FOR Ctr = 250 to 5 step -5 (5 is roughly 2% duty cycle, 250 is roughly 98% duty cycle)
       PWM RHIN,Ctr,200 '10)
    NEXT Ctr
    LOW RHIN ' It should be off, but let's make certain.
    PAUSEUS 100 ' Ensure the MOSFET has turned off.

    ' Now, let's make sure the motor is stopped
    HIGH LLIN  ' Both low side MOSFETs being on will act as a brake
    PAUSE 1000 ' Brake for one full second
    LOW LLIN '8) turn off one low side mosfet
    Pause 1 '8-9) wait a bit to settle
    GOTO loop '10) do it forever
I tested this one, still nothing, measured caps, don't charge to >10V only till 5V. So its bad timing y ? :)
 

SgtWookie

Joined Jul 17, 2007
22,230
Double-check to make sure that you have the ports wired to R/L HIN and R/L LIN as you say they are.

Double-check to make certain that the ports are going high and low when they are supposed to.
 

Thread Starter

aGpLT

Joined Jan 21, 2010
128
Double-check to make sure that you have the ports wired to R/L HIN and R/L LIN as you say they are.

Double-check to make certain that the ports are going high and low when they are supposed to.
Checked before several times if it's right and cheked now, LHIN smoothly growing from 0.12V to 5V RLIN 5V , RHIN 0V, LLIN 0V, i measured on IR2110 drivers so this checks both ports and wires.

But at very beginning SD should be high, but uC don't give that command via RB4 or maybe i can't catch it. Yeh as i said i couldn't catch that, so i paused it for 1sec to check, and it's working.

But uC do only half program, Voltage don't drop after it reaches 5V and don't turn off and change sides.
 
Last edited:

Thread Starter

aGpLT

Joined Jan 21, 2010
128
ANSEL = %00000000 ' All pins changed from analogue to digital
OSCCON = $60 ' Internal clock setted to 4Mhz
ADCON0 = 0 ' AD Modue OFF
CMCON = 7 ' Comparators OFF
TRISB = %00000000 ' All PORTB pins are outputs.
PORTB = %00000000 ' to be sure that at start all pins are low

I added this part into program, maybe it something with my fuse bits ? but it don't seem because its normally gets to the motor brake part. But still my motor don't move :( when i program i configure that WDT is off, intrc_clkout enabled, everything else as default:

WDT_OFF
MCLRE_ON
CODE_PROTECT_ROM_OFF
OSCILATOR: INTRC_IO_ON or INTERC_CLOCKOUT_ON
DEBUG_OFF
LVP_OFF
SWITCH_OVER_MODE_ON
PWRTE_OFF
BODEN_ON
CODE_PROTECT_EEP_OFF
CPPMX_CCP1_RB0
FLASH_WRITE_PROTECT_OFF
FAIL_SAFE_ON
 

SgtWookie

Joined Jul 17, 2007
22,230
After experimenting with the IR2110 a bit in simulation, found some interesting things.

It is not shown in the datasheet, but in the simulation when power is first applied, very heavy initial currents flow from the logic inputs through to ground - I'm talking hundreds of Amperes. I don't know why this is.

Anyway, if SD is raised, it "forgets" what state it's inputs were previously.

So, for starters, you raise SD to make sure it's turned off.

Then you go around and turn off all of the PIC outputs.

Then you lower SD, and wait a few microseconds to make sure it "took".

Then you can turn on the parts of the bridge that you want.

Here's a revision on the program; give it a whirl:

Rich (BB 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
LHIN     var PORTB.0 ' left HIN
LLIN     VAR PORTB.1 ' left LIN 
RHIN     VAR PORTB.2 ' right HIN 
RLIN     VAR PORTB.3 ' right LIN
SD       var PORTB.4 ' Shut down; when high, driver is disabled, when low driver is enabled

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 ' 1) SD drivers at start
    Pause 1 ' 4) wait some time for everything to settle
    LOW LHIN ' 2-3) Ensure PIC outputs are low.
    LOW RHIN
    LOW LLIN
    LOW RLIN
    LOW SD  ' 5) Turn on SD drivers
            ' Believe it or not, SD sets a flip-flop inside the IR2110.
            ' If you had an input high, you have to set it low and raise it again for the IR2110 to recognise it.
    PAUSEUS 10 ' Wait for propagation delay issues
    LOW LHIN 
    LOW RHIN
    HIGH LLIN
    HIGH RLIN
    Pause 100  ' 6-7) w8 some time
    LOW LLIN '8) turn off one low side mosfet
    Pause 1 '8-9) wait a bit to settle
loop: 
    ' RLIN is high, all others are off.

    ' Slowly increase spead of motor by PWMing LHIN
    FOR Ctr = 12 to 242 ' (12 is roughly 5% duty cycle, 250 is roughly 95% duty cycle)
       PWM LHIN,Ctr,100
    NEXT Ctr

    ' Ctr should be 242 here; we'll continue to use that for our PWM % for the next loop

    FOR RunCt = 1 to 100 ' Let's maintain top speed for awhile
       PWM LHIN,Ctr,200 '10)
    NEXT RunCt

    ' Now let's slow the motor down
    FOR Ctr = 242 to 12 step -1 '
       PWM LHIN,Ctr,100 '10)
    NEXT Ctr
    LOW LHIN ' It should be off, but let's make certain.
    PAUSEUS 100 ' Ensure the MOSFET has turned off.

    ' Now, let's make sure the motor is stopped
    HIGH LLIN  ' Both low side MOSFETs being on will act as a brake
    PAUSE 1000 ' Brake for one full second

    LOW RLIN   ' Start setting up for running the other way.
    PAUSEUS 100 ' Ensure the MOSFET has turned off.

    ' Slowly increase spead of motor by PWMing RHIN
    FOR Ctr = 12 to 242 
       PWM RHIN,Ctr,100 '10)
    NEXT Ctr

    ' Ctr should be 250 here; we'll continue to use that for our PWM % for the next loop

    FOR RunCt = 1 to 100 ' Let's maintain top speed for awhile
       PWM RHIN,Ctr,200 '10)
    NEXT RunCt

    ' Now let's slow the motor down
    FOR Ctr = 242 to 12 step -1
       PWM RHIN,Ctr,100 '10)
    NEXT Ctr
    LOW RHIN ' It should be off, but let's make certain.
    PAUSEUS 100 ' Ensure the MOSFET has turned off.

    ' Now, let's make sure the motor is stopped
    HIGH LLIN  ' Both low side MOSFETs being on will act as a brake
    PAUSE 1000 ' Brake for one full second
    LOW LLIN '8) turn off one low side mosfet
    Pause 1 '8-9) wait a bit to settle

    GOTO loop '10) do it forever
 
Top