Sorry but that doesn't make sense. The table index points to one of the 64 entries in the sine table, to recreate the sine shape it has to read all the 64 values. It doesn't matter what the frequency is, the index range should always be the same. If you limit it to less than 64 you reduce the quality of the sine shape and if you use more than 64 you 'fall off' the end of the table.No not only 2khz the frequency is a variable based on that i calculate the table index.
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt (void)
{
IFS0bits.T1IF = 0;
Period = ActualCapture - PastCapture; // This is an UNsigned substraction
// to get the Period between one
// hall effect sensor transition
// These operations limit the Period value to a range from 60 to 6000 rpm
[B] if (Period < (unsigned int)MINPERIOD) // MINPERIOD or 6000 rpm
Period = MINPERIOD;
else if (Period > (unsigned int)MAXPERIOD) // MAXPERIOD or 60 rpm
Period = MAXPERIOD;
// PhaseInc is a value added to the Phase variable to generate the sine
// voltages. 1 electrical degree corresponds to a PhaseInc value of 184,
// since the pointer to the sine table is a 16bit value, where 360 Elec
// Degrees represents 65535 in the pointer.
// __builtin_divud(Long Value, Int Value) is a function of the compiler
// to do Long over Integer divisions.
PhaseInc = __builtin_divud(512000UL, Period); // Phase increment is used
// by the PWM isr (SVM)
[/B]
// This subroutine in assembly calculates the MeasuredSpeed using
// fractional division. These operations in assembly perform the following
// formula:
// MINPERIOD (in fractional)
// MeasuredSpeed = ---------------------------
// Period (in fractional)
//
__asm__ volatile("repeat #17\n\t"
"divf %1,%2\n\t"
"mov w0,%0" : /* output */ "=g"(MeasuredSpeed)
: /* input */ "r"(_MINPERIOD),
"e"(Period)
: /* clobber */ "w0");
// MeasuredSpeed sign adjustment based on current motor direction of
// rotation
if (Current_Direction == CCW)
MeasuredSpeed = -MeasuredSpeed;
// The following values represent the MeasuredSpeed values from the
// previous operations:
//
// CONDITION RPM SFRAC16 SINT HEX
// Max Speed CW -> 6000 RPM -> 0.996805 -> 32663 -> 0x7F97
// Min Speed CW -> 60 RPM -> 0.009984 -> 327 -> 0x0147
// Min Speed CCW -> -60 RPM -> -0.009984 -> -327 -> 0xFEB9
// Max Speed CCW -> -6000 RPM -> -0.996805 -> -32663 -> 0x8069
SpeedControl(); // Speed PID controller is called here. It will use
// MeasuredSpeed, RefSpeed, some buffers and will generate
// the new ControlOutput, which represents a new amplitude
// of the sinewave that will be generated by the SVM
// subroutine.
#ifdef PHASE_ADVANCE
// Calculate Phase Advance Based on Actual Speed and MAX_PH_ADV define
// The following assembly instruction perform the following formula
// using fractional multiplication:
//
// PhaseAdvance = MAX_PH_ADV * MeasuredSpeed
//
register int a_reg asm("A");
a_reg = __builtin_mpy(_MAX_PH_ADV, MeasuredSpeed, 0,0,0,0,0,0);
PhaseAdvance = __builtin_sac(a_reg,0);
#endif
MotorStalledCounter++; // We increment a timeout variable to see if the
// motor is too slow (not generating hall effect
// sensors interrupts frequently enough) or if
// the motor is stalled. This variable is cleared
// in halls ISRs
if ((MotorStalledCounter % _10MILLISEC) == 0)
{
ForceCommutation(); // Force Commutation if no hall sensor changes
// have occured in specified timeout.
}
else if (MotorStalledCounter >= _100MILLISEC)
{
StopMotor(); // Stop motor is no hall changes have occured in
// specified timeout
}
return;
}
My doubt is what is the method to be followed to arrive at PHASE_ZERO because in one of micro chip project he is using 0 and the other it is 57344?
2^16 - 2^13 = 57344
360 - 360/8 = 360 - 45 = 0 - 45 = -45
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?