• AVR Freaks

Hot!PWM control on PIC24FJ256GB410

Author
dantheman
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2019/07/01 12:27:29
  • Location: 0
  • Status: offline
2019/07/16 07:21:31 (permalink)
0

PWM control on PIC24FJ256GB410

Hi all,
 
I'm taking a stab at creating some PWM code for LEDs on the PIC24FJ256GB410 on Explorer Board 16/32 (using MCC compiler). I've read all the family data sheets and schematics for both the PIC and development board, but just can't seem to get my footing anywhere. I've already managed to get the LEDs to perform the "Knightrider" sequence, but obviously this is a much bigger step.
 
Any help is appreciated!
#1

5 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23252
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PWM control on PIC24FJ256GB410 2019/07/18 21:17:02 (permalink)
    0
    Where are you getting stuck?
    You can use a CCP module or an Output Compare module to produce PWM.
    Have you decided which to use, and made a start configuring it?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    jbroadwell81@gmail.com
    Super Member
    • Total Posts : 1446
    • Reward points : 0
    • Joined: 2005/11/02 13:58:11
    • Location: Indianapolis, Indiana
    • Status: offline
    Re: PWM control on PIC24FJ256GB410 2019/07/20 08:14:33 (permalink)
    4 (1)
    Consider using the MCC development tool to get you started.  Create a new project that does just one PWM or one Output Compare.   Make that work on your board, then move the relevant code back to your main project, and start massaging it to be exactly what you feel you need.
     
    I find that the biggest hurdle, as you're saying here, is often getting anything to work at all.  Once it's working a little bit, incrementally changing it one register bit at a time to be what you need is a lot easier.

    http://www.serialwombat.com
    When someone asks you "Can't you just...", watch out.
    #3
    nigelwright7557
    Super Member
    • Total Posts : 276
    • Reward points : 0
    • Joined: 2006/11/06 08:15:51
    • Location: 0
    • Status: offline
    Re: PWM control on PIC24FJ256GB410 2019/07/20 09:12:38 (permalink)
    0
    Its just a matter of going through the datasheet concerning PWM mode and set all the registers accordingly.
     
    call setuppwm
    movlw 128
    movwf ccpr1l
     
    SETUPPWM    MOVLW   0CH
    MOVWF CCP1CON
    MOVLW 0
    MOVWF CCPR1L

    MOVLW 4 ;prescale will make longer in 2 lower bits
    MOVWF T2CON

    MOVLW 255
    BSF STATUS,RP0
    MOVWF PR2-80H
    BCF STATUS,RP0
    RETLW 0
    ;*************************************
    #4
    dan1138
    Super Member
    • Total Posts : 3166
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PWM control on PIC24FJ256GB410 2019/07/20 13:14:06 (permalink)
    0
    @dantheman,
    What you're trying to do is confusing because this PIC24 has at least three different PWM function blocks, each requires slightly different initialization methods.

    The MCC may help you to create the initialization functions.
    #5
    dan1138
    Super Member
    • Total Posts : 3166
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PWM control on PIC24FJ256GB410 2019/07/21 01:48:27 (permalink)
    0
    @dantheman,
     
    What you are trying to do is almost impossible when using the PIC24FJ256GB410 PIM and the DM240001-3 Explorer 16/32 development board.
     
    The first issue in this hardware configuration is that all of the LEDs (D3 to D10) are connected to PORTA RA0 to RA7, and these GPIO pins cannot be selected as target pins to map output function on.
     
    This means that OC1, OC2, OC3, OCM4, OCM5, OCM6 or OCM7 cannot be used to drive LEDs attached to PORTA.
     
    Now OCM1, OCM2, OCM3, OC4, OC5 and OC6 have fixed pin mappings. Only OCM1 has any outputs on PORTA. OCM1E is attached to RA6, OCM1F is attached to RA7. This results in only one PWM modulator output to drive an LED.
     
    Attached is an MPLABX v5.10 project with a MCC configuration file that builds code to enable OCM1F to drive RA7 with a 40KHz 50% duty cycle PWM output.
     
    Note that this code can only be tested in the real hardware. The MCCP simulation model for the PIC24F family in the MPLABX v5.10 simulator only works when the steerable output is selected as the OCM1A output.
    post edited by dan1138 - 2019/07/21 02:06:22
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5