POT command and Scale factors
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.
Re: POT command and Scale factors
Do you have the hardware connected as the manual shows in the POT command section?
Re: POT command and Scale factors
Quote:
Originally Posted by
mackrackit
Do you have the hardware connected as the manual shows in the POT command section?
yep tried it and still not working. Any hints?
2 Attachment(s)
Re: POT command and Scale factors
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 Attachment 5516 is a small PBP program to load into your 12F629 and or 12F675.
The attached file Attachment 5517 is a word doc showing how to recover your OSCAL value.
Hope this helps,
Ron
Re: POT command and Scale factors
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.
Code:
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:
Code:
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.
Re: POT command and Scale factors
It's amazing how many of my post get deleted suddenly...
However, Henrik's spot-on!
Re: POT command and Scale factors
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
Re: POT command and Scale factors
To read analog, you really want to use ADCIN (or manually set/read the PIC registers) anyway.
Nope it shouldn't slow things up.