PWM with dsPIC33FJ64MC802

Author
Sebos
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2010/03/10 05:59:39
  • Location: 0
  • Status: offline
2010/07/08 02:19:59 (permalink)
0

PWM with dsPIC33FJ64MC802

Hi,

I'm searching a c-code with a minimal configuration of the PWM-Module. I can't find easy examples on the Microchip Homepage.

Thanks for answering.

Regards
Sebastian
#1

6 Replies Related Threads

    ilco
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2009/10/14 12:55:06
    • Location: France
    • Status: offline
    Re:PWM with dsPIC33FJ64MC802 2010/07/08 04:52:26 (permalink)
    0

    //---------------------------------------------------------------------
    // MOTOR CONTROL PWM MODULE 1
    //---------------------------------------------------------------------
    #define MOTOR_PWM_FREQ 500        //motor PWM frequency in Hz
    #define FCY 40000000UL           
    #define MOTOR_DUTY 70           //motor duty in %

    void motor_update_duty(){

        P1DC1 = (2UL*P1TPER+2)*MOTOR_DUTY/100;
    }

    void motor_init(){
        //setup output pins
        LATBbits.LATB14=0;
        TRISBbits.TRISB14 = 0;

        //setup PWM ports
        PWM1CON1 = 0;                //clear all bits (use defaults)
        PWM1CON1bits.PMOD1 = 0;     //PWM1Ly,PWM1Hy are in independent running mode
        PWM1CON1bits.PEN1L = 0;     //PWM1L1 NORMAL I/O
        PWM1CON1bits.PEN1H = 1;     //PWM1H1 PWM OUTPUT

        //PWM mode and prescaler
        //PWM1, MOTORS 0,1,2   
        P1TCON = 0;                    //clear all bits (use defaults)
        P1TCONbits.PTMOD = 0b00;    //Free-runing mode
        P1TCONbits.PTCKPS = 0b11;    // 1:64 prescaler

        //setup desired frequency by setting period for 1:64 prescaler
        P1TPER = (FCY  / 64 / MOTOR_PWM_FREQ) - 1;   

        //update duty cycle
        motor_update_duty();   
       
        //ENABLE PWM1
        P1TMR = 0;
        P1TCONbits.PTEN = 1;   
    }

    //adapted from Starlino


    Output PWM1H1 on dsPIC33FJ128MC802, 70% duty cycle, freq 500Hz.

    You must configure your oscillator for 40Mhz!

    regards
    #2
    Sebos
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2010/03/10 05:59:39
    • Location: 0
    • Status: offline
    Re:PWM with dsPIC33FJ64MC802 2010/07/08 23:55:06 (permalink)
    0
    Thanks. It works!

    regards
    Sebastian
    #3
    samudio
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2011/11/11 13:15:40
    • Location: 0
    • Status: offline
    Re:PWM with dsPIC33FJ64MC802 2011/11/11 13:21:30 (permalink)
    0
    Thanks. :) regards
    #4
    samudio
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2011/11/11 13:15:40
    • Location: 0
    • Status: offline
    Re:PWM with dsPIC33FJ64MC802 2011/11/11 13:22:39 (permalink)
    0
    Thanks. :) regards
    #5
    Meeravalimau
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2011/06/15 22:39:46
    • Location: 0
    • Status: offline
    Re:PWM with dsPIC33FJ64MC802 2011/11/23 21:05:30 (permalink)
    0

    Hi Sebos

    For PWM configuration below pdf link may help you :

    http://ww1.microchip.com/downloads/en/DeviceDoc/70187D.pdf

    Regards
    M.Shaik
    #6
    nitinjoshi
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2013/04/17 00:23:04
    • Location: 0
    • Status: offline
    Re:PWM with dsPIC33FJ64MC802 2013/05/15 23:23:53 (permalink)
    0
    GM sir,
    i want to generate pwm using same dspic33fj64mc802 on microstick device.
    i was looking into your code example and the section 14 pdf for pwm for dspic33f.
    one thing i am not able to understand is this line:-P1DC1 =P1TPER to get 50% duty cycle.
    ie in reality duty cycle register value should be half of max P1TPER for duty cycle to be 50%.
    sorry if i have posted my query on wrong post.
     
    thanks and regards
    Nitin Joshi
    #7
    Jump to:
    © 2017 APG vNext Commercial Version 4.5