PDA

View Full Version : pause puts me in sleep mode



EDWARD
- 5th May 2005, 07:01
Its Edward again, with yet another problem.

i have a solenoid being driven by a NPN transistor. the base of the NPN is conneted to portc.2 if i make portc.2 output high it will turn on the solenoid as expected. i also have a push button connected to portb.0.
the goal is to turn on the solenoid for a short deley then turn off.

now comes the problem

when i use the PAUSE command it puts my pic 16f73 into low power mode or something, cause i only read ~3.5 volts on the vdd.

below are the two codes.
both codes work when led+resistor unit replace solenoid (no solenoid)
one works the other does not when solenoid is connected (solenoid)

'works


TRISC=235 'set PORTC as output on needed pins
TRISB=251 'PORT B INPUT EXCEPT on uneeded
'------------------------------------
MAIN:

PORTC=%00010000 'PWR LOCK-ON & solenoid data low

IF PORTB.0=1 THEN 'BUTTON 2 IS PRESSED ACTIVATE SOLENOID
GOTO SHOOT
ENDIF

IF PORTB.4 = 1 THEN 'BUTTON 1 IS PRESSED THEN EXIT
GOTO EXIT
ENDIF

GOTO MAIN
'---------------------------------------------------
EXIT:
PORTC = %00000000 'LOW PORTC all PWR OFF
END
'---------------------------------------------------

SHOOT:
PORTC.2 = 1 'SOLENOID ACTIVE
GOTO MAIN
'-------------------------------------------------








'doesnt work below

TRISC=235 'set PORTC as output on needed pins
TRISB=251 'PORT B INPUT EXCEPT on uneeded
'------------------------------------
PORTC=%00010000 'PWR LOCK-ON

MAIN:
IF PORTB.0=1 THEN 'BUTTON 2 IS PRESSED ACTIVATE SOLENOID
GOTO SHOOT
ENDIF

IF PORTB.4 = 1 THEN 'BUTTON 1 IS PRESSED THEN EXIT
GOTO EXIT
ENDIF

GOTO MAIN
'---------------------------------------------------
EXIT:
PORTC = %00000000 'LOW PORTC all PWR OFF
END
'---------------------------------------------------

SHOOT:
PORTC.2 = 1 'SOLENOID ACTIVE for 1/5 seconds
PAUSE 200 '<- RIGHT HERE RIGHT HERE RIGHT HERE IS PROBLEM!
PORTC.2 = 0
GOTO MAIN
'-------------------------------------------------


lastly when i disonnect the solenoid everything works fine again without a need to reset the pic. so the working model only alows the solenoid active AS LONG AS IM HOLDING BUTTON 2 DOWN. not a desired function i want the solen active for x number of seconds then off.

2 things come to mind.

1. if it was a hardware problem, why would it work just fine without the pause command.

2. when i tell portc.2 = 0 could that effect anyother pin on the portc?

u should also know that i have a "power on" command. becaue my boards power button is momentary button, the board was desgned that as long as portc.4 is high the vdd will be 5+. the board basically works like this.

1 press and hold pwr momentary button.
2 that sends 5+ to the pic and it starts the program
3 in the program I put portc.4 = 1 so that the vdd Locks-On
4 to power off pic just portc.4 = 0 or all of portC=0
5 that makes a transistor somewhere "off"

sory if i made this one too long.

NavMicroSystems
- 5th May 2005, 12:26
EDWARD,

I guess the problem is hardware related.
We would need to have a look at the schematic to further analysis.

Questions:

1. Where does the Solenoid get it's power from?
2. Do you have a Resistor between PortC.2 and the Base of the NPN?
3. Do xou have a reverse Diode across the Solenoid?
4. As your Buttons read "1" when pressed, do yo have PullDown Resistors on the corresponding PIC Pins?

Is this the same strange Board you had the LCD questions on?

EDWARD
- 5th May 2005, 21:38
yes it is the same board witht the lcd. i dont have the schematics for the board. the board has al surface mount components and i am trouble telling what ALL the parts are. i have figured alot out but not everything. i know the hardware will work because these boards have porgrams on them right now and work fine with the old code. i have erased one of them to use as my "test board" and have made no hardware changes.

the designer of the board, as it seems, did many things wrong. the designer

1:did not use a resistor on the soleniads npn base.

2:doesnt have any resistors to the inputs on portB, which cantains most
input buttons.

3: i think that there is a diode across the solenoid though.

4:solenoid is a 5vdc. it is driven by sinking. i got 9 volt going to a Vreg 5+, an that 5+ going to the red wire of the solenoid. the black wire goes to the collector of the npn.

( i am going to make a picture/table. im also going to try and create a schemati for you.)

mister_e
- 6th May 2005, 03:15
probably the transistor in use is a digital type with internal resistor or logic mosfet. that's why you don't have any external resisotr.

