PDA

View Full Version : pot command



trying
- 3rd May 2006, 05:30
Trying to learn to use the pot command
I have a 50k pot and .1uf cap connect as per the PBP man.
led should come if pot takes BO<125 off if BO> 125(starting point)
I've tried changing the scale from 1 to 255 as well as BO <xxx
do you see any problem with my code
any help thanks


@ DEVICE pic12F675
@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F675, WDT_ON
@ DEVICE pic12F675, MCLR_OFF
@ DEVICE pic12F675, CPD_OFF
@ DEVICE pic12F675, BOD_OFF
@ DEVICE pic12F675, PWRT_ON
@ DEVICE pic12F675, PROTECT_OFF
DEFINE OSC 4
Pause 10000 ' ALLOW PIC TO STABILIZE
TRISIO = %00001100 ' MAKE GPIO.2/.3 INPUTS
ANSEL = %00000100 'MAKE GPIO.2 ANALOG
CMCON = 7


SYMBOL LED = GPIO.5

LED=0

LED=1
Pause 250 'POWER UP OK
LED=0

BO VAR WORD

Pot GPIO.2,255,BO




CHECKIT:
LED=0
IF BO>125 Then LED=1 'LED ON WHEN BO>125,OFF WHEN BO<125
GoTo CHECKIT

Jerson
- 3rd May 2006, 07:34
How about doing it this way? Now, every time around the checkit will read the pot and take care of the LED

Jerson



CHECKIT:
Pot GPIO.2,255,BO

IF BO>125 Then
LED=1 'LED ON WHEN BO>125,OFF WHEN BO<125
else
LED = 0
endif
GoTo CHECKIT

Bruce
- 3rd May 2006, 15:26
With the POT command PBP needs to control the I/O-pin. If you have the pin
configured as an A/D input, the POT command can't toggle the pin to charge
the capacitor.

You could use ADCIN with the A/D configured for 8-bit or simply make the pin
digital, then use the POT command.

trying
- 3rd May 2006, 17:45
Jerson that the 1st. way I wrote the code but for some reason it would not compile

Bruce you a little over my head ( newbie) are you saying this is wrong?
TRISIO = %00001100 ' MAKE GPIO.2/.3 INPUTS
ANSEL = %00000100 'MAKE GPIO.2 ANALOG
please explan more
thanks

Bruce
- 3rd May 2006, 18:43
If you are using the POT command, then you do not want to make the pin
an analog input. It needs to be configured for digital I/O.

Change this: ANSEL = %00000100 ' MAKE GPIO.2 ANALOG
To this: ANSEL = %00000000 ' MAKE GPIO.2 (and all other A/D pins) digital.

Why?

Because the POT command requires a pin it can control by flipping it from
output, charging the cap, then flipping it back to an input. If you have the
A/D feature for that pin enabled, then the pin no longer functions as a digital
I/O-pin, and the POT command will fail.

If you prefer not to use the POT command, then you could use the ADCIN
command. In that case you would want to configure the pin as an analog
input with ANSEL = %00000100 ' MAKE GPIO.2 ANALOG

trying
- 3rd May 2006, 19:17
thanks Bruce
I will give it a try, with you and others I'm learning