Sinusoidal generator with PSIM

Thread Starter

tomson

Joined Sep 6, 2010
16
I've posted it originally in the Electronics forum but guess here's the place for this kind of question.

Hello. My task is to simulate sinusoidal generator with PSIM using two methods - absolute values and table of differences. Parameteres of the generator are : Amplitude u=255 V, frequency f=50H; sampling frequency 5kHz. I have created arrays of norm and diff values with C. Now I've thought of a method of iterating through elements of the array and in each time step, and pick the corresponding value. If function is in the first quarter - iterate array from the beginning. If it will be in the second one - iterate arrayfrom the end. If quarter is third - iterate from the beginning with values multiplied by one. Finally in the fourth one - go through array from the end, multiplying elements by -1.

Now I should somehow create a function, which in each time step takes value from the array, and depending on the place on the sinusoid either multiplies it by -1 or not. But how can I store the information which element from the array should be taken now and if array should be iterated from the beggining or the end ?

Because the previous post had been deleted, here are tho seurce codes once again. First calculated arrays :

Rich (BB code):
int main(){
    double amp = 128;                             
    float norm[25];
    float diff[25];
    float s;
    int i;

    for(i=0; i< 25; i++){
        if(i == 0){
            norm = 0;
        }
        norm = i*2*M_PI/100;
        s = amp*sin(norm);
        norm = s;
    }
    
    for(i=0; i<25; i++){
        if(i == 0){
            diff = 0;     
        }
        diff = norm - norm[i-1];
    }
    
    return 0;  
}

and here's template for the dll function :

Rich (BB code):
__declspec(dllexport)opc1(double t, double dt, double *in, double *out){
    double u = in[0];
    out[0] = y;
}
 
Last edited:

Thread Starter

tomson

Joined Sep 6, 2010
16
and what about storing the current counter value in a file ? Will the system manage to read/write from/to a file 5k times per second ?
 
Top