Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ttl switching 12V supply

Status
Not open for further replies.
eblc1388 said:
Check again with a voltmeter connected across the motor.

If there is 12V and the motor isn't rotating, bad motor or motor not a DC normal brush motor but AC motor or stepper motor.

If there is no voltage, check all power connections for broken wires etc. Also check the 12V is healthy.

I'm positive that the motor works.
The PIC outputs 5V when the motor is not connected, but when it is connected, the PIC output is 0V.
 
eblc1388 said:
Sorry. Some sort of misunderstanding.

So you are saying most PIC's outputs would be pulled-high even they are LOW before the chip enter power save mode? Now that's worrying.
Well I ment IC's in general. PIC's remain their I/O state durring sleep, so that's not a problem. But imagine that the PIC won't start (eg Oscilator failed or SW problem) the PINs will be in input state (maybe with even pull-ups enabled), and the motor WILL spin.
 
ptewright said:
The PIC outputs 5V when the motor is not connected, but when it is connected, the PIC output is 0V.

That's the problem. PIC don't like motor. You must not let the PIC knows that you are using it to drive a motor because it thinks it is supposed to do more important things. :lol:

Joking aside, how can the PIC knows that you have a motor connected via a MOSFET?
 
Jay.slovak said:
I wouldn't be that sure, most IC's have outputs in high impedance or pulled-high when they are off. And that would cause motor to spin.

You may be correct. But what do you mean by "off"?

I assumed you meant that the supply to the PIC is disconnected but the gnd is still connected.

Len
 
eblc1388 said:
ptewright said:
The PIC outputs 5V when the motor is not connected, but when it is connected, the PIC output is 0V.

That's the problem. PIC don't like motor. You must not let the PIC knows that you are using it to drive a motor because it thinks it is supposed to do more important things. :lol:

Joking aside, how can the PIC knows that you have a motor connected via a MOSFET?

Could you please tell me how to do that?
 
ptewright said:
Could you please tell me how to do that?

If you want to test and find out what the problem is, follow the instructions closely:

1. take only MOSFET(IRF540) and 12V motor, no PIC needed.
2. 12V power off
3. connect IRF540 source pin to 0V, drain pin to motor.
4. connect IRF540 gate pin to 0V
5. connect other end of motor to 12V and power ON

Motor should not turn. Power off 12V.

6. now connect gate to 12V
7. power 12V ON and motor should turn

Report results to this forum of each above step whether it is OK or fail.
 
eblc1388 said:
ptewright said:
Could you please tell me how to do that?

If you want to test and find out what the problem is, follow the instructions closely:

1. take only MOSFET(IRF540) and 12V motor, no PIC needed.
2. 12V power off
3. connect IRF540 source pin to 0V, drain pin to motor.
4. connect IRF540 gate pin to 0V
5. connect other end of motor to 12V and power ON

Motor should not turn. Power off 12V.

6. now connect gate to 12V
7. power 12V ON and motor should turn

Report results to this forum of each above step whether it is OK or fail.

Thank you!!
I did the tests as you suggested, all of them turned out as expected, so that means the MOSFET and motor are working properly right?

Here's my circuit. Tell me if there's anything wrong with it.
The motor is suppose to have a max current of 0.92A.

Using this circuit, the motor sometimes turns on, sometimes doesn't work at all. And when it turns on, it doesn't turn off after, even if my PIC attempts to output a 0V, the gate of the MOSFET remains at about 2.5V
I really need help........thanks a lot :D
 

Attachments

  • mycircuit.jpg
    mycircuit.jpg
    15.8 KB · Views: 579
Good. We are making progress, at last.

ptewright said:
Using this circuit, the motor sometimes turns on, sometimes doesn't work at all. And when it turns on, it doesn't turn off after, even if my PIC attempts to output a 0V, the gate of the MOSFET remains at about 2.5V
I really need help........thanks a lot :D

Do the above test again, but this time at step (6), connect the gate via R1 to +5V instead of +12V. i.e. disconnect R1 from rb0 and connect R1 to +5V.

If the motor is functioning good, then problem is in PIC or programming.

If the motor is sometimes running and sometimes do not, then problem is MOSFET assuming R1 is good. The gate voltage of IRF540 worst case requires 4V to start conducting so at 5V it could conduct only a little and not been able to start the motor. Solution is to use logic level MOSFET type of which operates on gate voltage of +5V. Or you can use a normal P-Type Mosfet and drive it with a NPN transistor.

If problem is in PIC, either there is bug in your programming or the port pin of the PIC is damaged.

Have you set up the port properly? How do you turn the motor On and off?
You can attach the source file here and other PIC experts can have a look.
Sorry can't help you more here because I'm a 8051 man.
 
Code

eblc1388 said:
Good. We are making progress, at last.

Do the above test again, but this time at step (6), connect the gate via R1 to +5V instead of +12V. i.e. disconnect R1 from rb0 and connect R1 to +5V.

If the motor is functioning good, then problem is in PIC or programming.

If the motor is sometimes running and sometimes do not, then problem is MOSFET assuming R1 is good. The gate voltage of IRF540 worst case requires 4V to start conducting so at 5V it could conduct only a little and not been able to start the motor. Solution is to use logic level MOSFET type of which operates on gate voltage of +5V. Or you can use a normal P-Type Mosfet and drive it with a NPN transistor.

