CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

H bridge Problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Favalito



Joined: 08 Nov 2010
Posts: 6

View user's profile Send private message

H bridge Problem
PostPosted: Mon Nov 08, 2010 4:32 pm     Reply with quote

Hi, I made a H bridge, but apparently I have a problem with the code control h bridge has 2 inputs and management control with a 16F628, but in switching mosfets engines burn, here the diagram and the code.
Thanks.





Code:

#include <16F628A.h>
#fuses XT,NOMCLR
#use delay(clock = 4000000)

int1 b1=0;
int1 b2=0;
int1 b3=0;

void main()
{
set_tris_b(0b00110000);
output_low(PIN_b1);
output_low(PIN_b2);
output_low(PIN_B3);                 
setup_ccp1(CCP_PWM);                 
setup_timer_2(T2_DIV_BY_1,50, 1);         
   
while(true){
               

pri:
  if (input(PIN_B4)==0 && input(PIN_B5)!=0) {
                                               if (b1==0){ set_pwm1_duty(0);
                                                         output_low(PIN_B1);
                                                         output_low(PIN_B3);
                                                         b1=1;
                                                         b2=0;
                                                         b3=0;                                                       
                                                         delay_ms(300);}
                                                         
                                               set_pwm1_duty(0);             
                                               output_high(PIN_B1); 
                                                 if (input(PIN_B4)==0 && input(PIN_B5)!=0)goto pri;
                                                     else { set_pwm1_duty(0);
                                                            output_low(PIN_B1);
                                                            output_low(PIN_B3);
                                                            delay_ms(500);
                                                            set_pwm1_duty(0);
                                                            output_low(PIN_B1); 
                                                            output_low(PIN_B3);
                                                            delay_ms(200);}
                                                    }
                                             
                                           
  if (input(PIN_B4)!=0 && input(PIN_B5)==0) {
                                              if (b2==0){ set_pwm1_duty(0);
                                                         output_low(PIN_B1);
                                                         output_low(PIN_B3);
                                                         b1=0;
                                                         b2=1;
                                                         b3=0;                                                       
                                                         delay_ms(300);}
                                                         
                                               set_pwm1_duty(50);           
                                               output_low(PIN_B1);
                                                 if (input(PIN_B4)!=0 && input(PIN_B5)==0) Goto pri;
                                                    else { set_pwm1_duty(0);
                                                           output_low(PIN_B1);
                                                           output_low(PIN_B3);
                                                           delay_ms(500);
                                                           set_pwm1_duty(0);
                                                           output_low(PIN_B1); 
                                                           output_low(PIN_B3);
                                                           delay_ms(200);}
                                            }
 
  if (input(PIN_B4)!=0 && input(PIN_B5)!=0) {
                                               if (b3==0){ set_pwm1_duty(0);
                                                         output_low(PIN_B1);
                                                         output_low(PIN_B3);
                                                         b1=0;
                                                         b2=0;
                                                         b3=1;                                                       
                                                         delay_ms(300);}
                                                         
                                               set_pwm1_duty(40);             
                                               output_low(PIN_B1);
                                                 if (input(PIN_B4)!=0 && input(PIN_B5)!=0)goto pri;
                                                   else  { set_pwm1_duty(0);
                                                           output_low(PIN_B1);
                                                           output_low(PIN_B3);
                                                           delay_ms(500);
                                                           set_pwm1_duty(0);
                                                           output_low(PIN_B1); 
                                                           output_low(PIN_B3);
                                                           delay_ms(200);}
                                            }
     
     
     set_pwm1_duty(0);
     output_low(PIN_B1);
     output_low(PIN_B3);
     delay_ms(200);
     


}
}
temtronic



Joined: 01 Jul 2010
Posts: 9172
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 5:21 pm     Reply with quote

