Maker Pro
Maker Pro

MOSFET/circuit troubleshotting :-\

A

Andrew Holme

Jan 1, 1970
0
Danny said:
Wha?! :-\
I know about weak pull-ups for inputs, but didn't realise there was
anything for outputs...


Nope.

I've checked the datasheet (PIC12F629) re Q2, and can't find any
mention of what you suggest - aand weak pull-ups it says are for
inputs, and are disabled for outputs...

If I tie the inputs high (to Vdd), instead of leaving them unconnected
(with pull-ups, they're high anyway), the voltage on both output pins
doubles when high (around .6 and 1.19)

I'm *totally* confused!

I think Anthony has spotted the problem. You're switching the outputs on
and off in a loop! Your meter is reading the average value of a
high-frequency square wave.
 
D

Danny T

Jan 1, 1970
0
Anthony said:
I looked at the code you posted in a.m.8-bit. What voltage does the pin
put out when it is not connected to the MOSFET? Your loop is turning
the motors off at the beginning. Assuming a clock of 4Mhz, your loop
takes 12uS to execute. 8 of those 12uS are spent with outputs turned
off resulting in a square wave with a duty cycle of 33%, hence the
average voltage is 1.3V. (1.3V * 3) + .7V = 4.6V or to put it another
way (4.5V - .7V)/3 =~1.3V

The motor failed to turn at all, it wasn't just slow (this is after I
got the rest of the stuff the right way round ;))
Do you have external pullup resistors on the inputs? If so, what value?

I did (10K), but it made no difference. Internal pull-ups are enabled,
and I now leave the pins unconnected.