If problem is in PIC, either there is bug in your programming or the port pin of the PIC is damaged.

Have you set up the port properly? How do you turn the motor On and off?
You can attach the source file here and other PIC experts can have a look.
Sorry can't help you more here because I'm a 8051 man.

The mosfet works fine with that test, how do I determine if the R1 value is correct?
Here's my code. It basically turns on the motor for 30seconds, turns off for 30 seconds, turn on for 30 seconds... Anything wrong with it?

#include <pic.h>
#include <pic16f62xa.h>

// 16F77 config word
__CONFIG(0x2121);


//feedback
static unsigned int counter; // counter for time elapsed
static unsigned int seconds; // sets desired pulse frequency
// ON time of pulse
void main(void)
{
TRISA = 0x00; // Port A: output
TRISB = 0x00; // Port B: output
PORTA=0x00; // Initialize Port A to 0
PORTB=0x00; // Initialize Port B to 0

//timer0
T0CS = 0; // Increment timer0 on instruction clock
T0IE = 1; // Enable interrupt on TMR0 overflow
T0IF = 0; // Clear the Timer0 interrupt flag
TMR0 = 0;
PSA = 0; // Sets the prescaler to Timer0 module
PS2 = 1; // Sets the prescale to 1:256
PS1 = 1; // Sets the prescale to 1:256
PS0 = 1; // Sets the prescale to 1:256
// overflow every 4*256*256/4000000 = 0.065536s

seconds = 916; // 60s/0.065535 = 916
counter = seconds;

// ADCON1 = 0x06; // Set PORTA to digital I/O

GIE = 1; // Enable global interrupt

while(1)
{
if(counter == 916)
{
RB1 = 1; // motor on
}
if(counter ==458)
{
RB1 = 0; // motor off
}
if(counter == 0)
{
counter = seconds;
}
}
}

static void interrupt
isr(void)
{
if(T0IF) // Timer0 interrupt
{
T0IF = 0; // Clear interrupt flag
counter--;
}
}
 
Because MosFETs are controlled by voltage, the resistor value is not critical, anything from 0-1K (yes, you can leave it out!) is fine...
 
PIC enable to go back down to 0V

I tested my PIC, the output rb0 goes 5V, 0V, 5V, 0V... correctly!!
I tested my mosfet and the motor, they work too.
however, when i feed the output rb0 to the gate of the mosfet, the mosfet turns on when at 5V, but it stays stuck there. Why is that?
 
Re: PIC enable to go back down to 0V

ptewright said:
I tested my PIC, the output rb0 goes 5V, 0V, 5V, 0V... correctly!!
I tested my mosfet and the motor, they work too.
however, when i feed the output rb0 to the gate of the mosfet, the mosfet turns on when at 5V, but it stays stuck there. Why is that?
Did you try to put the Pull-down there? Also did you measure the gate voltage when it won't turn off?
 
Hi Jay,

Do you see any problem in this C code? Or in C code the first pin of the port is 1 and not zero.
 

Attachments

  • mycircuitx.gif
    mycircuitx.gif
    15.6 KB · Views: 524
eblc1388 said:
Hi Jay,

Do you see any problem in this C code? Or in C code the first pin of the port is 1 and not zero.
Did you set RB0 to output?

I will make and send you sample code in Assembly, wait... :wink:
 
Jay.slovak said:
I will make and send you sample code in Assembly, wait... :wink:

I do not want any assembly code. The drawing & code is related to this thread by ptewright. I just wonder about the rb0 and RB1 notation.
 
eblc1388 said:
Jay.slovak said:
I will make and send you sample code in Assembly, wait... :wink:

I do not want any assembly code. The drawing & code is related to this thread by ptewright. I just wonder about the rb0 and RB1 notation.
But I already made you one :cry: ...

Give it a try... it's HEX, Internal Oscilator, No MCLR... 16F627, It sets PORTB on and OFF every second.
 

Attachments

  • test627.hex.doc
    871 bytes · Views: 128
Jay.slovak said:
But I already made you one :cry: ...

I hope it will run on my 8051. Wait a minute, it does !!!

You still have not answered my question. Is rb0 = RB1 in C ?
 
eblc1388 said:
Jay.slovak said:
I will make and send you sample code in Assembly, wait... :wink:

I do not want any assembly code. The drawing & code is related to this thread by ptewright. I just wonder about the rb0 and RB1 notation.

Sorry, I changed the output pin to rb1, just to see if the pin was broken. It didn't make a difference.

From my testing, it seems that the PIC is resetting every time it tries to drive the motor, that is why it never turns off.
So then i tried setting rb1=0 first, then rb1=1 second. When tested, the motor is off for 30seconds, then the motor turns on for about 2 seconds, and the whole thing resets, so motor is off for another 30 seconds, then it tries to turn on the motor for like a few seconds, and then automatic reset again........... :twisted:

(and obviously, if i take out the motor, then the PIC does the on/off thing properly)

why is that??? is the PIC not able to drive the mosfet???
is there a way to stop the resetting?
I didn't think that this circuit would be so complicated!!! :shock:
 
eblc1388 said:
Jay.slovak said:
But I already made you one :cry: ...

I hope it will run on my 8051. Wait a minute, it does !!!

You still have not answered my question. Is rb0 = RB1 in C ?
I don't "speak" C yet, so I can't tell you! But it's highly unprobable!!! I think rb0=RB0 in C
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top