14 Eylül 2017 Perşembe

PWM

Pulse Width Modulation output of PIC's can be used for dimming lights (LEDs) or motor control.

Proteus: We will use RC1 PWM output, it may differ for each PIC model check the datasheet. You will observe that duty cycle will change 0-50% and dim the LED.


MCC: add CCP2 and TMR2 peripherals. Select RC1 as output in pin manager and pin module. at CCP2 peripheral, select PWM mode and 50% duty cycle. at TMR2, enable timer, 1:1 prescaler, 1:16 postscaler and 16.384ms period.





XC8: include pwm2.h file. in the main while loop, change duty cycle within a for loop. I used __delay_ms() function instead of for loop to create delay.


#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/pwm2.h"

/*
                         Main application
 */
void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();



    while (1)
    {
        // Add your application code
        for (int duty = 1; duty < 512; duty = duty + 10)
        {
            PWM2_LoadDutyValue(duty);
            //for (int delay = 1; delay < 500; delay++)
            //{;}
            __delay_ms(100);
        }
    }
}

download the example

1 yorum:

  1. Learning Pic Programing With Xc8 Compiler: Pwm >>>>> Download Now

    >>>>> Download Full

    Learning Pic Programing With Xc8 Compiler: Pwm >>>>> Download LINK

    >>>>> Download Now

    Learning Pic Programing With Xc8 Compiler: Pwm >>>>> Download Full

    >>>>> Download LINK rp

    YanıtlaSil