PDA

View Full Version : 18F25K22 Help



ERMEGM
- 21st November 2014, 18:23
Hello All,

OK, I've been on here for hours trying to research the information, but can't find exactly what I'm looking for. Even exhausted my efforts on Google, the manual and Datasheet (for what I could interpret).

I want to make all my ports digital. I have tried the adcon1 = 15 and even Darrell's alldigital.php. It doesn't work correctly. I am trying to implement some simple code, but it doesn't behave properly. What am I doing wrong?



;----[18F25K22 Hardware Configuration]------------------------------------------
#IF __PROCESSOR__ = "18F25K22"
#DEFINE MCU_FOUND 1
#CONFIG
CONFIG FOSC = INTIO67 ; Internal oscillator block
CONFIG PLLCFG = OFF ; Oscillator used directly
CONFIG PRICLKEN = OFF ; Primary clock can be disabled by software
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Oscillator Switchover mode disabled
CONFIG PWRTEN = OFF ; Power up timer disabled
CONFIG BOREN = SBORDIS ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
CONFIG BORV = 190 ; VBOR set to 1.90 V nominal
CONFIG WDTEN = ON ; WDT is always enabled. SWDTEN bit has no effect
CONFIG WDTPS = 32768 ; 1:32768
CONFIG CCP2MX = PORTC1 ; CCP2 input/output is multiplexed with RC1
CONFIG PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset
CONFIG CCP3MX = PORTB5 ; P3A/CCP3 input/output is multiplexed with RB5
CONFIG HFOFST = ON ; HFINTOSC output and ready status are not delayed by the oscillator stable status
CONFIG T3CMX = PORTC0 ; T3CKI is on RC0
CONFIG P2BMX = PORTB5 ; P2B is on RB5
CONFIG MCLRE = INTMCLR ; RE3 input pin enabled; MCLR disabled
CONFIG STVREN = ON ; Stack full/underflow will cause Reset
CONFIG LVP = OFF ; Single-Supply ICSP disabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
CONFIG DEBUG = OFF ; Disabled
CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected
CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected
CONFIG CP2 = OFF ; Block 2 (004000-005FFFh) not code-protected
CONFIG CP3 = OFF ; Block 3 (006000-007FFFh) not code-protected
CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected
CONFIG CPD = OFF ; Data EEPROM not code-protected
CONFIG WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected
CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected
CONFIG WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected
CONFIG WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected
CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
CONFIG WRTB = OFF ; Boot Block (000000-0007FFh) not write-protected
CONFIG WRTD = OFF ; Data EEPROM not write-protected
CONFIG EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
CONFIG EBTR2 = OFF ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
CONFIG EBTR3 = OFF ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
CONFIG EBTRB = OFF ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
#ENDCONFIG

#ENDIF

;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF

' -----[ Initialization ]-------------------------------------------------------

Reset:

OSCCON = %01010000 ' 4MHz
ADCON1 = 15 ' set to digital outputs
TRISA = %00000000 ' sets pin as input (1) or output (0)
TRISB = %00000001 ' sets pin as input (1) or output (0)
TRISC = %10001100 ' sets pin as input (1) or output (0)
PORTA = %00000000 ' sets outputs as high (1) or low (0)
PORTB = %00000000 ' sets outputs as high (1) or low (0)
PORTC = %00000000 ' sets outputs as high (1) or low (0)

' -----[ Variables ]------------------------------------------------------------

led1 var porta.1 ' LED 1
led2 var porta.2 ' LED 2
led3 var portb.1 ' LED 3
led4 var portb.2 ' LED 4

action:

led1 = 1
pause 500

led2 = 1
pause 500

led3 = 1
pause 500

led4 = 1
pause 5000



This code should sequence on in half second intervals and stay on at the end. I had more code, but what was happening was it was sequencing on and then resetting after the sequence. I've tried putting code that made it hold in a loop, but when the LED's sequence on and it reaches the 5 second mark, the whole thing resets.

Also, when the code goes from LED1 to LED2, LED1 turns off. The rest stay on, but LED1 always turns off.

Any thoughts? I've spent over 6 hours trying to figure this out.

Thanks,
Tony

richard
- 21st November 2014, 21:26
since you have
CONFIG PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset




;Reset: probably not a good name for a label
startup:

OSCCON = %01010000 ' 4MHz
;ADCON1 = 15 what ?
ansela=0

