OK, I see that now. So how do I select between the IO pin and the Vref source in code? No idea how that is done...
Still don't see how the resistor - diod junction will provide me with a reading that represents the changing Vbatt...
OK, I see that now. So how do I select between the IO pin and the Vref source in code? No idea how that is done...
Still don't see how the resistor - diod junction will provide me with a reading that represents the changing Vbatt...
Last edited by tekart; - 27th October 2014 at 20:11.
"Do or do not, there is no try" Yoda
I think the confusion between you and pedja089. The first way you need two external pins from the ADC or comparator.
One of the pins is tied to an external vref source and the other is your analog input. There is no voltage reference in the 683
VCFG bit or ADCON0.6 either connects the ADC vref(input) to VDD internally or connects it to and external (pin) reference you provide. .
The second way only one external pin is needed. (pic12F1822) has an internal reference diode which can be configured to be the vref source for the adc or comparator.
Mark, thank you for clarifying. I thought it was something like that but my inexperience with internal voltage references left me confused. I have ordered some F1822 chips to experiment with.
So would you mind clarifying for me how I would go about using the single pin to take advantage of the internal reference diode. Do I understand correctly that this diode would replace the external diode we have been discussing, so all I would need is a pull-up resistor on the ADC pin? I still don't see how that would give me a reading that would very since I would still just be reading the voltage drop of the reference diode. Forgive me for being dense about this but I still don't get it.
"Do or do not, there is no try" Yoda
Your battery positive will be connected thru a 1K resistor to the adc, you may need a divider if v battery is greater than VDD? Then you take a normal acin reading and determine what number between 0 - 1024
equals a low battery. If an < x then low_bat. else..
To start
Fixed voltage reference FVR page 137
ADCIN will take care of the ADCON0 register
FVRCON = %10000001 ' vref enabled 1.024v
ADCON1 = %11110011 'Right just,FRC,+vref connected to FVR
Mark, thanks for the very helpful configuration settings. I got a test chip working fine using 8-bit reads and left justified results. I am in a similar position to peterdeco1 in that I have a circuit board designed for production and ready to go into volume assembly. Fortunately I already had two resistors connected to the A/D input creating a voltage divider so I am good to go - except for one minor problem. My test code works on the F683 chip just fine but when I try to implement it on my actual design I find that I do not have proper digital I/O on PortA.5 for some reason. My design uses portA.0 for the analog input and portA.2 for PWM out. I am struggling with what configuration error I have that is preventing portA.5 from operating as a digital output. I have been poring over the datasheet for an hour or so now and can't seem to find a configuration that seems to be setting that into something other than digital I/O. Any help would be appreciated.
"Do or do not, there is no try" Yoda
These "enhanced" pics don't use the GPIO like the old ones. Use porta.5 to read
and lata.5 to write. See page 13 and page 121 of the data sheet
Add: See Hecklers code and configs
http://www.picbasic.co.uk/forum/show...ght=pic12f1822
Last edited by mark_s; - 30th October 2014 at 20:19.
Wow. Thanks Mark - I missed that. I just HATE all these whiz bang "features" that force us mere mortal coders to spend *days* learning a new chip! Grrrr. <end rant>
SO to implement a pin as output only I use:
GreenLED var lata.1 ' high = light power LED
and also set:
' config
TRISa = %011001 ' set I/O directions (0 = output, 1 = input)
LATa = %011001
- still not getting it to work with above settings. Do I have bit polarity right for LATA?
"Do or do not, there is no try" Yoda
Hi;
The 12f1840 as Internal voltage reference ( Fixed Voltage Reference (FVR) with 1.024V, 2.048V and 4.096V output levels )
Thanks and Regards;
Gadelhas
Thanks guys! Now I completely understand what I need to do and this solution will work extremely well for me. I have ordered some sample chips and will dig into this later in the week. I appreciate your help and patience.
"Do or do not, there is no try" Yoda
Hi Tekart,
Do you have PBP3 ? I believe you will need it to use the 12F1822 or any xxF1xxx part.
Bookmarks