This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

HVPSFBKIT Spreadsheet Calculations



Hello All,

I am evaluating the HVPSFBKIT based on the F28027 microcontroller, and I am having trouble understanding how the scaling constants are calculated in this example.  I'm looking at the HVPSFB-Caculations.xls spreadsheet.  For each of the measured parameters [Vfbin, Vfbout, Ifb, Iout] I understand the calculation of the cascaded gain factors, such as ADC gain, transducer gain, etc.  I can also verify that I calculate the same LSB/amp or LSB/volt overall gain as that used in the "verification" section on each tab. All of that makes sense.

However, I have two questions about this spreadsheet (reference tab Ifb for example):

1. What is the reason for the 3-bit left shift of each measured parameter (cell B9)?   I cannot find where this is done in the code, so it must be implicitly done somewhere.  Does this have something to do with the averaging of 8 sampled values per switching cycle?

2. Can you explain how the Kv value is calculated (cell F12)?  It looks like the intermediate parameter 'q' (cell F11) is used to determine the number of bits required to store the number of LSB's associated with 1A (based on the maximum current Ifbmax).  Kv is then calculated by right-shifting the maximum current Ifbmax by (15-q) positions.  I cannot understand the reasoning behind this process, nor can I understand what the value Kv represents once this has been done.

Thanks in advance for your help.