;TRISB = %00000001 ' sets pin as input (1) or output (0) ???????????????
; TRISC = %10001100 ' sets pin as input (1) or output (0) ? for what reason
TRISB = %11111100
TRISA = %11111100

PORTA =0
PORTB =0 ' sets outputs as high (1) or low (0)
PORTC = %00000000 ' sets outputs as high (1) or low (0) why ?


' -----[ Variables ]------------------------------------------------------------

led1 var porta.1 ' LED 1
led2 var porta.2 ' LED 2
led3 var portb.1 ' LED 3
led4 var portb.2 ' LED 4

action:

led1 = 1
pause 500

led2 = 1
pause 500

led3 = 1
pause 500

led4 = 1
pause 5000

while 1 ; loop forever

richard
- 21st November 2014, 22:04
just noticed the wend fell off


while 1 ; loop forever
wend

ERMEGM
- 21st November 2014, 22:46
The settings are the way they are because that code is from a much larger piece of code. I am utilizing 23 I/O pins, so those are the settings for those pins.

Since the larger portion of code was not working, I dumbed it down to see where my problem was. It's a lot easier for me to diagnose this way. I just can't figure out why it resets itself after the last command. I even put a loop at the end which would only exit after a button was pressed. It would hold there for one time and then after the button was pressed once, it would run through the sequencing and reset as stated earlier without holding in the hold loop.

richard
- 21st November 2014, 23:37
an erased chip is all nop's
a program not in a closed loop will execute all the remaining nop's till it hits the end of pgm memory, it then wraps back to location 0000 ie looks like a reset

adcon1=15 is an invalid setting and may cause issues

I had assumed the leds were on b0,b1, a0,a1 my mistake in the tris settings

ERMEGM
- 22nd November 2014, 04:09
Actually, I tried multiple settings. I searched throughout this site and even found one instance where Darrel suggested adcon1 = 15, so I tried that. After my post, I changed it to:


ADCON1 = %00001110 ' set to digital outputs

The end code I had after the last LED pause was:


while program = 1

pause 100

wend

relay1 = 0
relay2 = 0
relay3 = 0
relay4 = 0

led1 = 0
led2 = 0
led3 = 0
led4 = 0

goto action

As stated, when the program is initially run, the program waits until the button was pressed. Once pressed, it then runs through the sequence continuously, never stopping at the while loop.

Now, I did put in the necessary variable at the top of the code so it would acknowledge the button and when it would be pressed, I'm just out of ideas. Anybody have any?

Thanks,
Tony

Demon
- 22nd November 2014, 04:13
Simplify, blink one LED on/off.

Robert


Edit: I had posted code for this pic but can't find it (on cell phone).

richard
- 22nd November 2014, 04:49
that snippet shows no possible way to exit the while loop . how CAN THE PROGRAM VAR EVER CHANGE ???

ADCON1 = %00001110 ' set to digital outputs IS STILL WRONG read the data sheet adcon1 has no effect on setting inputs to digital at all

post the whole test code

ERMEGM
- 22nd November 2014, 20:49
;----[18F25K22 Hardware Configuration]------------------------------------------
#IF __PROCESSOR__ = "18F25K22"
#DEFINE MCU_FOUND 1
#CONFIG
CONFIG FOSC = INTIO67 ; Internal oscillator block
CONFIG PLLCFG = OFF ; Oscillator used directly
CONFIG PRICLKEN = ON ; Primary clock can be disabled by software
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Oscillator Switchover mode disabled
CONFIG PWRTEN = OFF ; Power up timer disabled
CONFIG BOREN = SBORDIS ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
CONFIG BORV = 190 ; VBOR set to 1.90 V nominal
CONFIG WDTEN = ON ; WDT is always enabled. SWDTEN bit has no effect
CONFIG WDTPS = 32768 ; 1:32768
CONFIG CCP2MX = PORTC1 ; CCP2 input/output is multiplexed with RC1
CONFIG PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset
CONFIG CCP3MX = PORTB5 ; P3A/CCP3 input/output is multiplexed with RB5
CONFIG HFOFST = ON ; HFINTOSC output and ready status are not delayed by the oscillator stable status
CONFIG T3CMX = PORTC0 ; T3CKI is on RC0
CONFIG P2BMX = PORTB5 ; P2B is on RB5
CONFIG MCLRE = INTMCLR ; RE3 input pin enabled; MCLR disabled
CONFIG STVREN = ON ; Stack full/underflow will cause Reset
CONFIG LVP = OFF ; Single-Supply ICSP disabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
CONFIG DEBUG = OFF ; Disabled
CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected
CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected
CONFIG CP2 = OFF ; Block 2 (004000-005FFFh) not code-protected
CONFIG CP3 = OFF ; Block 3 (006000-007FFFh) not code-protected
CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected
CONFIG CPD = OFF ; Data EEPROM not code-protected
CONFIG WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected
CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected
CONFIG WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected
CONFIG WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected
CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
CONFIG WRTB = OFF ; Boot Block (000000-0007FFh) not write-protected
CONFIG WRTD = OFF ; Data EEPROM not write-protected
CONFIG EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
CONFIG EBTR2 = OFF ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
CONFIG EBTR3 = OFF ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
CONFIG EBTRB = OFF ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
#ENDCONFIG

