PDA

View Full Version : 18F4550 issue with simple program.



jmgelba
- 11th January 2016, 22:18
I'm having a problem getting a really simple program to run on an 18F4550. It just a couple of blinky LED's to verify the PIC is alive. I can program it fine and read back from the device but cannot get this program to work.

I'm running this on a 20mhz resonator using HS+PLL with PLL/5. MCLR is disabled, low voltage programming disabled. What am I missing?! :)

Define OSC 48
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval var word ' Create adval to store result

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10001111 ' Set PORTA analog and right justify result
TRISB = %00000000
TRISC = %00000000

RCSTA.7 = 0

loop1:
Portc.6 = 1
pause 100
Portc.7 = 1
pause 200
portc.6 = 0
portc.7 = 0
pause 200
goto loop1
End

Scampy
- 12th January 2016, 08:18
deleted after posting

richard
- 12th January 2016, 09:07
you might need another read of the hardware manual for a 18F4550:)


ADCON1 = %10001111 ' Set PORTA analog and right justify result ?????????????


sets all analogue pins digital

you need
ADCON1 = %00001010 'Set PORTA analog
ADCON2.7=1 ' right justify result

ps

where does this bogus line come from
ADCON1 = %10001111 ' Set PORTA analog and right justify result ?????????????
it comes up repeatedly

jmgelba
- 12th January 2016, 16:16
Yes you're right. I hadnt changed the comment but the setting is correct for what I need. Still, It is not running. I've noticed that the code is being loaded into the end of the program space and not the beginning. Is this an issue and how do I resolve it if it is?

I'm using PBP 2.60A, MCS 3.0.0.5 and MPLAB 8.20A

Mike2545
- 12th January 2016, 18:06
Is MCLR tied high?

Scampy
- 12th January 2016, 18:56
Not sure if this helps, but this is a section of code that uses an 18f4580, with four pots on port A




; config settings 18F2550/4550/18F4580, 20mhz crystal
ASM
__CONFIG _CONFIG1H, _OSC_HSPLL_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM

DEFINE OSC 48
ADCON1 = $0F
clear


DEFINE ADC_BITS 10 ' Set-up ADC for fastest 10-bit results
DEFINE ADC_CLOCK 2
DEFINE ADC_SAMPLEUS 5
INCLUDE "DT_Analog.pbp"

MaxSetPoint CON 500 ' Pot fully clockwise - gives max setting 50 degrees
MinSetPoint CON 100 ' Pot fully counter clockwise - sets min setting 10 degrees
ADbits = 14 ' set A/D resolution to 14-bits
CMCON = 7 ' disable Comparators
ADCON1 = %00001011 ' sets up Analogue pins
ADCON2.7 = 1 ' ADFM bit isn't in ADCON1 anymore

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

TRISA = %11001111




It uses DT's analogue include file, which might be worth downloading and including in your own code

jmgelba
- 12th January 2016, 20:37
Is MCLR tied high?

No. Does the PicKit 3 programmer hold it high or low when powering the target board?

I do have it disabled in the config bits.

Mike2545
- 12th January 2016, 21:04
Not sure what the Pickit3 does, I know the MCLR pin needs to be held high (~10K resistor) to run the processor...give that a try

jmgelba
- 13th January 2016, 16:34
Turns out this was a MPASM issue. Once I had that resolved the program worked.

jmgelba
- 19th January 2016, 18:28
I cant seem to get some of the ADC readings to write to EEPROM. Channels 0 and 1 work perfectly the others write anything. Any idea whats going on? I think all the ports are set correctly.

Define OSC 48
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

adval var word ' Create adval to store result
adval1 var word
adval2 var word ' Create adval to store result
adval3 var word
adval4 var word ' Create adval to store result
adval5 var word

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000000 ' Set PORTA analog and right justify result
ADCON2.7=1
TRISB = %00011111
TRISC = %00000000
TRISE = %00001111
RCSTA.7 = 0


loop1:
ADCIN 0, adval
pause 1
write 0, adval

adcin 1, adval1
pause 1
write 1, adval1

adcin 2, adval2
pause 1
write 2, adval2

adcin 3, adval3
pause 1
write 3, adval3
adcin 4, adval4
pause 1
write 4, adval4

adcin 5, adval5
pause 1
write 5, adval5


SEROUT PortC.6,2,[adval, adval1, adval2, 10]

portc.6 = 0
portc.7 = 0
pause 200
goto loop1
End

richard
- 19th January 2016, 21:39
adval var word ' Create adval to store result
adval1 var word
adval2 var word ' Create adval to store result
adval3 var word
adval4 var word ' Create adval to store result
adval5 var word
.............................

pause 1
write 0, adval

adcin 1, adval1
pause 1
write 1, adval1




how many bytes in a word ?

Dave
- 20th January 2016, 11:48
Jmgelba, you need to index the memory pointer by 2 for it to store a word or, something like this:

write 1, adval1.lowbyte
write 2, adval1.highbyte

then you can read them back by using:
READ 1,value to read the entire word.