PDA

View Full Version : Pic12f683, Trisio, High Z, A2d



jmbanales21485
- 8th April 2007, 01:27
Hello to all,

I have a little problem on the 12F683. I want to get the pin GPIO.0 to switch from a LOW state (GND) to a High impedence state (High Z) and while in High Z take an anolog to digital conversion at GPIO.4.

The problem with the current circuit and Code that i have (attached is a schematic and sample code) is that while in in the LOW State the A/D will be normal and read normal voltage. However, in the HIGH Z state the PIN GPIO.4 (or AN3) will jump to a HIGH state (i.e to VDD).

Does anyone have any suggestions on how I can go about achieving this task? Maybe another way of switching from High Z to Gnd? Any help would be greatly appreciated.

Sammple Code:

'Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
Define OSC 4 'define oscilator
Volt VAR WORD
main:
TRISIO = %010000 'Set GPIO.0 as OUTPUT
LOW GPIO.0 'GND STATE
Pause 5000
TRISIO = %010001 'Set GPIO.0 as input (HIGH Z State)
pause 4000
ADCIN 3, Volt
if Volt >= 970 then loop
pause 1000
goto main

loop:
goto main
END

Schematic Attached:
Thank You All!

keithdoxey
- 8th April 2007, 01:46
Does the PIC have a common ground with the circuit you show in your diagram ?

Acetronics2
- 8th April 2007, 10:50
A good question would be How much are Va and Vb ...

probably more than the VDD supply of the pic ...


gave you some idea for debugging your Pic batt charger ???

Alain

jmbanales21485
- 8th April 2007, 10:55
well, i guess i missed that little detail in the schematic. I used the voltage from Vb to power the PIC (VDD) and also used the same common ground for Vss. I'm making a battery charger and basically i want to take the voltage measurement at Vb while there is no current going into the battery from the outside voltage source Va (i want to do this because the voltage of the battery increases while the current is going into the battery, however when the current is removed i can measure the voltage of the battery and it will be closer to the open voltage.)

I hope this makes a little more sense.

jmbanales21485
- 8th April 2007, 10:58
Vb = 4v
Va = 9v
Ic = 280 mA (while in LOW state)
Ic = 0.05 mA (while in High Z state)

if this helps at all

keithdoxey
- 8th April 2007, 12:51
You need to use an NPN transistor to drive R3 not the PIC.

Because the PIC is powered from 4V the voltage on its pins cannot exceed 4.6v due to internal protection diodes. This means that even when in its hi-z state current will still be flowing via R3 which would explain why you stil have current flowing even when it is supposed to be off.

T.Jackson
- 8th April 2007, 14:55
Keith is 100% correct. The base of Q2 would need to be at the same level as Va in order for it to switch off. 0.6v or more below Va would mean that it's biased on.
You will find that in its current form Q2 is actually always on.

Trent Jackson

jmbanales21485
- 8th April 2007, 18:39
I'll try that solution as soon as i can and get back to you to see if it worked out. but everything seems logical thanks.
jose

jmbanales21485
- 12th April 2007, 23:19
The NPN Transistor driving R3 works fine. thank you all for your help it is greatly appreciated!

jose

erice1984
- 5th July 2007, 20:34
if you put a resistor on the battery for a short period you can decrease surface charge a lot and get an even more accurate reading (closer to actual charge held) on the battery