no resistor on PORTB... probably the internal pull-ups where in use. I bet the pushbutton are between PIC and gnd!

The major cause, as i suspect, might be the current provided by the power supply, must be unsufficient to make the 5 volt line goes to 3.5 volt. Use another power supply.

EDWARD
- 6th May 2005, 07:39
thanks for your response mister_e. i know that the hardware is sufficient for my purposes, but oddly enough the buttons are actually between 5+ and pic,weird.

also, i bought bunch of 9 volts, and still same problem. this only happens when i use the pause command. if the solenoid is programmed to ONLY BE ON WHEN THE BUTTON(on a different port) IS HELD TRUE, it works fine. but if i tell the solenoid to stay high for 1 seconds (PAUSE 1000) the vdd drops to 3.5. dang!

is it possible that some of the power to "help" drive the solenoid and/or PIC, comes from a data port? conversly, will defining (TRISX) to many pins as outputs (not necessarily HIGH), will draw excesive current?

EDWARD
- 6th May 2005, 08:13
ok guys i made a breakthrough of "KFC snacker size" proportions.

OK so im hungry and not funny. but i am gaining on my pause problem.
today i found out that if i short out portc.2 it will "turn off" my solenoid "driver" the only way for the driver to turn fully off is to short it. portc.2 =0 doesnt go low enough.

secondly, i found out how the driver works. my solenoid red wire is connected to a 5+, and the black wire of the solenoid is connected to 2 transitors in parallel. one of the transiters set the sink bias to make the solenoid "driver" at a 4.4 volts on the ground side, even when portc.2 is low. and when portc.2 goes high, it sinks the solenoid over 5+. thereby fireing the solenoid.

This has led me to beliver that when i ground out the portc.2 pin, which in turn turns off the driving transistor, which turns off the solenoid.

that can only mean that when i put portc.2 = 0 it is not going low enough. how do i make portc.2 less than 0 :) it really wierd cause as soon as i short portc.2 with my vdd goes back up to 5+.

ive tried swapping solenoids and batteries.

EDWARD
- 6th May 2005, 12:32
my pictures are at:
http://pg.photos.yahoo.com/ph/[email protected]/album?.dir=/6008

yo, i took some pics of my board and put them in a yahoo photo album thing. feel free to check em out. basically it shows the pic, the solenoid/batery harness side and a full view. one of the pictures has a mspaint drawing on it. oh yeah the picture i upside, sry forgot to rotate before i started editing.

BTW i think i figured out my lcd probem that was posted in pbc. ill just have to make my own subs and with all the data you great people have given me it should be a snap (oh here i got being all optimistic again)
thanks to whomever sent me to

(lcd HD44780 commands)
http://www.geocities.com/SiliconValley/Circuit/8882/lcd/commands.htm

and
lcd.bas example (it will open browser as txt file if u click it)

http://www.melabs.com/resources/samples/pbc/lcd.bas

NavMicroSystems
- 6th May 2005, 13:03
EDWARD,

could you draw a schematic of the "solenoid-driver" part?
It is still not clear to me what this looks like.

EDWARD
- 7th May 2005, 00:09
ok i tried to make a shcematc for ya. disregard the black box around the circuit if any.

Im not sure if the (B) PNP transistor is in fact a PNP, it could be some weird 3 pin device.

also its werid how there is a 5+ going into the solenoids RED supply and 4.2+ going into the solenoid on the BLACK supply. when i drive the npn base high (portc.2) the solenoid gets "stuck on" the 4.4 that was present on the BLACK is now 0vdc. and the RED is at 3.5 vdc, meaning the vdd is at 3.5.

even if i drive the portc.2 LOW the transistor stays on cause the board has "crashed". now i cant read the voltage at the transistor base because when i put the (my multimeter) black probe on the battery ground and the red probe
on the NPN base it drives the base Low making te solenoid turn off, and putting 5+ back on the VDD, thereby reseting the pic to the top of the program. if i disconnect the solenoid, i get all the expected reading at the expected times, e.g. portc.2 will actully out a 5+ vdc when i tell it to and 0vdc when i tell it too.

lastly, im telling you there is not a harware problem, power supply problem, solenoid problem. i have tested all my parts on another board, that still has the old code, and they work.

Warrier
- 7th May 2005, 16:04
Hi:

Looking at your schematic a few things can be explained:

The B transistor is connected as a forward biased diode! It drops about 0.6v and hence you see 4.4volt on the black wire of the solenoid.

When A transistor is turned on by taking portc.2 hi, it shorts out this diode to ground and very little current will flow through the solenoid! In fact voltage across it cannot exceed more than the Vce of the B transistor.

Since this is a functional board I have to assume that this configuration cannot be correct... The 5volt regulator usually drops about 1.5volts across it.

