Setting a Pin a As a Ground? (GreatCowBasic)

Thread Starter

ajm113

Joined Feb 19, 2011
174
Hello I have a PIC 12F675 and I'm using great cow basic and I wrote a program that turns a fan on and off and I want to use a PNP transistor to act as a switch, but I need a pin to act as a ground so it works.

But for the life of me I can't figure out how to set it as a ground in Great Cow Basic.

I'm trying set GPIO 0 as ground.

Here is the code in GCBASIC:
Rich (BB code):
;Chip Settings
#chip 12F675,0
#config MCLRE=OFF, WDT=OFF

;Variables
Dim byOffDelay As integer
Dim byOnDelay As integer
Dim OutputVar As byte
Dim CountStartTimer As integer

byOffDelay = 1000
byOnDelay = 1000
CountStartTimer = 0
Dir GPIO.0 Out
Dir GPIO.1 In
Dir GPIO.2 In
Dir GPIO.4 In
Set GPIO.0 On
Goto DelayOff
DelayOn:
Repeat byOnDelay
	Pot GPIO.4, OutputVar
	Wait 1 ms
	If GPIO.1 = On Then
	Else
		CountStartTimer = CountStartTimer + 1
		If CountStartTimer >= 300 Then
			CountStartTimer = 0
			Set GPIO.0 On
			Goto DelayOff
		End If
		byOffDelay = 1000 * [integer]OutputVar
	End If
	If GPIO.2 = On Then
	Else
		byOnDelay = 1000 * [integer]OutputVar
	End If
End Repeat
Set GPIO.0 On
Goto DelayOff
DelayOff:
Repeat byOffDelay
	Pot GPIO.4, OutputVar
	Wait 1 ms
	If GPIO.1 = On Then
		CountStartTimer = 0
	Else
		CountStartTimer = CountStartTimer + 1
		byOffDelay = 1000 * [integer]OutputVar
	End If
	If GPIO.2 = On Then
	Else
		byOnDelay = 1000 * [integer]OutputVar
	End If
End Repeat
Set GPIO.0 Off
Goto DelayOn
If you perfer assembly language let me know and I'll post it on a copy and paste website, I'm in a rush atm.

Thank you!
 
Just invert the sense of GPIO.0 to Off, in place of On. Wouldn't hurt to add a higher value pullup resistor (47k) to the base of the pnp, or gate of a pfet.
 

Thread Starter

ajm113

Joined Feb 19, 2011
174
Really? I wouldn't think just setting it to "off" would solve it and putting a 47K at the base. Wouldn't setting it "off" just simply create a low current instead and cause problems such as fried parts?

I'm just wondering cause I'm new to this and I really don't want to fry anything with volts from 4v-13v. I'll give it a try when I get a chance though, it just kinda seems different or unexpected to me.
 
Last edited:
Yes if the source is above 5v then using the pullup would then depend on the pics internal clamping diodes, not so good without an additional buffer. Since the pin won't be floating then it shouldn't be a problem. I was thinking of a circuit with a pfet driver that did the level translation to a higher source voltage, my fault.

When in doubt I try my logic out on leds to start with, then move up from there.
 
Last edited:
Well I jumped in the muck of level translating with a pnp, and it looks like web says that a npn is required to control the base of the pnp. Interestingly, a pullup is used in that configuration on the pnp base.

I'm used to using logic level mosfets with microcontrollers. The easiest way would be to use something like an IRL510 nfet to control the low side of the fan.
 

Thread Starter

ajm113

Joined Feb 19, 2011
174
Hmm, well I tried a few methods such as using the NPN only and by using a 1.5K pull up resistor and it seems to work a bit better, what I find strange about the hole thing is if the base resistor is more then 10K then the NPN seems to ignore it completely and I've tried methods such as this one:

So instead of using a PNP I went ahead and used a 5v relay switch that was controlled by a NPN and it made the job faster and simpler since the fan was only going to go on and off ever few minutes.
 
Top