#ENDIF

;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF

' -----[ Initialization ]-------------------------------------------------------

Reset:

OSCCON = %01010000 ' 4MHz
ADCON1 = %00001110 ' set to digital outputs
TRISA = %00000000 ' sets pin as input (1) or output (0)
TRISB = %00000001 ' sets pin as input (1) or output (0)
TRISC = %10001100 ' sets pin as input (1) or output (0)
PORTA = %00000000 ' sets outputs as high (1) or low (0)
PORTB = %00000000 ' sets outputs as high (1) or low (0)
PORTC = %00000000 ' sets outputs as high (1) or low (0)

' -----[ Variables ]------------------------------------------------------------

led1 var porta.1 ' LED 1
led2 var porta.2 ' LED 2
led3 var portb.1 ' LED 3
led4 var portb.2 ' LED 4

program var porta.0 ' button to restart sequence

action:

led1 = 1
pause 500

led2 = 1
pause 500

led3 = 1
pause 500

led4 = 1
pause 500

while program = 1 ' loop here until the button is pressed

pause 100

wend

led1 = 0
led2 = 0
led3 = 0
led4 = 0

goto action

The current code is written as such: Turn on each LED in sequence and leave them on until the button is pressed. It is a pull down input. When the button is pressed, turn off all the LEDs and repeat the sequence.

Right now, LED1 turns on and then when LED2 goes to turn on, LED1 turns off. LEDs 2-4 sequence on and stay on, but LED1 stays off. On the first run, the LEDs turn on and stay on until the button is pressed. After the initial press, the LEDs turn on in sequence (except for LED1) and once LED4 is lit, they all turn off and the sequence in repeated.

Can't figure it out unless it's because of my pins not all being set to digital. I'm asking for help on what the proper code is for setting them all to digital. I keep finding posts where people say read the datasheet. I've read the datasheet and I've entered what I think it is telling me for how to set the pins to all digital. I'm now asking for help.

richard
- 22nd November 2014, 21:46
GOOGLE "PIC READ MODIFY WRITE"



;----[18F25K22 Hardware Configuration]------------------------------------------
#IF __PROCESSOR__ = "18F25K22"
#DEFINE MCU_FOUND 1
#CONFIG
CONFIG FOSC = INTIO67 ; Internal oscillator block
CONFIG PLLCFG = OFF ; Oscillator used directly
CONFIG PRICLKEN = ON ; Primary clock can be disabled by software
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Oscillator Switchover mode disabled
CONFIG PWRTEN = OFF ; Power up timer disabled
CONFIG BOREN = SBORDIS ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
CONFIG BORV = 190 ; VBOR set to 1.90 V nominal
CONFIG WDTEN = ON ; WDT is always enabled. SWDTEN bit has no effect
CONFIG WDTPS = 32768 ; 1:32768
CONFIG CCP2MX = PORTC1 ; CCP2 input/output is multiplexed with RC1
CONFIG PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset
CONFIG CCP3MX = PORTB5 ; P3A/CCP3 input/output is multiplexed with RB5
CONFIG HFOFST = ON ; HFINTOSC output and ready status are not delayed by the oscillator stable status
CONFIG T3CMX = PORTC0 ; T3CKI is on RC0
CONFIG P2BMX = PORTB5 ; P2B is on RB5
CONFIG MCLRE = INTMCLR ; RE3 input pin enabled; MCLR disabled
CONFIG STVREN = ON ; Stack full/underflow will cause Reset
CONFIG LVP = OFF ; Single-Supply ICSP disabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
CONFIG DEBUG = OFF ; Disabled
CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected
CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected
CONFIG CP2 = OFF ; Block 2 (004000-005FFFh) not code-protected
CONFIG CP3 = OFF ; Block 3 (006000-007FFFh) not code-protected
CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected
CONFIG CPD = OFF ; Data EEPROM not code-protected
CONFIG WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected
CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected
CONFIG WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected
CONFIG WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected
CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
CONFIG WRTB = OFF ; Boot Block (000000-0007FFh) not write-protected
CONFIG WRTD = OFF ; Data EEPROM not write-protected
CONFIG EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
CONFIG EBTR2 = OFF ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
CONFIG EBTR3 = OFF ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
CONFIG EBTRB = OFF ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
#ENDCONFIG

