Quadrature encoder code question

Status
Not open for further replies.

yzou_ua

Member level 5
Joined
Nov 5, 2008
Messages
92
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,869
After init etc., I calculate the speed in following way. Could someone help me find anything wrong here?? Buz the measured result varies time by time(when running the motor at constant speed).

while(1)
{

if(TMR3<23000)
{
if(POS1CNT=0)
{CntsRev=0;
CntsRev+=1;}

Cnts=POS1CNT+(CntsRev-1)*MaxCnt; // The total pulse number during above time period

Speed_rad=2*3.14159*Cnts/ppr/TMR3; // Speed in rad/s
}
}
 

Is this step correct??? {CntsRev=0;
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…