• AVR Freaks

Helpful ReplyHot!QEI revolutions counting

Page: 12 > Showing page 1 of 2
Author
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
2019/05/10 05:08:13 (permalink)
5 (1)

QEI revolutions counting

I am trying to count number of revolutions using QEI in my 30F4011, encoder gives 2500PPR.
I am counting revolution on Index interrupts. In my Index ISR I increment number of revolutions when UPDWN is true and decrementing when UPDWN is False.
void __attribute__((__interrupt__)) _QEIInterrupt (void)
{
IFS2bits.QEIIF = 0; // Clear timer 1 interrupt flag
if (QEICONbits.UPDN)
    {Revs = ++Revs;
     }
if (!QEICONbits.UPDN)
    {Revs = --Revs;
}
asm ("btg LATC, #13");//kk
return;
}


 
However, if I stop rotor on a let say "forbidden" zone exact at Index Pulse and if I perform lest say continuous very small movements of the rotor(left right and so on within very few A/B pulses) then my number of revolution is increasing or decreasing wrongly. I mean I go 3 pulses right and Revolutions are incremented,  I go back 3 pulses  and then revolution are not decremented.
In such way if a motor will stop exact at index position, some vibration can increment wrongly my number of Revolutions. Sometimes it gets wrongly incremented sometimes it's wrongly decremented.
 
I am thinking if the problem could be that the Index pulse is long as 4.5 A/B pulses.
void InitQEI(void)
{
ADPCFG |= 0x0038; // Configure QEI pins as digital inputs
QEICONbits.QEIM = 0; // Disable QEI Module
QEICONbits.CNTERR = 0; // Clear any count errors
QEICONbits.QEISIDL = 0; // Continue operation during sleep
QEICONbits.SWPAB = 0; // QEA and QEB not swapped
QEICONbits.PCDOUT = 0; // Normal I/O pin operation
QEICONbits.POSRES = 1; // Index pulse resets position counter
DFLTCONbits.CEID = 1; // Count error interrupts disabled
DFLTCONbits.QEOUT = 1; // Digital filters output enabled for QEn pins
DFLTCONbits.QECK = 5; // 1:64 clock divide for digital filter for QEn
//DFLTCONbits.INDOUT = 1; // Digital filter output enabled for Index pin
//DFLTCONbits.INDCK = 5; // 1:64 clock divide for digital filter for Index
POSCNT = 0x0000; // Reset position counter
QEICONbits.QEIM = 4; // X2 mode with position counter reset by Index

//QEICONbits.QEIM1 = 0;
//QEICONbits.QEIM1 = 1;
IEC2bits.QEIIE = 1;// Enable QEI interupt

}

 
the problem is presented on video:
https://youtu.be/MnpIUXk3zZA
#1
Jim Nickerson
User 452
  • Total Posts : 6186
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: QEI revolutions counting 2019/05/10 06:50:35 (permalink)
0
I think the bug is in the bit of code that sets "QEICONbits.UPDN"
edit: unless you mean the dsPIC30F in which case why would you not just read the POSCNT register ?
post edited by Jim Nickerson - 2019/05/10 06:57:22
#2
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: QEI revolutions counting 2019/05/10 07:22:49 (permalink)
0
Hi Jim, I will check QEICONbits.UPDN.
I do not understand the question.
 
My aim is to have absolute position information (Servo application). The idea is to increment/decrement integer number of revolution based on the Index Interupt. Actual absolute position information would be as:
Position= (Revs x 2500) + POSCNT.
2500 is no of pulses per one rev.
post edited by _dex - 2019/05/10 07:25:04
#3
Jim Nickerson
User 452
  • Total Posts : 6186
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: QEI revolutions counting 2019/05/10 07:27:32 (permalink)
0
That is true if the POSCNT is set to reset to zero on each index as you have.
Which particular encoder might you have ?
 
 
#4
Jim Nickerson
User 452
  • Total Posts : 6186
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: QEI revolutions counting 2019/05/10 07:42:58 (permalink)
0
I see this in the manual, maybe yours is a similar problem 

Attached Image(s)

#5
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: QEI revolutions counting 2019/05/10 07:53:28 (permalink)
5 (1)
I will check this suggestion.
The encoder is built in in my PMSM motor, I have very poor datasheet. I can not attach pdf here, due to forum 200kB limit.
Motor:
ZLAC60ASM200-36-1250/2500
 
http://zlingkj.cn/Upload/soft/%E4%B8%AD%E8%8F%B1%E7%A7%91%E6%8A%80%E5%8D%B0%E5%88%B7%E7%A1%AE%E5%AE%9A%E7%89%88.pdf

post edited by _dex - 2019/05/10 08:14:38
#6
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: QEI revolutions counting 2019/05/10 08:22:12 (permalink)
5 (1)
JANickerson
That is true if the POSCNT is set to reset to zero on each index as you have.
...