When the solenoid is ON (Vdd goes down to 3.5v as you note) the regulator output is being short circuited and it may be going into a voltage foldback current limit mode.

I have to assume that the LED works because you have a series resistor and LED takes only a few mA to turn on and the 5v regulator is able to supply that.

You can do two things:
1. Remove B transistor and replace it with a diode (1N4148 or 1N4001) with its cathode connected to the red wire of the solenoid (+5v)
2. Connect a capacitor (100uF) between the output of regulator and ground - if this is not already in the circuit.

I don't think it has anything to do with your code or the PIC. Of course you can clean it up by not using so many GoTo statements.

As for transistor A, as Steve correctly points out it may be a digital version (base resistors are built in). You can verify this by looking at the voltage on portc.2 when it goes hi - if it is close to 5v then the transistor is a digital type. Otherwise portc.2 will only go upto 0.6volt. In latter case you must add a 1k between portc.2 and the base of this transisitor.

hope these are helpful

-warrier

NavMicroSystems
- 7th May 2005, 16:12
Im not sure if the (B) PNP transistor is in fact a PNP, it could be some weird 3 pin device.I would assume (B) is a Diode in a three pin package.
(Cathode should be connected to the red wire of the solenoid, anode to the black wire.
Is there any SMD code printed on it?


also its weird how there is a 5+ going into the solenoids RED supply and 4.2+ going into the solenoid on the BLACK supply. with the NPNs (A) base low there is a voltage drop of about 0.8V accross the solenoid, this means there must be something else connected to the NPNs collector that is drawing current.


when i drive the npn base high (portc.2) the solenoid gets "stuck on" the 4.4 that was present on the BLACK is now 0vdc. and the RED is at 3.5 vdc, meaning the vdd is at 3.5. looks like the solenoid draws more power than the Vreg can deliver, that causes the voltage drop at the Vreg's output.


even if i drive the portc.2 LOW the transistor stays on cause the board has "crashed".
If the transistor stays on, the base isn't low !


now i cant read the voltage at the transistor base because when i put the (my multimeter) black probe on the battery ground and the red probe
on the NPN base it drives the base Low making te solenoid turn off, and putting 5+ back on the VDD, thereby reseting the pic to the top of the program. if i disconnect the solenoid, i get all the expected reading at the expected times, e.g. portc.2 will actully out a 5+ vdc when i tell it to and 0vdc when i tell it too.

Questions:
1. what is the resistance of the solenoid?
2. what kind of multimeter are you using and what is it's input resistance in the voltage range you have selected?




lastly, im telling you there is not a harware problem, power supply problem, solenoid problem. i have tested all my parts on another board, that still has the old code, and they work.

are you really sure the schematic matches the board?

EDWARD
- 7th May 2005, 23:08
yes its a led and a resistor series.

the transistor b is a digital type cause i do get 5v when i disconnect the solenoid.

I cant stress enough how harware is not the issue here. These boards are all surface mount, and i cant go cutting 1000+ traces guys. I didnt design 'em, or have anything to do with the manufaturing process. This device can be coded proprerly to work, i know this. i dont mind if the code idnt prtty, or has long boot sequncces(i have an lcd issue as well). im putting up some more pics in that yahoo album. ill double check that schematic for errors.

great info guys thanxs.

NavMicroSystems
- 8th May 2005, 12:49
...I cant stress enough how harware is not the issue here.
...This device can be coded proprerly to work, i know this.


EWDWARD,
of course there will be a way to get it to work, but it will be difficult without having a schematic.

A simple example I have seen in the past was a standard TTL I/O pin on the PIC being used as open Drain.

If you would assume it was a standard output, you would never get it to work.
You would have to make that pin an input if not driven low. (Some kind of "Software open-Drain")

With the unusual parts of your hardwares design we have seen so far I wouldn't be surprised if there was more of that kind.

To ensure the product works reliably with your new code you will have to do some reverse engineering and draw a full schematic of the board.

EDWARD
- 8th May 2005, 20:26
yes, it is going to be difficult, thats why im in here :)

i have decided to make a schemtic of the whole board. ill might even desolder one of my boards so i can see the layout better.

what are the basic priciples on uing an input control a trans?

It sounds like your saying i need portc.2 as an input throughout the whole process.

i can trisc more then once, right?

i already tried a code like this with no success: 'some things are wrong for simplicity.

'-----------------------------------------
main:

trisc=%11111011 'portc.2 as output

if portb.0 = 1 then 'if i press a button
gosub fire
endif

goto main

fire:
portc.2 = 1 'make transistor active
pause 500
trisc=%11111111 'portc.2 as input
pause 500
RETURN
'--------------------------------------------

NavMicroSystems
- 9th May 2005, 00:04
EDWARD,

