Header Ads

Header ADS

Using Internal PWM Module of PIC Microcontroller+MikroC Programming

Using Internal PWM Module of PIC Microcontroller




void main()
{
  short current_duty_1  = 16; // initial value for current_duty_1
  short current_duty_2 = 16;  // initial value for current_duty_2

  TRISD = 0xFF;
  TRISC = 0x00;

  PWM1_Init(5000);  //Initialize PWM1
  PWM2_Init(5000);  //Initialize PWM2

  PWM1_Start();  // start PWM1
  PWM2_Start();  // start PWM2

  PWM1_Set_Duty(current_duty_1); // Set current duty for PWM1
  PWM2_Set_Duty(current_duty_2); // Set current duty for PWM2

  while (1)        // endless loop
  {
     if (!RD0_bit)   // if button on RD0 pressed
     {
      Delay_ms(40);
      current_duty_1++;  // increment current_duty_1
      PWM1_Set_Duty(current_duty_1);  //Change the duty cycle
     }

    if (!RD1_bit)               // button on RD1 pressed
    {
      Delay_ms(40);
      current_duty_1--;  // decrement current_duty_1
      PWM1_Set_Duty(current_duty_1);
     }

    if (!RD2_bit)     // if button on RD2 pressed
    {
      Delay_ms(40);
      current_duty_2++;    // increment current_duty_2
      PWM2_Set_Duty(current_duty_2);
     }

    if (!RD3_bit)       //if button on RD3 pressed
    {
      Delay_ms(40);
      current_duty_2--;   // decrement current_duty_2
      PWM2_Set_Duty(current_duty_2);
     }

    Delay_ms(10);      // slow down change pace a little
  }
}

1 comment:

  1. This works especially well Ganga music when the topic includes specific figures, such as dollar amounts, percentages, and dates.ganga bhakti

    ReplyDelete

Theme images by Bim. Powered by Blogger.