Thats true in one direction(should be).
If you perhaps looked at the video on youtube POSCNT is reset always after Index(2500).
I see now possible problem to absolute position counting. But this has no influence on the main problem (counting of integer number of revolutions)
If I go forwards, Index Pulse reset the POSCNT to 0000, fine.
But, if I go backwards the POSCNT is changing in steps like 0001,0000 to FFFF .
And this should be 0x09C3 (2500 PPR)
How to get around that?
I have an idea to just set it to 0x09C3(2500) after Index Interrupt and when one UPDN is 0 (backwards rotation). Perhaps there is a smarter solution.
 
post edited by _dex - 2019/05/10 08:33:10
#7
Jim Nickerson
User 452
  • Total Posts : 6186
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: QEI revolutions counting 2019/05/10 08:24:17 (permalink)
0
If the pdf is small enough add ".txt" to the file name so the forum will allow the attachment
The download of the pdf fails for me from this page

Attached Image(s)

#8
Jim Nickerson
User 452
  • Total Posts : 6186
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: QEI revolutions counting 2019/05/10 08:28:33 (permalink)
0
even with the direct link I can not get the pdf.
Does it have a graphical depiction of the A, B, Index pulse ?
#9
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: QEI revolutions counting 2019/05/10 08:42:01 (permalink)
0
The pdf was divided to 4 parts used total Commander and the extension changed to txt.
Now to combine you should cut txt extension from the file name and use "Combine" function in total Commander.
 
Alternative way is to changed name of 001 file to xxxx.pdf and the copy 002 to the same name xxxx.pdf and when system asks if overwrite a file just to select append(at the end of existing file).
#10
Jim Nickerson
User 452
  • Total Posts : 6186
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: QEI revolutions counting 2019/05/10 08:44:48 (permalink) ☄ Helpfulby _dex 2019/05/11 09:20:49
5 (1)
I looked at the video.
Maybe you could use MAXCNT set to 2500 ?
Can you attach a logic analyzer to capture A, B, Index Up/Down etc.
#11
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: QEI revolutions counting 2019/05/10 08:46:03 (permalink)
5 (1)
Easiest way
https://we.tl/t-O8wGYB9I0G
I have sent it to free host.
#12
Jim Nickerson
User 452
  • Total Posts : 6186
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: QEI revolutions counting 2019/05/10 08:58:52 (permalink)
5 (1)
ok, I saw the pdf on your free host.
It seems to indicate a resolver output, I assume that is from the motor to the driver.
There does not seem to be any info on the driver though I do not read Chinese.
I think a logic analyzer might be the only way to determine the relationship of the index and when it changes with respect to A and B during reversal.
 
#13
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: QEI revolutions counting 2019/05/10 09:08:22 (permalink)
5 (1)
So here we have screens from scope.
Red is always Index(Z).
A stands for QEIA, B for QEIB; both always Yellow.
post edited by _dex - 2019/05/10 09:09:29

Attached Image(s)

#14
Jim Nickerson
User 452
  • Total Posts : 6186
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: QEI revolutions counting 2019/05/10 09:27:05 (permalink) ☄ Helpfulby _dex 2019/05/11 09:21:01
5 (1)
I might think about using MAXCNT to reset the position Counter like in 16.5.2

 
 

Attached Image(s)

#15
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: QEI revolutions counting 2019/05/10 09:33:27 (permalink)
5 (1)
Ok I will try, I was thinking about that as well. We will see.
#16
Jim Nickerson
User 452
  • Total Posts : 6186
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: QEI revolutions counting 2019/05/10 09:38:03 (permalink)
5 (1)
On your 2 channel scope if it has external trigger you might trigger on index and capture the relationship of A and B
#17
1and0
Access is Denied
  • Total Posts : 9612
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: QEI revolutions counting 2019/05/10 10:29:41 (permalink)
5 (1)
_dex
 

if (QEICONbits.UPDN)
    {Revs = ++Revs;
     }
if (!QEICONbits.UPDN)
    {Revs = --Revs;
}


I believe these Revs statements are undefined behaviors.
#18
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: QEI revolutions counting 2019/05/10 11:09:17 (permalink)
0
JANickerson
On your 2 channel scope if it has external trigger you might trigger on index and capture the relationship of A and B

Jim,
This looks quite normal 90 degree out of phase, as in pictures bellow. It was triggered on index Z (external).
QEA is RED
QEB is Yellow.
 
post edited by _dex - 2019/05/10 11:13:04

Attached Image(s)

#19
_dex
Starting Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: QEI revolutions counting 2019/05/10 11:16:34 (permalink)
0
1and0

if (QEICONbits.UPDN)
    {Revs = ++Revs;
     }
if (!QEICONbits.UPDN)
    {Revs = --Revs;
}

I believe these Revs statements are undefined behaviors.

 
Hi 1and0, what do you mean?
Revs are declared just after configuration bits:
int Revs = 0;
 
I suppouse the problem could be with UPDN marking. I am really not sure what is a UPDN mark when there is a very small transition as for example from 0000 to FFFF and otherwise. Just within one step. I will try to print out UPDN bit somehow to check correct recognizing of the direction.
post edited by _dex - 2019/05/10 11:27:12
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5