#ENDIF

;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF

' -----[ Initialization ]-------------------------------------------------------

Reset:

OSCCON = %01010000 ' 4MHz
ADCON1 = %00001110 ' set to digital outputs this is totally wrong
TRISA = %00000000 ' sets pin as input (1) or output (0)
TRISB = %00000001 ' sets pin as input (1) or output (0)
TRISC = %10001100 ' sets pin as input (1) or output (0)
PORTA = %00000000 ' sets outputs as high (1) or low (0)
PORTB = %00000000 ' sets outputs as high (1) or low (0)
PORTC = %00000000 ' sets outputs as high (1) or low (0)
ANSELA=0 WILL SET PORTA DIGITAL
ANSELB=0 WILL SET PORTB DIGITAL



' -----[ Variables ]------------------------------------------------------------

led1 var porta.1 ' LED 1 JUST ASKING FOR READ MODIFY WRITE ISSUES
led2 var porta.2 ' LED 2
led3 var portb.1 ' LED 3
led4 var portb.2 ' LED 4


led1 var LATA.1 ' LED 1 CAN ELIMINATE READ MODIFY WRITE ISSUES
led2 var LATA.2 ' LED 2
led3 var LATB.1 ' LED 3
led4 var LATB.2 ' LED 4
program var porta.0 ' button to restart sequence

action:

led1 = 1
pause 500

led2 = 1
pause 500

led3 = 1
pause 500

led4 = 1
pause 500

while program = 1 ' loop here until the button is pressed

pause 100

wend

led1 = 0
led2 = 0
led3 = 0
led4 = 0

goto action

andybarrett1
- 22nd November 2014, 21:53
Hi

Aside from the analog port issues..... If you want the LED's to sequence, you need to put them low at some point otherwise they all going to be mostly high all the time ?

Maybe as others far wiser than me will suggest (Robert)..... get the code to turn one LED on and off (Flash)
Move this simple code around the ports.. Then once you know this is working OK... Progress on further.

flash: ledx high
pause 500
ledx low
pause 500
goto flash

BR
Andy

Demon
- 23rd November 2014, 04:13
What Andy proposed (1 LED) and Richard (RMW).

Also, put AllDigital back in and doublecheck the code generated.

Robert

ERMEGM
- 25th November 2014, 06:31
I would like to thank all those who helped looking over the code. The commands I chose were those that I found on this forum, but did not work. So, with that said, I would like to post what I did that got my program working again.

First off, ADCON1 = whatever. Don't use it. It'll just screw things up. Second, I did not have any success with Darrel's AllDigital include. Not saying it doesn't work, it just didn't work for me.

What did get it working again was using ANSELA = 0, ANSELB = 0 and ANSELC = 0. I used ANSEL for setting each register to digital, TRIS for selecting input/output and then PORT for setting the outputs to high or low. This was the first step in setting up my code. Then, you have to change your output variables from port to lat. For instance, my LED variable of LED1 var porta.1 needed to be changed to LED1 var lata.1. You can Google it like it was suggested above, but I found I understood it better when viewing a youtube video of the explanation along with circuit and oscilloscope examples. Just remember, only the outputs get changed from port to lat. Leave the inputs as portx, but change the outputs to latx.

Thanks again to all those that helped and I hope my explanation will help those in the future.

Tony

Archangel
- 25th November 2014, 06:55
ANSELx = ANALOG SELECT or inversely Digital Select . . .
ADCON0 is where you choose which Analog Channel to use
ADCON1 is where you CHOOSE what your voltage references are & Trigger Select

