14.08.2013, 11:07 AM
Angenommen n=128 und ich wöllte -90° Phase (0...31=32; 128/4=32) vorsteuern, dann sähe das so aus:
[/navy]
......
......
......if(i == 127){
.........i = -1;
......}
......i++;
......if(reglerOn == 1){
.........setOut(soll[i] + err[i]);
......}else{
.........setOut(soll[i]);
......}
...}
...firstrun = 0;
...reglerOnOld = reglerOn;
}
[/code]
anstatt dem einfachen
Code:
[navy]//Interrupt, der im immer gleichen Zeitabstand aufgerufen wird.[/navy]
void c_int(void){
...if(reglerOn == 1 && reglerOnOld == 0){....[navy]//Regler frisch angeschaltet, err[] nullen[/navy]
......for(j = 0; j < n; j++){
.........err[j] = 0.0;
......}
...}
...if(firstrun == 1){
......setOut(soll[0]);
...}else{
......ist = getIst();
......error = (sollAmplitude * soll[i]) - ist;
......[navy][code]
......if((i - 31) < 0){
.........err[i - 31 + 128] += error * kr;
......}else{
.........err[i - 31] += error * kr;
......}
......
......
......if(i == 127){
.........i = -1;
......}
......i++;
......if(reglerOn == 1){
.........setOut(soll[i] + err[i]);
......}else{
.........setOut(soll[i]);
......}
...}
...firstrun = 0;
...reglerOnOld = reglerOn;
}
[/code]
anstatt dem einfachen
Code:
err[i] += error * kr;
Pffffffffft. "Da entwich das Vakuum" - Heinrich Physik, 1857.