18F4550 issue with simple program.


+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default 18F4550 issue with simple program.

    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

  2. #2
    Join Date
    Oct 2009
    Posts
    582

    Default Re: 18F4550 issue with simple program.

    deleted after posting

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,032

    Default Re: 18F4550 issue with simple program.

    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

  4. #4
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Re: 18F4550 issue with simple program.

    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

  5. #5
    Join Date
    Jul 2009
    Location
    Ohio, USA
    Posts
    57

    Default Re: 18F4550 issue with simple program.

    Is MCLR tied high?

  6. #6
    Join Date
    Oct 2009
    Posts
    582

    Default Re: 18F4550 issue with simple program.

    Not sure if this helps, but this is a section of code that uses an 18f4580, with four pots on port A

    Code:
    ; 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

  7. #7
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Re: 18F4550 issue with simple program.

    Quote Originally Posted by Mike2545 View Post
    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.

  8. #8
    Join Date
    Jul 2009
    Location
    Ohio, USA
    Posts
    57

    Default Re: 18F4550 issue with simple program.

    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

  9. #9
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Re: 18F4550 issue with simple program.

    Turns out this was a MPASM issue. Once I had that resolved the program worked.

  10. #10
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Re: 18F4550 issue with simple program.

    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

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,032

    Default Re: 18F4550 issue with simple program.


    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 ?

  12. #12
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default Re: 18F4550 issue with simple program.

    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.
    Dave Purola,
    N8NTA
    EN82fn

Similar Threads

  1. USB issue - 18F4550
    By Scampy in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 20th February 2013, 21:49
  2. 18F4550 issue
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 4th February 2013, 07:27
  3. Simple LED driving issue - setup?
    By George in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th March 2011, 02:54
  4. Code issue with a flashing light(simple question)
    By IAmTheAnswer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th May 2010, 12:46
  5. Simple 4 line LCD display with 18F4550
    By pic-ker in forum Code Examples
    Replies: 4
    Last Post: - 9th April 2007, 03:58

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts