PDA

View Full Version : pot command



lerameur
- 24th November 2006, 03:41
Hi,

Little problem trying to switch POrt on my pot command.
I am geting good result using the default port . The port command only goes to port B. I want to use portA, so I would like to use this command but it do not work: PortA.02,175,B0

The follwoing is my working code:

B0 var byte
Start:
Pot 2,175,B0 ' would like PortA.2,175,B0
Lcdout $fe, 1 'Clear screen
Lcdout "Pot: ", Dec B0 'Display the decimal value
Pause 300

k

mister_e
- 24th November 2006, 03:51
Once again, we can't guess wich PIC you're using so try one or all of the following lines

CMCON=7
ADCON1=7
ADCON1=$0F
ANSEL=0
ANSELH=0

if any of ADCON or ANSEL setting work... you may discover something interesting and NEVER EVER use POT command :D

lerameur
- 24th November 2006, 03:59
sorry pic16F88

mister_e
- 24th November 2006, 04:07
Now you have to forget POT but use ADCIN instead. Just your POT on your PORTA, no capacitor in serie.

Your PIC have ADCs AND analog comparator on PORTA... it's useless to use POT.

Datasheet section 12.0 and 13.0.

You need to disable the comparator first.. something is right in my previous thread about that.

lerameur
- 24th November 2006, 04:09
well the adcon1 I used before doing some A/d conversion.
I also tried setting the port to output using the Tris command. NOthing works.
Also, I guess when you say I donthave to use the Pot command you are refering to making A/D conversion ??

k

mister_e
- 24th November 2006, 04:12
Probably you have disable the ADCs but not the comparator? Both have to be disable.

And yes i'm talking about doing a A/D conversion... that's already built-in, free and far better than POT

lerameur
- 24th November 2006, 04:30
by just using a pot on that pin, wont I have to use a voltage divider. If I just put a pot, then it will the same voltage and the convertion will be the same.
Right now with this I am getting weird characters on the lcd.
I did not touch portB..
To disable I guess by using the ADCON1 = 0 it is disable (bit 2 and 3)

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
B0 var byte
Start:
TRISA = 3 ' Set PORTA to all input
ADCON1 = 0 ' PORTA is analog
ADCIN 0, B0 ' Read channel 0 to B0

Lcdout $fe, 1 'Clear screen
Lcdout "Pot: ", Dec B0 'Display the decimal value
Pause 300

lerameur
- 24th November 2006, 04:35
TRISA = 3 and ADCON1 should be out of the loop...

Archangel
- 24th November 2006, 05:17
Once again, we can't guess wich PIC you're using so try one or all of the following lines

<h4>CMCON=7</h4>
<h4>ADCON1=7</h4>
ADCON1=$0F
<h4>ANSEL=0</h4>
ANSELH=0

if any of ADCON or ANSEL setting work... you may discover something interesting and NEVER EVER use POT command :D
Hi Lerameur,
I think we gave mister_e a headache tonight, The data sheet chap. 5, 12, 13 makes mention of these. Get it here if you do not have.
Cheers
JS
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en010243

lerameur
- 24th November 2006, 05:23
yes I am printing them out and carefully reading them now.
But, i am curious, if I wanted to use the POT command, what do i have to do to read from port A?

k

Archangel
- 24th November 2006, 07:09
yes I am printing them out and carefully reading them now.
But, i am curious, if I wanted to use the POT command, what do i have to do to read from port A?

k
lerameur,
without actually doing it to verify it works . . .as I do not have a 16F88
put the three BOLD commands into your code to make the PortA pins digital and turn off the analog comparators


CMCON=7 ' Disable comparators
ANSEL=0 ' Set port as digital I/O
ADCON1=7
TrisA = %11111111 'sets all port a as input
TrisB = %00000000 ' sets all port b as output
B0 var byte ' establishes a variable called B
Start:
Pot PortA.2,255,B0 ' would like PortA.2,175,B0 use number to suit you
Lcdout $fe, 1 'Clear screen
Lcdout $FE,$80,"Pot: ", #B0 'Display the numerical value
Pause 300
goto start
end

This should work.
JS

peterdeco1
- 24th November 2006, 11:43
Hi Lerameur. I have an 'F88 and this program works. The 'F88 has 5 ADC's which are better than using the pot command. I connected pin 17 (ana 0) to the center terminal of a 1 meg pot. The CCW terminal to ground, CW terminal to B+.

OSCCON = $60 'SET INT OSC TO 4MHZ
ANSEL = 0 'SELECT ANALOG INPUTS 0 = NONE AND ALL DIGITAL
ADCON0 = 0 'AD MODULE OFF & CONSUMES NO CURRENT
CMCON = 7 'COMPARATORS OFF
TRISA = %11111111 'PORTA INPUTS
TRISB = %00000000 'PORTB OUTPUTS
X VAR BYTE 'VARIABLE TO PUT POT VALUE
PORTB = 0 'ALL OUTPUTS LOW

START:
ADCIN 0, X 'READ VALUE ON ANA 0
IF X > 0 AND X <= 50 THEN LED1
IF X > 50 AND X <= 100 THEN LED2
IF X > 100 AND X <= 200 THEN LED3
IF X > 200 THEN LED4
GOTO START