ANSELA configures portA Analog or Digital
ANSELB configures portB Analog or Digital
ANSELC " " " " " portC Analog or Digital
ANSELD " " " " " portD Analog or Digital
ANSELE " " " " " portE Analog or Digital

All about COMPARATORS Below from Data Sheet


TABLE 18-2: REGISTERS ASSOCIATED WITH COMPARATOR MODULE
Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Register on Page
ANSELA — — ANSA5 — ANSA3 ANSA2 ANSA1 ANSA0 154
ANSELB — — ANSB5 ANSB4 ANSB3 ANSB2 ANSB1 ANSB0 155
CM2CON1 MC1OUT MC2OUT C1RSEL C2RSEL C1HYS C2HYS C1SYNC C2SYNC 318
CM1CON0 C1ON C1OUT C1OE C1POL C1SP C1R C1CH<1:0> 317
CM2CON0 C2ON C2OUT C2OE C2POL C2SP C2R C2CH<1:0> 317
VREFCON1 DACEN DACLPS DACOE — DACPSS<1:0> — DACNSS 347
VREFCON2 — — — DACR<4:0> 348
VREFCON0 FVREN FVRST FVRS<1:0> — — — — 344
INTCON GIE/GIEH PEIE/GIEL TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF 116
IPR2 OSCFIP C1IP C2IP EEIP BCL1IP HLVDIP TMR3IP CCP2IP 129
PIE2 OSCFIE C1IE C2IE EEIE BCL1IE HLVDIE TMR3IE CCP2IE 125
PIR2 OSCFIF C1IF C2IF EEIF BCL1IF HLVDIF TMR3IF CCP2IF 120
PMD2 — — — — CTMUMD CMP2MD CMP1MD ADCMD 57
TRISA TRISA7 TRISA6 TRISA5 TRISA4 TRISA3 TRISA2 TRISA1 TRISA0 156
TRISB TRISB7 TRISB6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0 156


Comparators are really good at causing you to tear out your hair while trying to get the PIC to do digital too.
Sorry this post comes too late to help you, I bet you won't forget though. Keep up the good work Tony.
JS

richard
- 25th November 2014, 07:19
just for the record what version of alldigital.pbp did you try ? there are a number of versions



First off, ADCON1 = whatever. Don't use it. It'll just screw things up.

is not right ,it just does not do what you erroneously thought it did as archangel says
ADCON1 is where you CHOOSE what your voltage references are & Trigger Select

and needs to set appropriately " rtfm "

Archangel
- 25th November 2014, 07:31
Richard,
Problem is; None of this is in the manual, it's in the data sheet, and it takes some of us a while before we understand how to read it, and when we get frustrated, it's just harder. That's why I explained it the way I did, because Acronyms are always obvious . . . to the person who makes them. The rest of us, maybe not so much.

richard
- 25th November 2014, 09:25
as tony discovered the wrong info in a thread can lead you astray , I don't think perpetuating error helps anyone but the right info is priceless

HenrikOlsson
- 25th November 2014, 10:36
Hi,
Here's my view on this....
This sort of info can't be in the manual because then the manual would be the size of all the 8bit PIC datasheets combined.


It's up to the user to set the registers correctly for the application at hand, HOW to set them IS described in the manual, WHAT to set the TO is described in the datasheet for the particular PIC. Yes, it does take some time to learn what to look for in a datasheet but you're going to have to learn it.


The commands I chose were those that I found on this forum, but did not work.
Just because you find a piece of code where you see some_register = some_value ' Enable this, do that doesn't mean it'll work for you and your PIC. Take CMCOM for example, it's not uncommon that someone finds a piece of code, on this forum, where it says CMCON=7 ' Turn off comparators, uses that on a completely different PIC than the one for which the code was written and ultimately ends up in trouble. All because the comment said Turn off comparators - which it of course does on the PIC for which it was written. On some chips the registers are named differently, on others you need CMCON=15, on others you don't need to anything.

Where exactly did you find the reference to ADCON1=15?

Finally, just because you find pieces of code an a forum doesn't mean it's correct, working, debugged code ready to go. Most of the code posted here contains errors and problems - which is usually the reason for it being posted in the first place even though you're sometimes asked to troubleshoot code without even seeing it.



/Henrik.