My current circuit is 4.5V to Vdd, with a 1uF cap across Vdd to Vss. Vdd
and MCLR are connected with a 1K resistor. GP4 and GP5 are unconnected
(outputs - I'm putting my meter on these), and GP0, GP1 and GP2 are left
unconnected (I've connected these to ground to test "low" output readings).

How did you come up with your __CONFIG value. It all looks good except
for the '3'. Shouldn't that be a '1'? The datasheet says that other
bit is unimplemented.

I've changed this. I used the drop-down boxes in MPLAB and set the
options, and it generated 3A4. After posting that code, I checked
everything in the datasheet, and changed it to 1A4 after coming to the
same conclusion!

Updated code is below. Setup is as described above...

*dawns*

You're right!! My output is reading really low on my meter, because it's
off for *most* of the time! Stupid fool! I'll change the logic to
"buffer" it (like further down, or I'll call the delay after turning
the motors on).

Don't I feel stupid!

Thanks - it's really appreciated!
 
A

Anthony Fremont

Jan 1, 1970
0
Danny T said:
ground?

Wha?! :-\
I know about weak pull-ups for inputs, but didn't realise there was
anything for outputs...

Some PICs (many actually) have some open collector output pins. They
are not configurable, you just have to know that they exist and deal
with them appropriately. I checked the datasheet and your PIC (12F629)
does not appear to have any open collector outputs. Open collector
means that the output pin cannot output a 5V driving signal, it can only
pull low. This means that the pin cannot *source* and current, it can
only *sink* it. If the pin is being used as an output pin and you wish
to drive say an LED, you would use an external pull-up resistor to
supply the positive voltage to illuminate the led and then turn it off
by driving the pin low. Open collector outputs are common in the micro
world.
Nope.

I've checked the datasheet (PIC12F629) re Q2, and can't find any mention
of what you suggest - aand weak pull-ups it says are for inputs, and are
disabled for outputs...

If I tie the inputs high (to Vdd), instead of leaving them unconnected
(with pull-ups, they're high anyway), the voltage on both output pins
doubles when high (around .6 and 1.19)

I'm *totally* confused!

Never leave input pins unconnected, always have some kind of pull-up or
pull-down resistor applied, be it internal or external. The code I saw
in a.m.8 has the internal pull-ups disabled, so I hope you have external
pull-ups applied to the input pins.
 
D

Danny T

Jan 1, 1970
0
Anthony said:
I looked at the code you posted in a.m.8-bit. What voltage does the pin
put out when it is not connected to the MOSFET? Your loop is turning
the motors off at the beginning. Assuming a clock of 4Mhz, your loop
takes 12uS to execute. 8 of those 12uS are spent with outputs turned
off resulting in a square wave with a duty cycle of 33%, hence the
average voltage is 1.3V. (1.3V * 3) + .7V = 4.6V or to put it another
way (4.5V - .7V)/3 =~1.3V

I'm not getting 2-3V (with delays added after the motors are turned on).
This is only on the pin with my LED though (measuring voltage in
parallel with the LED).

The time spent "high" is more than enough to make the LED look like it's
lit constantly, but obviously wasn't enough to drive the MOSFET.

I'll re-write my code later, before re-connecting the motors and see how
it goes!

Thanks all! :)
 
J

John Popelish

Jan 1, 1970
0
Danny said:
http://dantup.me.uk/tmp/breadboard.jpg

I've tried to mark as much as I can, since any angle I took the pic from
obscured something! Under the larger cap is another diode, like the one
you can see. These two diodes are slightly different to the one used for
back EMF protection, since I was using up some old bits.

As I said, replacing the MOSFET with a cable between S/D causes the
motor to spin. Moving the cable connected to G to and LED, also works fine.

:-\

I don't see how the motor runs, even if you short the mosfet drain ot
source.

It looks like the positive lead on the motor (the one that ties to the
cathode of the reverse voltage clamping diode and the small blue
bypass cap has no connection to the diodes to the positive supply.
 
J

John Popelish

Jan 1, 1970
0
Danny said:
It's only just over 1V, but the motor is *on*. When the pin goes low,
the pin output drops to exactly 0, but the motor only slows - this
doesn't make any sense?

It makes sense if the gate oxide has been blown and there is a low
resistance, now, between gate and source. Take the mosfet out and
check the gate to source resistance with an ohm meter.
 
J

John Popelish

Jan 1, 1970
0
Danny said:
I believe all my problems come down to the one thing - my pic "high"
isn't really high.

I've got two chips, both with the same program burnt (I can post, it it
helps).

They sit "high" until an input goes low, then they go low too.

Using my meter, is seems these outputs are:

GP4 0.3V (way below the min the datasheet says!)
GP5 0.6V

When I make the input low, they go:

GP4 0V
GP5 0V

Both chips do the same, and I can't find anything in the datasheet to
suggest even if I had something silly enabled/disabled, this would happen.

Any ideas?

Without a scope to look at these outputs, you have little assurance
that you are really getting a continuous logic high out of the pins,
and not a train of slim pulses. You might connect a small capacitor
in series with your meter, set to AC volts, and see if you get no AC
(steady voltage) on the logic high test. If you measure more than a
few millivolts AC, you are not getting a steady state output.
You are troubleshooting both software and hardware, simultaneously.
 
A

Anthony Fremont

Jan 1, 1970
0
John Popelish said:
I don't see how the motor runs, even if you short the mosfet drain ot
source.

I don't know what particular MOSFET he's using, but if it has an
internal protection diode and is put in backwards, wouldn't this happen?
 
J

John Popelish

Jan 1, 1970
0
Danny said:
You said I want a 100nF cap from Vdd to Vss.. Just noticed I've got a
100uF... Guess I ordered the wrong ones...

All I currently have are 100uF, 1000uF and 1uF (ceramic). Is what I'm
using ok, or should I use one of the others?

The capacitors are okay, and your connections match your schematic,
but you didn't follow my directions. Your connections force the motor
noise to go out to the ground bus and back on their way to the
capacitors. Those capacitors should be plugged directly into the
source row to keep that noise current local.
 
A

Andrew Holme

Jan 1, 1970
0
Danny said:
it's off for *most* of the time! Stupid fool! I'll change the logic to
"buffer" it (like further down, or I'll call the delay after turning
the motors on).

Buffer it. Don't just put in a delay. You'll needlessly create glitches if
you rapidly switch it on and off; even if it's only off for a micro-second.
That would be sloppy. You shouldn't need a delay if you're doing it right.
 
D

Danny T

Jan 1, 1970
0
Andrew said:
Do you have them configured as open-drain outputs with weak pull-up? Are
you even sure you have them configured as outputs?

Yes, they're *definately* outputs. I don't understand what open drain or
weak pull-ups are. The only reference to either of these are weak
pull-ups for inputs, which are disabled for outputs :-\

As you've probably seen elsewhere, I've got it sorted now, it was down
to the logic of my programming. The pin was high less than half the
time, so although enough to light an LED constantly, it wasn't enough to
drive the MOSFET. Thanks for your help, sorry I didn't post enough info
in this group to show what was wrong!!

Sanity check: what does the voltage on the Vdd pin measure? Is that 4.5V??

It did :)
 
D

Danny T

Jan 1, 1970
0
John said:
The capacitors are okay, and your connections match your schematic,
but you didn't follow my directions. Your connections force the motor
noise to go out to the ground bus and back on their way to the
capacitors. Those capacitors should be plugged directly into the
source row to keep that noise current local.

Ok, I'll change this. Does it really make that much difference, it's
only one wires length from ground anyway? :-\
 
D

Danny T

Jan 1, 1970
0
Anthony said:
Never leave input pins unconnected, always have some kind of pull-up or
pull-down resistor applied, be it internal or external. The code I saw
in a.m.8 has the internal pull-ups disabled, so I hope you have external
pull-ups applied to the input pins.

I don't remember what I posted then, but bit 7 of my INPUT register is
current set to 1, to allow pull-ups. The individual pull-ups are enabled
on power :)
 
