PDA

View Full Version : Port settings - 18F4620



Scampy
- 18th November 2015, 21:58
Guy's I'm a bit rusty, can someone confirm that the following settings turns off all analogue settings and makes port A digital



;----[Analog Settings]----------------------------------------------------------
INCLUDE "alldigital.pbp" ' make all pins digital

;----[Port settings]------------------------------------------------------------

TRISA = %11000111
TRISB = %00000000
TRISD = %00000001
CMCON = 7 ' disable Comparators
ADCON1 = $0F ' %0000 1111 AN2=VSS, AN3=VDD, AN12-0 = Digital
ADCON2 = $00 ' %0000 0000


Should ADCON1 be set to $00 ? or does the all digital.php override these settings ?

I want to use PORTA.0, PORTA.1 and PORTA.2 as digital inputs from switches -

HenrikOlsson
- 19th November 2015, 06:38
Hi,

CMCON = 7 is correct for the 18F4620 but it's also the POR default so it's not REALLY needed.
ADCON1 = 15 is correct if all pins should be digital, if you set it to 0 all 12 inputs will be analog.
ADCON2 doesn't really matter since the ADC is off anyway.

I've never used Darrels AllDigital but remember that when you INCLUDE a file like that the content of the file will be put in at that very spot - just as if it was actually typed in right there. Since you include it first and THEN set CMCON etc manually YOU will overwrite whatever it is IT does to the relevant registers. Had YOU set the registers first and THEN included AllDigital IT would overwrite anything you've set manually - in the register it believes are important only of course.

/Henrik.

Scampy
- 19th November 2015, 23:11
Thanks Henrik,

I think that I'll remove any manual settings and add the AllDigital include file at the start of all my project that have no analogue requirements - makes things simple

HenrikOlsson
- 20th November 2015, 06:17
You can do that - as long as the chip is "supported" by AllDigital. How do you know if a certain chip is supported? I don't know, you'd need to read the code for AllDigital and compare it to the datasheet for the device - which kind of defeats the purpose of AllDigital.

I guess any chip released prior to AllDigital will be handled and possibly a lot of later chips as well but don't take anything for granted.

Or you can do it manually and learn something in the process - perhaps you get so good at it that you can maintain AllDigital and keep it up to date.

/Henrik.