免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 回復 發帖

2P2Z

i have written code for 2p2z using dspic33E controller with inbuilt function. problem with code is duty cycle register is not getting updated here is my code

#include<p33Exxxx.h>
#include"smps_control.h"
SMPS_2P2Z_T controller2P2Z;
int16_t controller2P2ZACoefficient[2] __attribute__((section(".xbss")))={0,0};
int16_t controller2P2ZControlHistory[2] __attribute__((section(".ybss")))={0,0};
int16_t controller2P2ZBCoefficient[3] __attribute__((section(".xbss")))={0,0,0};
int16_t controller2P2ZErrorHistory[3] __attribute__((section(".ybss")))={0,0,0};
int main(void) {
SMPS_Controller2P2ZInitialize(&controller2P2Z);
controller2P2ZACoefficient[0] = Q15(0.777969); /* A B coefficient*/
controller2P2ZACoefficient[1] = Q15(0.222031);
controller2P2ZBCoefficient[0] = Q15(0.858713);
controller2P2ZBCoefficient[1] = Q15(0.085612);
controller2P2ZBCoefficient[2] = Q15(-0.773101);
/* pointer to a structure */
controller2P2Z.aCoefficients = &controller2P2ZACoefficient[0]; //pointer to A coefficient
controller2P2Z.bCoefficients = &controller2P2ZBCoefficient[0]; //pointer to B coefficient
controller2P2Z.controlHistory = &controller2P2ZControlHistory[0]; // pointer to previous PDC1 value controller2P2Z.errorHistory = &controller2P2ZErrorHistory[0];
controller2P2Z.preShift = 1; // preshift
controller2P2Z.postShift = 1;
controller2P2Z.postScaler = 0;
controller2P2Z.minOutput = min_duty_cycle;
controller2P2Z.maxOutput = max_duty_cycle
config_osc();
start_pwm();
while (1);
}
/* calculating PDC(duty cycle) value on generation of interrupt */
void __attribute__((__interrupt__, no_auto_psv)) _PWM1Interrupt() {
int temp1 = 0;
IFS5bits.PWM1IF = 0; // clear PWM flag
adc_function_call(); // ADC function call
output_voltage = ADCBUF2; // saving ADC coverted value
if (output_voltage >reference ) { // error calculation()
errorr = output_voltage - reference;
} else if (output_voltage < reference) {
errorr = reference-output_voltage; // total error
}
errorr=errorr*10; // scaling of error
save_error_in_array(errorr); // saving error in array
/*update function for PDC*/
SMPS_Controller2P2ZUpdate(&controller2P2Z, &ADCBUF2, reference, &PDC1);
CORCON = temp1;
pdc_val = PDC1; // save PDCx value for error control history
controller_ControlHistory(pdc_val);
}
void save_error_in_array(int errorr) {
controller2P2ZErrorHistory[2] = controller2P2ZErrorHistory[1];
controller2P2ZErrorHistory[1] = controller2P2ZErrorHistory[0];
controller2P2ZErrorHistory[0] = errorr;
return;
}
void controller_ControlHistory(int pdc_val) {
controller2P2ZControlHistory[1] = controller2P2ZControlHistory[0];
controller2P2ZControlHistory[0] = pdc_val;
return;
}
my PDCx value is not getting updated kindly support
返回列表