D

Danny T

Jan 1, 1970
0
Andrew said:
Buffer it. Don't just put in a delay. You'll needlessly create glitches if
you rapidly switch it on and off; even if it's only off for a micro-second.
That would be sloppy. You shouldn't need a delay if you're doing it right.

I agree, I meant for testing. It worked, and I'll write it properly now :)

Thanks again,
 
D

Danny T

Jan 1, 1970
0
Andrew said:
Buffer it. Don't just put in a delay. You'll needlessly create glitches if
you rapidly switch it on and off; even if it's only off for a micro-second.
That would be sloppy. You shouldn't need a delay if you're doing it right.

I've changed my code, it now looks like this:

Start
clrf TMPOUT ; Clear temp output
btfsc GPIO,2 ; If left sensor is high
bsf TMPOUT,4 ; Right wheel on!
btfsc GPIO,0 ; If right sensor is high
bsf TMPOUT,5 ; Left wheel on!
btfsc GPIO,1 ; If front sensor is high
clrf TMPOUT ; stop all!
movf TMPOUT,0 ; Move output
movwf GPIO ; To GPIO
GOTO Start ; Start again

My question is... If I had a third output, the "Stop all!" line would
turn it off. Is there any way to clear two bits and leave the other 6
unchanged, without having to do:

btfsc GPIO,1 ; If front sensor is high
bcf TMPOUT,4 ; stop left!
btfsc GPIO,1 ; If front sensor is high
bcf TMPOUT,5 ; stop right!

Since this wouldn't necessarily be consistant (if the sensor switches
between those lines), which probably means reading from GPIO onto a temp
register, then processing here. Writing bytes with unchanged bits would
be much better!
 
D

Danny T

Jan 1, 1970
0
Danny said:
I've changed my code, it now looks like this:

Start
clrf TMPOUT ; Clear temp output
btfsc GPIO,2 ; If left sensor is high
bsf TMPOUT,4 ; Right wheel on!
btfsc GPIO,0 ; If right sensor is high
bsf TMPOUT,5 ; Left wheel on!
btfss GPIO,1 ; If front sensor is low
clrf TMPOUT ; stop all!
movf TMPOUT,0 ; Move output
movwf GPIO ; To GPIO
GOTO Start ; Start again

I've corrected that, the front sensor is low to say stop, whereas the
other sensors are the opposite
 
A

Anthony Fremont

Jan 1, 1970
0
Andrew Holme said:
Buffer it. Don't just put in a delay. You'll needlessly create glitches if
you rapidly switch it on and off; even if it's only off for a micro-second.
That would be sloppy. You shouldn't need a delay if you're doing it
right.

I completely agree.
 
J

John Popelish

Jan 1, 1970
0
Danny said:
Ok, I'll change this. Does it really make that much difference, it's
only one wires length from ground anyway? :-\

Yes, it actually does. And the length of the leads on the capacitors
matters, too. Sometime you might calculate the inductance of those
wires and how much voltage that inductance can produce when an ampere
turns on or off through it in a few tens of nanoseconds. Wires are
inductors.

I would lay out a circuit board for this circuit that put the positive
motor lead adjacent ot the source pin, and jump that small distance
with a low ESR capacitor. That is the only way to keep all that
current pulsing out of the rest of the system.
 
A

Anthony Fremont

Jan 1, 1970
0
Danny T said:
I don't remember what I posted then, but bit 7 of my INPUT register is
current set to 1, to allow pull-ups. The individual pull-ups are enabled
on power :)

Bit 7 of the OPTION register is /GPPU (active low). Setting it
*disables* the pull-ups. Upon power-up, the pull-ups are disabled
because the bit is set.
 
D

Danny T

Jan 1, 1970
0
Anthony said:
Bit 7 of the OPTION register is /GPPU (active low). Setting it
*disables* the pull-ups. Upon power-up, the pull-ups are disabled
because the bit is set.

Doh!

Been a long few days... Corrected now - setting my option register to 0h.

Ta :)
 
Top