Hi,

I am using a buck converter in my solar project.right now i am writing the code for Maximum power point algorithm(MPPT).

In this first i am reading the solar panel votage through ADC. and i have also generated the PWM at 20KHz,60% duty cycle as follows:

//Reads the solar panel voltage first


AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 = cascaded mode; 0= dual sequencer mode;
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; //1 = continouous run because solar power always changing
AdcRegs.ADCMAXCONV.all = 0x0000;  //solar panel voltage conversion first
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0;  //ADCINA0 is selected as input channel

AdcRegs.ADCTRL2.all = 0x2000;

S_PanelVoltage = AdcRegs.ADCRESULT0>>4; //as ADCRESULT Registers are left Justified

//End of the solar panel voltage reading and stored in S_PanelVoltage variable

//Now generating the Pulse width modulation at a frequency of 20KHz and
//caputure the pulse width to find out the duty cycle

//first intilize the GPIO for PWM setup
//use ePWM1 to produce reqiured pulses to MOSFET through EPWM1A
//i.e
 
 
//Initilisation of PWM peripheral by enabling the clock
   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
   EDIS;

  EALLOW;
  SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK = 1;
  EDIS;
// Setup of Time Base Module.i.e TB
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; //default
EPwm1Regs.TBCTL.bit.CLKDIV = 0; //default
EPwm1Regs.TBCTL.bit.CTRMODE= TB_COUNT_UPDOWN;
EPwm1Regs.TBPRD =3750;// defined the timebase period value for 20KHz
EPwm1Regs.TBCTR = 0;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // phase is disabled

// setup compare values
EPwm1Regs.CMPA.half.CMPA = 1125;

// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE=CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE= CC_CTR_ZERO;

// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; // completion of generating PWM wave supplied to MOSFET.
//find out of the duty cycle


// product of solar panel voltage and duty cycle
 EALLOW;
 SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
 EDIS;

 

and my questions are:

1) above code is correct or not i mean the flow

2) now i have to product the duty cycle and solar panel voltage how to do that

3) in this alogorithm i have to change the duty cycle continuously still i get maxiumum power how to do that whether changing the value Of CMPA always or it is beterr to go for eCAP?

please help me i struck here only

 

Thanks & Regards

Naveen Rangu