PIC18F25K22 Compile Problems

2012-11-04
2013-05-30
  • Nobody/Anonymous

    Has anyone had success using GC Basic on this chip? I'm just trying the usual blink-an-LED project, but have gotten no joy yet.

    MCLR=OFF generates a warning ("Configuration setting not valid: MCLR=INTMCLR"). It would be nice to free up the MCLR pin, though.

    After commenting it out, the program compiles, assembles and burns okay. However I'm still not seeing a blinking LED. I suspect something is going on or not going on with the clock.

    Any ideas?

     
  • Nobody/Anonymous

    A very solid day of experimenting has yielded the following. I got the MCLR business figured out; the attached code shows that ON/OFF are not the values expected. See the second #CONFIG statement for what I eventually found.

    More serious is the first #CONFIG statement. PLLCFG and PRICLKEN generate GC Basic compile errors. Changing them to PLL_EN_ON and PRI_CLK_EN_OFF passes GC Basic but then fails in the assembler. So, it's heads you win, tails I lose!

    So, what's going on? Is it GC Basic or MPASM. Is the problem in the .dat file or the .inc file? Either way, it doesn't seem possible to set the PLLCFG or PRICLKEN config bits.

    ;A program to blink a single LED on B.0 once a second
    #chip 18F25K22, 64          ;PIC18F25K22 running at 64 MHz
    #config PLLCFG=ON, PRICLKEN=OFF
    #config MCLRE = INTMCLR
    #config PWRTEN = ON
    #config FOSC = INTIO67   
    #config WDTEN = OFF      
    #config BOREN = OFF
    #config PBADEN = OFF
    #config LVP = OFF
    OSCCON = 0b01110000         ;clock at 16MHz, set by config
    OSCTUNE.6 = 1               ;Enable the PLL
    ANSELA = 0                  ;all digital I/O
    ANSELB = 0
    ANSELC = 0
    ;************************ Constants ************************
    #define LED PortB.0         ;LED is on B.0
    ;************************  Program *************************
      dir LED out               ;make B.0 an output
      
      main:
        set LED on              ;turn LED on for 1/2 second
        wait 500 ms
        set LED off             ;then off for 1/2 second
        wait 500 ms
      goto main                 ;repeat in perpetuity
    end
    
     
  • Anonymous

    Anonymous - 2012-11-06

    Hi all,

    I'm getting closer. The compile trouble is in the .dat file. The 2nd and 3rd lines in the  section of the file 18F25K22.dat should read:

    PLLCFG=OFF,ON
    PRICLKEN=ON,OFF
    

    I suspect that Hugh's auto-parser choked on the underscores when preparing this file. So, Hugh, if you agree with these two changes, you might want to make them to the file in the "official" download.

    Anyway, the code compiles and assembles correctly now.

    Unfortunately, though, I still can't make an LED blink; the circuit just sits there doing nothing. Here's the code:

    ;A program to blink a single LED on C.0 once a second
    #chip 18F25K22, 16          ;PIC18F25K22 running at 16 MHz
    #CONFIG PLLCFG=ON
    #CONFIG PRICLKEN=OFF
    #CONFIG MCLRE = INTMCLR
    #CONFIG PWRTEN = ON
    #CONFIG FOSC = INTIO67   
    #CONFIG WDTEN = OFF      
    #CONFIG BOREN = OFF
    #CONFIG PBADEN = OFF
    #CONFIG LVP = OFF
    #CONFIG DEBUG = OFF
    #CONFIG XINST = OFF
    OSCCON = 0b01110000         ;clock at 16MHz
    OSCTUNE.6 = 0               ;disable the PLL
    ANSELA = 0                  ;all digital I/O
    ANSELB = 0
    ANSELC = 0
    ;************************ Constants ************************
    #define LED Portc.0         ;LED is on C.0
    ;************************  Program *************************
      dir LED out               ;make an output
      
      main:
        set LED on              ;turn LED on for 1/2 second
        wait 500 ms
        set LED off             ;then off for 1/2 second
        wait 500 ms
      goto main                 ;repeat in perpetuity
    end
    

    The same program (with minor syntax changes) works fine in PIC Basic Pro, but I would much prefer to use Great Cow Basic.

    Can anybody spot something obvious I've missed?

    Thomas Henry

     
  • kent_twt4

    kent_twt4 - 2012-11-06

    The assembler looks O.K. from what I can tell.  GCBasic handles the program end, so that is not required.  I compiled an old 18f26k22 LED blinky that I had.  My config excluded DEBUG and PWRTEN.  Sometimes its a mystery whether DEBUG means NOT DEBUG.

    If that doesn't work you could try another pin, like RC2 which has no alternate pin functions.  If that works, then you will have to reconcile the CONFIG bits (i.e. P2B or T3CKI) with the PORTC I/O summary table from the data sheet.

     
  • Anonymous

    Anonymous - 2012-11-07

    Hi again,

    Okay, this really has me stumped! I put in another 4 hours today, but haven't made any progress. Thanks for your suggestions Kent, but I had already tried moving to other pins and tons of other things. But it's good to have a reminder that not all pins are created equal.

    In an effort to figure out what's going on, I simplified things even more. How about this:

    ;A program to illuminate a single LED on B.0 
    #chip 18F25K22, 16      ;PIC18F25K22 running at 16 MHz
    dir PortB.0 out         ;make an output
    set PortB.0 on          ;turn LED on
    

    You can't get any simpler than this; it simply turns on the LED, or at least is supposed to. Here I'm just using the default configs that GC Basic provides.

    Can I ask anyone with a spare moment to look at the assembly this creates and see what you think? Also, if you get a chance, could you single-step it in MPLAB SIM. I'm pretty new at this, but I didn't think it was doing what if should be.

    Finally, (again forgive my newed-ness), but aren't there supposed to be three vectors at the start of this chip? If so, then I think the code is assembling into where the interrupt vectors reside. But again, I'm pretty new at this all.

    Incidentally, I've been programming in assembly language for microprocessors since 1981, but am still finding the PIC kind of hard to wrap my head around. I'm trying to break my prejudice for the old Motorola and MOS chips which made perfect sense to me from the get-go.

    Thanks for any comments,

    Thomas Henry

     
  • kent_twt4

    kent_twt4 - 2012-11-07

    Hey Henry,

    This chip (i.e. 18fxxK22) had a real rough start.  To begin with MPASM hid the DEBUG bit from the standalone PICKit programmer app, and had to be flashed through MPLAP :-(   There was a thread started by me on this some time ago on this situation.  Hugh fixed it with the internal GASM, which worked great.  MPASM/MPLAB decided to unhide the DEBUG bit in later revisions, because of all the complaints.  If you have an older edition of MPASM or GCASM for that matter, that could be the problem.

    Check the config bits in the programmer UI and make sure that the DEBUG bit is OFF.  Change it and recompile, and you should have your answer.

    Other suggestions would be if you have a 0.1uf bypass cap on the power supply?  Or, the chip got overvolted and is now bad?

    Kent

    PS:  You should use PBADEN=OFF when using digital I/O on PORTB

     
  • Anonymous

    Anonymous - 2012-11-08

    Hi Kent,

    Thanks for the reminders, but I had already tried these. DEBUG really is being turned off, and I've tried various ports. And I always use bypass caps, even on the breadboard.

    What perplexes me is that the same program (with just a few trivial syntax changes) works under PicBasic Pro. I am able to confirm that the config settings are same in both .hex files. So unless I'm missing something obvious, I don't think that's it.

    But I really do appreciate your comments,

    Thomas Henry

     
  • kent_twt4

    kent_twt4 - 2012-11-08

    Well in some ways things are getting narrowed down?  I have used the 18f26k22 on several different projects with GCBasic with very little problems.  There are challenges to address the SFR's, beyond the 256 limit. The inbuilt adc library may not be able address all the ANX pins, and so forth.

    I don't have a 18f25k22 chip to test. So is the 18f25k22.dat file corrupt? Try saving the 18f25k22.dat file to 18f25k22_old.dat and copy over the 18f26k22 to the new 18f25k22.dat file.  Everything should be the same, excepting the memory limitations.  Good Luck!

     
  • Anonymous

    Anonymous - 2012-11-08

    Hi again,

    Well, I got it figured out, and as usual for this sort of thing, it's operator error (me).

    To set the stage, I'll mention that the only PIC work I've done so far was with the 16F88, and I've done perhaps forty or fifty projects successfully. To simplify my work, I whipped up an IDE using TextPad, which I wrote up in a recent article in Nuts & Volts Magazine. So, anyway, before evolving to the 18F25K22, I had been exclusively using the 16F88 and so the IDE was expecting that chip.

    Can you see where this is leading? The older chip was wanted the .hex code to be in INHX8M  format, while the 18F25K22 needed it to be in INHX32 format. Once I made the change to the file extension in the IDE batch file, away it went!

    So, anyway, it all works according to Hoyle now. I'm going to update my IDE batch file to automatically make the changeover if I can.

    The problem really wasn't mostly with GC Basic after all, but rather in how the .hex file was being save. Nonetheless, there were two goof-ups in the 18FK22.dat file which prevented the code from being correctly compiled and assembled. I've already detailed these above, so make those changes if you expect to use this chip.

    Hey, I hope I haven't wasted your time too much. Thanks again, Kent, for looking at this with me.

    It all works now, and I can finally get cracking!

    Thomas Henry

     

Log in to post a comment.