Andy

  • Andy,

    So far you're on the right track.  The purpose behind much of this spreadsheet is to scale the ADC inputs to and from real-world values that can be put into a CCS watch-window and easily viewed (these variables don't have any impact on the control loop directly, except to scale user inputs into references used by the controllers).  These "GUI" variables are typically signed 16-bit values and have a q-value attached to them.  Via the watch window any variable can be viewed with various q-values.

    As for your questions:
    1) In most of our devices, such as the F28027, the ADC result is a 12-bit value.  In order to get the full amount of resolution out of our signed 16-bit "GUI" variable we would need to shift the ADC result by 3 bits (hence the gain of 8).  In the code, typically we add together the last 8 consecutive ADC values and this gives us our gain directly:
    ((ADC_input_hist1 << 3) + (ADC_input_hist2 << 3) + ...  + (ADC_input_hist8 << 3)) / 8 = ADC_input_hist1 + ADC_input_hist2 + ... + ADC_input_hist8

    ---

    2) The q-value "q" specifies the number of bits designated as fractional bits. Cell E11 ("q") tries to figure out the most optimum choice of q value such that:
       a) the integer part of the number (B11) can be represented while b) maximizing the number of fractional bits

    Kv is then used to scale the actual ADC input to the new q-scaled format viewable in the watch window.  (cell F14, the Kv value in Q15, is actually what gets multiplied).  iKv is used to convert values the opposite direction (from user input to the controller)

    ---

    Hopefully this clears things up (at least somewhat)


    Thank you,
    Brett

  • Hi Brett,

    Thanks very much for your reply.  This does help me considerably.  I now understand where the x8 ADC gain comes from, as well as how Kv (and iKv) values in Q15 are calculated.  If you don't mind, I'd like to ask a follow-up question now that I understand this a little better. 

    I'm working on a custom PSFB using the kit as a reference.  In my design, I need to use a different current transformer with lower gain.  As a starting point, I want to integrate my new CT into the HVPSFBKIT and try to get the gain and scaling correct.  When I enter the updated gain figure in the spreadsheet, I get a value for Kv which is no longer Q12, but Q8.  Now, based on your explanation, I think I probably need to:

    1.  Make the representation of Gui_Ifb and Gui_IfbSet in the watch window "Q8" instead of "Q12".

    2.  Look for any places in the code where Gui_Ifb and Gui_IfbSet are assumed to be Q12 and update those instances.  For example:

    int16    Gui_IfbSet = 614;                    // Q12 -- Build 1 Only - 0.15A

    would now be:

    int16    Gui_IfbSet = 38;                      // Q8 -- Build 1 Only - 0.15A

    >>

    If you wouldn't mind, could you comment on (1) whether I'm on the right track with the above suggested changes, and (2) in general, what do I need to consider when changing the scaling of the current transducer (any other variables or constants which might be impacted?). 

    I realize that with this lower-gain CT, the sensed voltage will likely be down in the weeds when I run it on the HVPSFB at <1A on the primary.  I'm thinking I can manage that (at least to a point) by adjusting the burden resistor on the CT (e.g. increasing the gain).  But I think if I understand the process of accommodating different gain values (and the impact of changing the Q-number of the resulting scaling factors), that will satisfy my immediate need.

    Thanks again for the help.

    Regards,

    Andy

  • Andy,

    You're getting there...

    For your listed steps:
    1) Correct
    2) Correct, assuming that the CT gain is somewhere around 0.00053 (cells B18 & F18 in the spreadsheet are useful for finding the proper Q0 values for initialization)
      [FYI, it seems that the comment for the original code is incorrect.  I believe it should say: int16 Gui_IfbSet = 614;   //Q12 -- Build 1 Only - 0.127A]
    3) anything else missing? - you'll need to change Ifb's K and iK scaling constants (around line 288 for the VMC project).  I think that's it...


    Thank you,
    Brett

  • Thanks Brett.  I appreciate the help.

  • Hello Brett,

    I'm still struggling with these calculations, and I've narrowed down my problem to a tidy example that I'm hoping you can help resolve.  I have dropped back to using the stock CT on the HVPSFBKIT, and simply changed the burden resistor from 48.7 ohms to 20 ohms.  This should result in a CT gain decrease on the order of 2.4x.  I hope I've at least got that much right.

    When I change the value of Rtotal in the spreadsheet (cell E3) to 20, I get the following values:

    (cell F11) q: 10

    (cell F12) Kv: .5156

    (cell F14) KvQX(Q15): 16896

    (cell I14) iKvQY(Q14): 31775

    (cell F18) IfbQ0: 298 (Should correspond to 0.15 A as shown in cell B18)

    Next, I run the PCMC application with these values (and I change Gui_IfbSet and Gui_Ifb in the watch window to Q10 format).  As soon as I start the debugger, I notice that my Gui_IfbSet is showing up as 0.2910 A instead of the expected 0.15 A.  A quick check shows that converting the IfbQ0 value in F18 (298) to Q10 indeed gives me .2910 instead of 0.15.  So, what am I not understanding about how to convert these scaling factors?  The bottom line is that I want to be able to change my CT gain (resulting in a Q-shift for the scaling factors) and still maintain sanity in the watch window. 

    Thanks in advance for your help.

    Regards,

    Andy

    16896
  • Andy,

    Everything you're doing makes sense to me.  0.291 is roughly 2*0.15 so you may be just barely off. 

    Which PSFB project are you using?  Note that if you're using the VMC project Gui_IfbSet means nothing. 

    Other than that, make sure (as you mentioned previously) that you change the q-value of the variables in the watch window to their new value.

    If none of this works it may be worthwhile to start anew from the TI source file.  It's possible to mess something up unexpectedly after playing with things for awhile and getting frustrated :(.  Or maybe that's just me...


    Thank you,
    Brett

  • Hi Brett,

    I think I figured it out.  It appears that for setting the Gui_IfbSet value directly, you have to multiply the IfbQ0 field by Kv in addition to converting to your Q-format of choice. 

    This is why in the original code, the initial Gui_IfbSet value was initialized to 614 instead of 725 (as would be predicted by converting the spreadsheet IfbQ0 field to Q12, as I originally thought).  This is also why the comment in the source is correct in calling out an initial default current of 0.15 A, using a value of 614.  As long as your Kv value is close to unity, making this mistake does not result in significant/noticeable error.  However, if you change your gain such that Kv is significantly less than 1, this error becomes significant.  This is the case that I was experiencing. 

    I will (try to) attach my modified spreadsheet which demonstrates this conversion (see the Ifb tab).  This is probably pretty obvious to someone more familiar with working with fixed-point systems, but it took me a while to figure out. Please let me know if you see anything incorrect in my assumptions or conclusions.

    Thanks again for the help.

    Regards,

    Andy

    1526.HVPSFB-Calculations_Modified_10312012.xls