Part Number: DRV8312-C2-KIT
Hey there,
I am working with the kit mentioned above and the "InstaSPIN_BLDC_GUI"-project.
I know the SpeedLoopFlag shows if the calculation of speed is finished and enables the speed-controller.
But I have a question about setting the flag:
When the SPEED_PR_MACRO is called the first time, with the code printed below, it gets the actual timestamp.
//while counting up we want positive speed
if((mod_dir1.Counter==5)&&(PreviousState==4)&&(mod_dir1.TrigInput))
{
speed1.TimeStamp = VirtualTimer;
SPEED_PR_MACRO(speed1);
SpeedLoopFlag = TRUE;
}
//while counting down we want negative speed
else if((mod_dir1.Counter==0)&&(PreviousState==1)&&(mod_dir1.TrigInput))
{
speed1.TimeStamp = VirtualTimer;
SPEED_PR_MACRO(speed1);
speed1.Speed = _IQmpy(speed1.Speed,_IQ(-1.0));
speed1.SpeedRpm = _IQmpy(speed1.SpeedRpm,_IQ(-1.0));
SpeedLoopFlag = TRUE;
}
Now inside SPEED_PR_MACRO, code is again printed below:
The OldTimeStamp gets the initialization value of the NewTimeStamp, which means 0. The NewTimeStamp gets the value of the actual timestamp.
Now the EvenPeriod is caluclated by substraction.
#define SPEED_PR_MACRO(v) \
if (v.InputSelect == 0) \
{ \
v.OldTimeStamp = v.NewTimeStamp; \
v.NewTimeStamp = v.TimeStamp; \
v.EventPeriod = v.NewTimeStamp - v.OldTimeStamp; \
\
if (v.EventPeriod < 0) \
v.EventPeriod += 32767; /* 0x7FFF = 32767*/ \
} \
\
v.Speed = _IQdiv(v.SpeedScaler,v.EventPeriod); \
\
/* Q0 = Q0*GLOBAL_Q => _IQXmpy(), X = GLOBAL_Q*/ \
v.SpeedRpm = _IQmpy(v.BaseRpm,v.Speed); \
#endif // __SPEED_PR_H__
And here I see the problem: The EventPeriod has no relation to te motor speed, when it is called the first time.
Later on, OldTimeStamp and NewTimeStamp are displaying the time the motor needs for one revolution.
This is ensured by calling the macro and creating timestamps after every revolution.
Therefore EventPeriod is calculated right from second calling of SPEED_PR_MACRO.
But when calling the first time, the EventPeriod ist just the actual value of vitual timer, which has nothing to do with motor speed.
It is a wrong value for controller.
This is why I thought the SpeedLoopFlag only should be set after second execution of PEED_PR_MACRO.
Can you please explain me the contradiction?
Thanks in advance,
Sarah