AnsweredAssumed Answered

QG8:Vary PWM from ADC reads

Question asked by Abhijit Jagtap on Jun 18, 2013
Latest reply on Jun 26, 2013 by Abhijit Jagtap

Hello

 

I am trying to vary the PWM duty-cycle based on an ADC value.PWM frequency is 16khz

What i am trying to achieve is keep an output current constant by driving MOSFETs through a QG8.An ADC channel measures this current value.

What i see is that the duty-cycle remains unchanged even when ADC values change.

 

I think i am doing a very basic mistake , someone please correct me..writing init and ISR codes here

 

#define TIMER_OVERFLOW            60 // us

 

interrupt 7 void TimerCH1 (void)

{

  // Stops Timer1

  TPMSC = TIMER_STOP;

  

   if(current_adjust>512) // 1.5v corresponds to 5A

          {

            duty_cycle_variation--;

            if(duty_cycle_variation<=1)duty_cycle_variation=1;

          }

                 

           if(current_adjust<512)

          {

            duty_cycle_variation++;

            if(duty_cycle_variation>=100)duty_cycle_variation=100;

           }

  TPMC1V = duty_cycle_variation;

 

  // Restarts Timer1

  TPMSC = TIMER_START; 

}

 

 

 

void Timer1_init(void)

{

  // Timer1 period 

      TPMMOD = TIMER_OVERFLOW; //15ms

 

//Initial duty cycle 

    TPMC1V=0;

 

  // Selects PWM Low-true pulses in the Timer1 Channel0 (PTA0/TPM1CH0)

  TPMC1SC = 0x028; //flag=0|ch_int_dis=0|MSnBA=10=edge aligned PWM|ELSBA=01=set o/p on compare|00

  // Starts Timer1                                                 ELSBA=10=clr o/p on compare

  //TPMSC = TIMER_START;  //0,TOIE=1,CPWMS=0,CLKSAB=01 PS2-0=011(div/8=1us)

     

}

 

Someone please help

 

Thanks and regards


Outcomes