LED1:
HIGH PORTB.0
PAUSE 1000
LOW PORTB.0
GOTO START

LED2:
HIGH PORTB.1
PAUSE 1000
LOW PORTB.1
GOTO START

LED3:
HIGH PORTB.2
PAUSE 1000
LOW PORTB.2
GOTO START

LED4:
HIGH PORTB.3
PAUSE 1000
LOW PORTB.3
GOTO START

lerameur
- 24th November 2006, 12:48
I am going to try this today thanks.
I am following John Iovine,s book, he usesa F84a pic. He always uses the portB by default, I wanted to try using port A , but on a F88.
Also I was reading the command CMCON=7 meaning th three first bit are set to one. When I read the legend it says 1 is for Setting th bit, I would of first thought setting would be for setting for comparator mode.

k

Archangel
- 24th November 2006, 13:02
I am going to try this today thanks.
I am following John Iovine,s book, he usesa F84a pic. He always uses the portB by default, I wanted to try using port A , but on a F88.
Also I was reading the command CMCON=7 meaning th three first bit are set to one. When I read the legend it says 1 is for Setting th bit, I would of first thought setting would be for setting for comparator mode.

kHi Lerameur,
I have his book too, I thought that was where you got that code. He , in my opinion, left too many loose ends in his code as he neglected to put in all the needed little setup routines, like the trisa and trisb etc. he relies on pbp defaults
and that sorta leaves beginners out in the cold, if you do not rely on defaults and write in everything your code will always be usable and only require minor tweaking to port to other PICs
Cheers
JS

lerameur
- 24th November 2006, 13:55
yes thats what I am beginning to realize too , lots of stuff missing in the book, then when you use another chip, I'm screwed.
Abou tthe A/D, doesn't that read a voltage ? whereas the Pot read a resistance ?

lerameur
- 24th November 2006, 15:52
both cde works,
i am trying to figure out one thing now.

I am replacing this command line:
HIGH PORTB.0
PAUSE 1000
LOW PORTB.0

by this one:
serout 2,n9600,(2)

i am getting errors:
C:\PBP\POT_TRY.BAS ERROR Line 39: Bad expression.
C:\PBP\POT_TRY.BAS ERROR Line 33: ID LED2 is not a LABEL.
C:\PBP\POT_TRY.BAS ERROR Line 34: ID LED3 is not a LABEL.
C:\PBP\POT_TRY.BAS ERROR Line 35: ID LED4 is not a LABEL.

suddenly my labels are not labels ??

keithdoxey
- 24th November 2006, 16:00
Sometimes the error messages bear no relation to the actual error.

Try changing serout 2,n9600,(2)

to serout 2,n9600,[2]

lerameur
- 24th November 2006, 16:12
yes thanks,

those french keyboards...

k

mister_e
- 24th November 2006, 17:30
:D yeah i know what you mean. It's always handy to have English(United State) driver installed too. Just need to press Shift+Alt to switch between language

Acetronics2
- 24th November 2006, 17:46
yes thanks,

those french keyboards...

k

Hi,

For once one can say it's the Keyboard's error ...

Mhhhh, have something against French Goose liver, Sauternes, Camembert, Cognac, ... and so on ...

Ahhhh, I see ... that was just a "glitch" ...

Alain

PS: In French, as I've read here, your should be called " Le Ramier " ... and not "Lerameur" ....
LOL !!!!

lerameur
- 24th November 2006, 18:54
wow shift-alt, thats cool.

I am still confused about one part. The default selection from the compiler is great but very specific for me. Lets say you are using the Pic16F877, with port A, B, C,D,
I then use the command serout, IS there a problem using the exact port?
Ex: serout portC.2,N9600,[3]
instead of 2,N9600,[3] . ( by which I know the pin number, but I dont know the port)
For me it looks like its taking a random port, obviously , the one by default...

ken

Archangel
- 24th November 2006, 22:29
wow shift-alt, thats cool.

I am still confused about one part. The default selection from the compiler is great but very specific for me. Lets say you are using the Pic16F877, with port A, B, C,D,
I then use the command serout, IS there a problem using the exact port?
Ex: serout portC.2,N9600,[3]
instead of 2,N9600,[3] . ( by which I know the pin number, but I dont know the port)
For me it looks like its taking a random port, obviously , the one by default...

kenHi Ken,
No it's better to specify PortA or PortB or . . . than just serout 2,N9600. I have only seen serout 2,N9600 used as port B, I think it is a throwback to PBasic and not the pro that still works in Pro,maybe for basic stamps, the PBasic cannot use the Pro sytax which allows you to specify the port. I only use the full name of ports so I do not allow myself to get sloppy, I am not a good enough programmer to ALLOW sloppy, I think generally speaking you can serout on any "I/O" pin which can be made digital, possible exception A.4 or 5 and IT may work with ext. pullup.
Joe

lerameur
- 25th November 2006, 04:12
I was programing in serial and it di dnot work, then I saw another command serout2, decided to use it, and just by adding the 2 it works.. I am only doing one signal, why would this one work and not the other ? using the F88,

serout2 PORTB.2,n9600,[2]

ken