How generate PWM using AT89c52

Dear friends,

i am ghanshyam gajjar. i have interface CS5460A to AT89c52. And generate PWM by using the AT89c52.
I have no idea for how to generate the PWM using the AT89c52 because it has no any pwm channel.
it is posible for using timer.
please give me answer.

Thanks.
ghanshyam gajjar.

Parents
  • You can emulate PWM using Timer as PWM puls oscillator. Here is an example of 8-bit PWM. Timer period must be equal <PWM_Period>/256. You can adjust this example for PWM wide other than 8 bits. And optimize the perfomance if needed.

    unsigned char PWM_Period_Counter, PWM_Puls_Counter, PWM_Value;
    
    // define PWM_PASSIVE_LEVEL as you need
    #define PWM_PASSIVE_LEVEL 1
    #define PWM_ACTIVE_LEVEL (1-PWM_PASSIVE_LEVEL)
    
    // define PWM_Output pin, INTERRUPT_TIMER0 vector & PWM_ISR_RBANK as you need
    sbit PWM_Output = Pn^m;
    #define INTERRUPT_TIMER0 1
    #define PWM_ISR_RBANK 1
    void PWM_Timer_ISR() using PWM_ISR_RBANK interrupt INTERRUPT_TIMER0
    {
      if  (--PWM_Period_Counter==0)
      {  // end of PWM period - reload PWM value
        PWM_Puls_Counter = 256-PWM_Value;
        PWM_Output = PWM_PASSIVE_LEVEL;
      }
      else
      {
        if  (--PWM_Puls_Counter==0)
          PWM_Output = PWM_ACTIVE_LEVEL;
      }
    }
    void main()
    {
      PWM_Value = 0;
      // setup and start Timer0 (or TimerX)
      while (1)
      {
        PWM_Value = produce a PWM value...
      }
    }
    

    Or (better) use an other uCPU (for example, AT87C51Rx2) with hardware PWM function. ;)

Reply Children
More questions in this forum