1. ## ADC resolution for 16F616

I'm using a 16F616 analog input with a ADCIN routine. My resolution is 5V / 256 = about .19 mv. I'm using a voltage divider for the input with .1% tolerance resistors. Is there a better way to improve my accuracy? It seems that my code is not reacting to .19mv steps, more like 100 or 200 mv at best. I tried 10 bit resolution but never got that to work - pretty sure my code was wrong.

Last edited by pescador; - 26th April 2018 at 01:51.

2. ## Re: ADC resolution for 16F616

Note: - I'm not doing anything as far as CCP1CON, CM1CON0,CM2CON0, CM2CON1, ADCON1.

Yes I'm new...

3. ## Re: ADC resolution for 16F616

I've been reading other posts - so I tried this to see if light would turn green - fail

OUTPUT PORTA.1 ' FAULT LED
OUTPUT PORTA.0 ' TIMING LED

adval var word ' holds analog value
GREEN VAR PORTA.0 ' TIMING LED
RED VAR PORTA.1 ' FAULT LED

low green
low red

main:

high green
endif

goto main

4. ## Re: ADC resolution for 16F616

Its working - but crazy numbers now - 32k instead of 1024 uggg...

5. ## Re: ADC resolution for 16F616

I dont know what I'm doing.. I dont know what to set ADCON1 to.

6. ## Re: ADC resolution for 16F616

I'm using Analog port 2 on 16F616 - 4Mhz.. VDD as reference. Any help would be great. I didn't have to set the ADCON registers for 8 bit. Why is 10 bit different? Was I lucky?

7. ## Re: ADC resolution for 16F616

Next, look at Section 4, starting on page 33 of the Data Sheet. It covers I/O Ports. Register 4-1 is your PORTA Register; 1 = HIGH, 0 = LOW. Next is your TRISA Register, which stands for TRIState. Bits 7-6 are shaded grey as this PIC only has PORTA <5:0>, there is no PORTA.6 or 7. Next, if the bit is clear (0) the port is configured as an Output. If the bit is set (1) it is configured as an input. An easy way to remember this is a number 1 looks like the letter I for Input. The number 0 looks like the letter O for Output. Register 4-3 is your ANSELA Register, which is used to denote Input ports as Analog Inputs. A "1" makes it analog. You must configure the port as an Input in the TRISA Register for the ANSELA Register to work. Setting an ANSELA bit on a pin set up as an output in the TRISA Register can cause unpredictable results (on some PICs it causes a current overload). And now for one that I think may be causing you issues, the WPUA Register (Register 4-4 on page 35). Remember the number above the Bit in the Register denotes the default value. The Weak Pull Up Enable is defaulted to ON. Unless you turn it off with the WPUA Register, it could be causing you...well, what you described. "WPUA = 0" is a quick fix.

Take a weekend to read through the Data Sheet. It's a lot to absorb, but your answers are always in there. Although I've never worked with the PIC16F616, it looks like a pretty good one. I hope this helps.

8. ## Re: ADC resolution for 16F616

I've read the docs about 25 times, but sometimes this 65 year old brain is a bit slow.

Now - I didn't start w page 73 on this topic, I started with 74. If I would have slowed down and read pg 73 I might have understood better. So - again thanks for taking the time to explain. I actually got it to work by "massaging the ADCON0 register but need to read your reply again and figure out why it worked.

Would you be willing to write code for me? - for a price of course.. email kovenllc@gmail.com - my name is Rich. I could use a good programmer for my side business. (hope this is ok to post)
Last edited by pescador; - 26th April 2018 at 13:45.

9. ## Re: ADC resolution for 16F616

My ADCON0 register looks like this 10010011. Now I have to figure out why it worked.

starting from left

1 = Right justified, needed for 10 bit
0 = reference is VDD
0010 = using AN2
1 = not sure..

INPUT PORTA.2
ANSEL - PORTA.2
WPUA = ?
Last edited by pescador; - 26th April 2018 at 14:02.

10. ## Re: ADC resolution for 16F616

With PBP3 you won't need to even list ADCON0 unless you change your resolution. PBP3 has to address the ADCON0 Register to select the appropriate AD Channel, and the Justify Bit. Try not listing ADCON0 or ADCON1 at all and see if it still works.

11. ## Re: ADC resolution for 16F616

Everything you need to setup the registers is really in the pdf of your chip. Please be careful selecting new chips as Microchip may issue a Preliminary pdf file having a lot of errors. Also keep your eye on the errata files that Microchip publishes on the chip's page.

Most chips have 8 or 10 bits at the low end 8-bit chips. If you can spare some time on your chip and your application, then you may use the Oversampling routine published here: http://dt.picbasic.co.uk/CODEX/AnalogueOverSampling

You may reach 16-bits results given you will sacrifice 50-100ms, depending on the chip. I thing 12 or 14 bits are good enough with maximum 6.2ms delay in your program (less if you have a fast MCU).

With the routine mentioned, you do not need to filter your results for noise or invalid sampling.

Ioannis

You do not have permission to view the list of names.