#include "xc.h"
#include "config.h"
#include "extern.h"
#include <libq.h>

void Init_DbarMin_LookupTable()
{
int i;
int N;
float MinDbar_FP;
  //Set up DbarMin Lookup table.
for (i=0;i<=255;i++)
   {
    N = i<<6;  //Cooresponding RPM
    MinDbar_FP =  ((float) MinDC + ((float) MinDC_LIN)*N + (((float) MinDC_QUAD)*N)*N);  //Encoded as 0->255 corresonds to DC 0->1.
   if(MinDbar_FP < 1.0)
       dbarMinLookup[i] =  (unsigned char) 255*MinDbar_FP;
   else
       dbarMinLookup[i] = 255;
   }

}


//This returns the minimum allowable bridge duty cycle in Q15 representation, based upon the specified RPM in Q15 representation in which each bit represents 0.5RPM
int LookupDbarMin(int f_N)
{
return (dbarMinLookup[_Q15abs(f_N) >> 7]) << 7;
}