If it was me..I'd checkout the hardware first without the PIC.
Simply put a couple LEDs(one red, one green) back to back ,with current limiting resistors as the 'motor'.Add a couple of pulldown resistors to the transistor drivers to ensure they are OFF unless YOU pull them high!.
Now turn one on(pulled high with 10Kr) and see which LED lights. Repeat for the other driver transistor(other LED should light.
If this simple test fails, you have a hardware problem and MUST be fixed berfore connecting the PIC.
When it works THEN program the PIC with similar logic without the PWM code. A simple press button A turns on red LED, press button b turns on green LED type code...
After all that you should be able to carry on......

hope this helps
Favalito



Joined: 08 Nov 2010
Posts: 6

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 5:57 pm     Reply with quote

Quote:

If it was me..I'd checkout the hardware first without the PIC.
Simply put a couple LEDs(one red, one green) back to back ,with current limiting resistors as the 'motor'.Add a couple of pulldown resistors to the transistor drivers to ensure they are OFF unless YOU pull them high!.
Now turn one on(pulled high with 10Kr) and see which LED lights. Repeat for the other driver transistor(other LED should light.
If this simple test fails, you have a hardware problem and MUST be fixed berfore connecting the PIC.
When it works THEN program the PIC with similar logic without the PWM code. A simple press button A turns on red LED, press button b turns on green LED type code...
After all that you should be able to carry on......


hi, thanks for replying, I did the test without the pic testing and everything works fine, actions 5v each entrance to the bridge and it works fine, so I say that the problem is the program, but not where the problem is.
Greetings
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 6:01 pm     Reply with quote

Good thoughts, Temtronic.

You also might disconnect your motor ckt and just look at the two drive lines coming out of the PIC with a scope. It sounds like they may be overlapping. Sometimes a trusty scope is faster than trying to find a bug in code.

Also may want a solid pulldown on the transistor inputs since the PIC lines float until TRIS'd.
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 6:20 pm     Reply with quote

Okay humor me, I'm a little slow sometimes.
Question 1: Are you driving your circuit with PIN_B1 and PIN_B3?
Question 2: Are you using PIN_B3 as a PWM output (switching hi/lo)?
Question 3: If 1 and 2 are true, won't running the PWM with PIN_B1 high turn on all 4 bridge transistors?
Favalito



Joined: 08 Nov 2010
Posts: 6

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 6:38 pm     Reply with quote

Quote:

Okay humor me, I'm a little slow sometimes.
Question 1: Are you driving your circuit with PIN_B1 and PIN_B3?
Question 2: Are you using PIN_B3 as a PWM output (switching hi/lo)?
Question 3: If 1 and 2 are true, won't running the PWM with PIN_B1 high turn on all 4 bridge transistors?


hi pmuldoon tks for reply, for questions 1, 2 and 3: yes, yes, no.
Pic probe outputs with LEDs and all apparently working as it should, but when connected, the fuse blows.

For example, with 5 v activating a rotation repeatedly this works fine, but when done with the pic, the fuse blows. Very strange, so I think that is a matter of time, do not know.

Greetings
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Nov 08, 2010 6:49 pm     Reply with quote

The gates on the high side have to have enough voltage to turn on. Unlike the low side this voltage is not referenced to ground. Often a high side driver is needed to get the FET fully turned on. Also watch for any possibility the gates are on and create a short .
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 6:55 pm     Reply with quote

How is your PIC connected to your circuit?
Is the Vcc that feeds the motors the same 5v that is supplying the PIC?
The PIC would not like the motor/pwm noise on it's supply line.

Are the PIC lines B1 -> J1P1 and B3 -> J1P2?
Have you tried connecting only one of the motor lines to the PIC and grounding the other? That should drive the motor without the chance of blowing anything up. And it will prove your code is running (not being reset by noise) and at least kind of working.

I'm still not seeing how you could ever take B1 high and PWM B3 without blowing up your drivers. Is the PWM intended for one direction only?
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 7:00 pm     Reply with quote

Yeah, what Doug said.
I was assuming the other connector was to a higher voltage source.

(hmmm. misguided electrons and goto's. this could be a long thread, eh Mr. Kennedy?)
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 7:06 pm     Reply with quote

I would also start the code over with something very simple (like what TEM said earlier). Forget about the PWM stuff and avoid the goto's.

also, you do realize that when you try to detect both buttons:
Code:
 if (input(PIN_B4)!=0 && input(PIN_B5)!=0)

since both buttons cannot be pressed at exactly the same time, one of the other IF's will launch first.
Favalito



Joined: 08 Nov 2010
Posts: 6

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 7:14 pm     Reply with quote

Quote:

The gates on the high side have to have enough voltage to turn on. Unlike the low side this voltage is not referenced to ground. Often a high side driver is needed to get the FET fully turned on. Also watch for any possibility the gates are on and create a short .


hi Douglas Kennedy, at the top of the schema can see the entrance of MC step-up converter 34063, with that offset the decline in tension with the N-channel mosfet upper H-bridge
As you say your door to check the short?


Quote:
How is your PIC connected to your circuit?
Is the Vcc that feeds the motors the same 5v that is supplying the PIC?

if this can be a big problem?

Quote:
Are the PIC lines B1 -> J1P1 and B3 -> J1P2?
Have you tried connecting only one of the motor lines to the PIC and grounding the other? That should drive the motor without the chance of blowing anything up. And it will prove your code is running (not being reset by noise) and at least kind of working.


now proves it

Quote:
I'm still not seeing how you could ever take B1 high and PWM B3 without blowing up your drivers. Is the PWM intended for one direction only?


good thing I implement pwm to rotate slightly

Greetings.
Favalito



Joined: 08 Nov 2010
Posts: 6

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 7:20 pm     Reply with quote

Quote:
would also start the code over with something very simple (like what TEM said earlier). Forget about the PWM stuff and avoid the goto's.


ok, i probe.

Quote:

also, you do realize that when you try to detect both buttons:
Code:
if (input(PIN_B4)!=0 && input(PIN_B5)!=0)

since both buttons cannot be pressed at exactly the same time, one of the other IF's will launch first.


Tickets are not buttons, but another pic that receives an RF signal

greetings.
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 7:40 pm     Reply with quote

Okay, I think your telling me that grounding one of the wires allowed the pic to drive the motor. That is good. I think if you rewrite the code in smaller steps, and test each step, you will get it running very soon.

Yes, it is bad to connect your PIC supply to the motor supply. The noise can cause the PIC to reset unexpectedly.

Make sure you run your PIC & Motor grounds and VCC SEPARATELY all the way back to the power supply.

Make sure you have a couple of capacitors across the PIC power pins. Something like a 1uF Alum and a 0.1uf Ceramic would be nice, to supress the noise.

Since you are driving transistors, you could probably even DIODE ISOLATE your PIC by putting a forward biased diode between the power supply and the PIC (and capacitors). It will reduce your PIC output voltage slightly, but it will keep the PIC from being starved for current when the motor turns on.

Also, you are reading the input pins individually - that takes time. Even from an RF board you could get unexpected states if the change-in-state happens between reads. Better to read the entire port at once and mask for the bits of interest. Better yet, read-mask then read-mask and don't do anything unless the two readings match.

Hope that helps some.
Favalito



Joined: 08 Nov 2010
Posts: 6

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 7:53 pm     Reply with quote

pmuldoon, prove all the recommendations you gave me.
Thank you very much and greetings.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group