PDA

View Full Version : POT command and Scale factors



fanman
- 17th May 2011, 12:26
Hi Guys,

I'm a newbie. I am having trouble using the "POT" command with my 12F675. It simply doesn't work on any port (neither does RCTIME). I have had success using ADCIN using a voltage divider which worked fine but not POT or RCTIME? Why?

Next question, I have a variable that I want to scale from say 50% up to 105%. How can I do this in code? When I try to multiply or divide large numbers from the ADCIN (say 1023) the result is usually 1 or 0 and nothing in between. I'm guessing its a bit limitation thing. Please help. Thanks.

P.S... I'm using an external XT as I stuffed up the internal calibration value.

mackrackit
- 17th May 2011, 14:46
Do you have the hardware connected as the manual shows in the POT command section?

fanman
- 17th May 2011, 23:05
Do you have the hardware connected as the manual shows in the POT command section?

yep tried it and still not working. Any hints?

RDavid60
- 18th May 2011, 04:57
Fanman:

I can't help you with the POT and or RCTIME command, but I can help you recover the internal oscillator calibration value.

The attached file 5516 is a small PBP program to load into your 12F629 and or 12F675.

The attached file 5517 is a word doc showing how to recover your OSCAL value.

Hope this helps,
Ron

HenrikOlsson
- 18th May 2011, 06:37
Hi,
If ADCIN works on the same pins you're trying to use for POT and/or RCTIME then my guess is that when trying POT/RCTIME you're forgetting to switch the pins from analog to digital inputs. POT/RCTIME both need the pin to be in "digital mode" and they default to analog on startup.


ANSEL = 0 'Turn off ADC functionallity on all analog pins
CMCON = 7 'Turn off comparator functionallity.

When scaling values you need to make sure that the result of the calculation fits in the variable to which you assign it. As you know, a value of 1023 won't fit in a BYTE variable, you need a WORD. The result of multiplying 1023 by anything above 0.25 won't fit in a BYTE either so the result variable must be WORD as well.

Scaling 50 to 105 is the same as multiplying by 2.1, PBP doesn't do floating point, ie you can't program Result = ADCValue * 2.1 but you can do something like:

Result VAR WORD 'Must use a 16bit variable here
Result = ADCValue * 21 'Result is now 0-21483
Result = Result / 10 'Result is now 0-2048

/Henrik.

mister_e
- 18th May 2011, 23:09
It's amazing how many of my post get deleted suddenly...

However, Henrik's spot-on!

fanman
- 19th May 2011, 00:08
Hi guys,

Thanks that helped. I decided to use the ACDIN to read the pot value and then scale as you recommended.

By the way, does using the ACDIN command slow things down much? I'm using it to control a gain control to trigger a strobe (LED).

cheers

mark

mister_e
- 19th May 2011, 00:15
To read analog, you really want to use ADCIN (or manually set/read the PIC registers) anyway.

Nope it shouldn't slow things up.