The "Open-Drain" Scenario was just meant to be an example of a Hardware design that would give you a hard time in Software Development without knowing the schematic.

Desoldering one of the boards and drawing a full schematic is a good idea.
Try to document all type codes of the components before they are all wiped off.

BTW
Here is yet another example for your "Fire" Subroutine


Fire:
HIGH PortC.2 ' make transistor active
PAUSE 500
INPUT PortC.2 ' PortC.1 as input
PAUSE 500
RETURN

Warrier
- 9th May 2005, 00:44
Edward:

Don't tie yourself in knots with your code!

The reason for a good schematic is to see where and what causes such a heavy drain of current in your circuit to pull Vdd down. It is not to see how well you can desolder 1000+ connections as you think.

An NPN transistor needs a little more than 600mV on its base MORE POSITIVE than voltage on its emitter. A PNP needs 600mV LESS on its base than voltage on its emitter. A transistor unlike an FET is a current controlled device. The collector current is the product of base current and the current gain of the transistor. Transistors are made with different gain which is also a function of the frequency at which it operates. That's 101 on transistors. If you need more tutorial on transistors this is not the forum for it!

So if you need to turn on a NPN transistor you need to have two conditions met - voltage at base is higher than 600mv trelative to emitter voltage (=0)and provide sufficient base current to operate the load connected at the collector.

In your case, the PIC supplies 5volt out - you are trying to drive a solenoid. If your solenoid needs some current through its coil to turn it on - what is your solenoid spec? If it needs more current than what your regulator can supply then the 5v regulator will shut down and the solenoid will not turn on.

Solenoid also requires a minimum time to turn on. If your solenoid turn on time is more than 200msec it will just click but will not come on.

Now to your latest code - you turn on portc.2 and then trisc the pin to input! That will not turn off the solenoid unless transistor A is a digital type and connects the base to emitter through a resistor so that when portc.2 becomes input the base voltage drops to zero. Leaving the base open with collector driving an inductive load is a good way to destroy the part.

You must have changed the 5volt regulator and the solenoid from your original unit - Even if you short circuit all output pins of portc the PIC will not draw enough current (that's <200mA) to pull Vdd to 3.5volts. Your post says pause puts you to sleep - do you realize that sleep mode keeps the PIC at its lowest power consumption!!!!!!!

Like Ralph says, post your schematic correctly - if you can't tell a diode from a transistor then you have a long way to travel, my friend.

-warrier

EDWARD
- 9th May 2005, 03:55
did you read this forum from start to finish?

i know how a transistor works.

what are you talking about seeing how good i can desolder?

there are leads that run under componets, ill need to only desolder 1 board dude.


i have 1000+ of these boards,not connections. so i can get the component data either before or afterwards or any time in between.

i know the code wasnt going to work, it was to try and get an understanding on what NAV ment in his previous post.

yeah i changed a surface mount pcb......not!

oh yeah, could you be anymore condensending??

dont bother replaying warrior cause i dont need help from a jerk. ive been very polite so far and i think i deserve to be talked to better then that.

and for the last time NO F'ING HARDWARE CHANGES!!!

and lets say i dont knw what a diode is or a transitor is, does that give you the right to be a jerk?

you are an idiot warrier. please dont fill up this forum with your trash.

oh yeah, i have a ! button too.

Warrier
- 9th May 2005, 05:26
Edward:

The first thing you learn is to keep your language clean! This is not a tabloid...

It looks as though your willingness to learn or understand technical forum is as good as your soapy language...

You don't run this show and if you can't take some critique then keep digging into your SMD stuff - no one is stopping you.

As for knowing how things work - may be you could take some elementary courses in the English language before you try these forums which are for people with a little more savvy.

Good luck

-warrier

NavMicroSystems
- 9th May 2005, 08:53
Do you really think this is the right place for a conversation like this?

John C
- 9th May 2005, 13:54
Edward is PORTC.2 set to digital using the CMCON Register

EDWARD
- 10th May 2005, 01:26
k thanks for the input guys but i finally got it working today. for some reason the solenoid cant be programmed to stay on for more than a few milla seconds, not sure why this is happening. if I PULSOUT PORTC.2, 10 (ive got a 4mhz osc) itll work, and i havent done too much fiddling around yet but im sure there is maximum PULSOUT time that will work with this design. thanks for all the help guys I do appreciate it. thanks for all the replys NAV. but as for my problem i think i got it under control. peace out. I think the board was designed to control the air( going thru the 'noid) using some sort of "Pneumatic Pulse Width MOD." PWM. weird design but itll work for my purposes.

the solenoid needs to keep turning on and off rapidly to feed the ram, must be they dont use accurate regs for the pnumatic ram. once again thanks guys, ive learned alot here. sry warrier i shouldnt have said that stuff. peace.