Menu

PWM Again

Help
2011-03-04
2013-05-30
  • Nobody/Anonymous

    Could someone please tell me why the below code does not give me apx. 50% brightness on an LED?

    #chip 18f14k22,16
    #config MCLRE=ON, OSC=IRC, LVP=OFF, PLLEN=off
    #define Up portb.5
    #define Down portb.6
    dim bright as byte
    dir Up in
    dir Down in
    dir portc.5 out

    start:

    set PR2 = 250
    set T2CON.T2CKPS0 On
    set T2CON.T2CKPS1 On
    set CCPR1L = 125
    set CCP1CON.DC1B1 on
    set CCP1CON.DC1B0 on

    set CCP1CON.CCP1M3 on
    set CCP1CON.CCP1M2 on
    set CCP1CON.CCP1M1 off
    set CCP1CON.CCP1M0 off

    set T2CON.TMR2ON On

    goto start

     
  • kent_twt4

    kent_twt4 - 2011-03-04

    It's spot on, good job!

    The problem lay with Microchip and how they decided to handle the debug bit for the 18fxxK22 devices.  My Pickit 2 can manually set the !debug bit by ticking the config4L.7 box.  Hugh has fixed this for the internal asm, which is how I deal with it when working with my 18lf14k22.  I end up commenting out the MPASM lines in the COMPILE.BAT and MAKEASM.BAT and uncomment the following GCASM lines.  One of these lines may not be required, because I think GCASM is default, I forget which one.

    COMPILE.BAT

    GCBASIC /NC %1 /O:compiled.asm /A:GCASM /P:download.bat
    

    MAKEASM.BAT

    Assembler = GCASM
    

    Good to use the code tags when posting code next time.  Also initializing registers usually before Main/Start.

     
  • kent_twt4

    kent_twt4 - 2011-03-04

    P.S.  I've heard that the newest MPLAB MPASM may have fixed the !debug bit problem, for at least some of the 18fxxK22's, but haven't yet tried myself.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.