PSIM Code generation to calculate RMS and average values

s_pal
s_pal Altair Community Member
edited October 17 in Community Q&A

Dear all, 
I can see that PSIM does not support the inbuild avg and rms block for code generation. 

Hence, I implemented it directly in CCS by manually written the code in PSIM generated .c file. 
I was wondering if it is possible to implement a virtual clock inside the PSIM, which is dedicated to update the registers (assign to hold the RMS or average values) only at specific time intervals. 

Thank you. 

Tagged:

Best Answer

  • Jack_2nd
    Jack_2nd
    Altair Employee
    edited October 14 Answer ✓

    Hi Souradeep,

    Average mode can only be used in simulation, but when the program runs in a CPU, we cannot set an average level to a hardware device, for example, you cannot set an average level to a PWM output. No hardware supports it.

    If you want to set a sampling rate for a curtain routine, you can use some blocks that include sampling frequency, for example, PWM block, or ZOH block. When you use a PWM block, SimCoder uses PWM to cause interruption, when there are only ZOH or UDelay blocks for a specified sampling frequency, SimCoder uses a timer to causes an interruption.

     

    Thanks,

    Jiakai

Answers

  • Jack_2nd
    Jack_2nd
    Altair Employee
    edited October 14 Answer ✓

    Hi Souradeep,

    Average mode can only be used in simulation, but when the program runs in a CPU, we cannot set an average level to a hardware device, for example, you cannot set an average level to a PWM output. No hardware supports it.

    If you want to set a sampling rate for a curtain routine, you can use some blocks that include sampling frequency, for example, PWM block, or ZOH block. When you use a PWM block, SimCoder uses PWM to cause interruption, when there are only ZOH or UDelay blocks for a specified sampling frequency, SimCoder uses a timer to causes an interruption.

     

    Thanks,

    Jiakai

  • Albert_Dunford
    Albert_Dunford
    Altair Employee
    edited October 17

    in addition to jaikai's comments if you integrate "1" the value of the integral will be the time that has passed. You can use resettable integral to just track the same period over and over again. if you are implementing c code you can use the c block to test your algorithm within PSIM simulation