 |
 |
| View previous topic :: View next topic |
| Author |
Message |
carl
Joined: 06 Feb 2008 Posts: 240 Location: Chester
|
|
Posted: Sat Jan 31, 2009 6:56 am |
|
|
Tried it with 5000ppr encoder and it displays 5000.
Thankyou Ttelmah for all your help.
Do you think I will be able to also do the RPM with the QEI at the same time to get the speed.
Also do you know the max input voltage to the input pins for these signals - is it 5V or can I put upto 24V into them.
Best Regards
Carl |
|
 |
Ttelmah Guest
|
|
Posted: Sat Jan 31, 2009 2:13 pm |
|
|
Depends how often you want to update the RPM, and the accuracy needed.
You will get a much faster update, by simply timing the interval between two changes on the QEI counter. You can reciprocate this to give speed. Alternatively, just setup a timer to update at some nice interval. Pulses per interval of time, converts easily into RPM.
The counter will work fine, but if you start doing much else, you will need to consider timings or edges may get missed.
Best Wishes |
|
 |
carl
Joined: 06 Feb 2008 Posts: 240 Location: Chester
|
|
Posted: Sat Jan 31, 2009 3:04 pm |
|
|
Hi Ttelmah,
thanks again for all your help. The update can be every few revolutions. The accuracy is +/_10rpm where the range is 1 to 6000rpm.
I will play around with it.
Thanks again
Carl |
|
 |
wikijoya
Joined: 18 Dec 2011 Posts: 1 Location: Pakistan
|
| Understanding how to setup QEI module |
Posted: Sun Dec 18, 2011 9:17 am |
|
|
| Kenny wrote: | The basic test code below is for the 18F2331 in QEI mode with the encoder index
to clear the counter. It should work for the 18F4431.
Your application could be built on this and possibly include the interrupts for
detecting the index and change of direction.
The CCS version was 3.249. This version also has support for the interrupts.
Note that for the counter to be reset, the encoder must move to give a
transition on one of the encoder phases while the INDEX is high.
The position counter is not buffered and this can cause a problem:
http://forum.microchip.com/tm.aspx?m=199253&mpage=2
| Code: |
#include <18F2331.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP,PWMPIN
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
// Definitions
#byte QEICON = 0xFB6 // Quadrature Encoder Interface control register
#byte DFLTCON = 0xF60 // Digital filter control register
#byte POSCNTH = 0xF67 // Position register high byte
#byte POSCNTL = 0xF66 // Position register low byte
union
{
int8 bytes[2];
int16 word;
} position_union;
void main()
{
// QEICON setup:
// Velocity mode disabled, no overflow or underflow error bit,
// UP/DOWN 1 = Forward, x4 QEI mode, INDX to clear count.
QEICON = 0xB4;
// Digital filter setup:
// Enabled for INDX, PHA, PHB. Tcy/16
DFLTCON = 0x3B;
while(1)
{
position_union.bytes[0] = POSCNTL;
position_union.bytes[1] = POSCNTH;
// Workaround for hardware bug caused by lack of buffering
if ((position_union.bytes[0] == 0) || (position_union.bytes[0] == 0xFF))
{
position_union.bytes[0] = POSCNTL;
position_union.bytes[1] = POSCNTH;
}
printf("position = %5lu\n\r",position_union.word);
delay_ms(500);
}
}
|
|
I want to understand the above code. Please help me to understand it.
Q1- In the definitions section why have you initialized the QEICON and DFLTCON with FB6 and FB0?
Q2- In the second last line "delay_ms(500)", why have you added delay statement? Is this because of some issue with LCD or any other reason?
Please help me. I am waiting for reply.
 |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9658 Location: Greensville,Ontario
|
|
Posted: Sun Dec 18, 2011 9:26 am |
|
|
answers...
q1) 'normal' way to directly access PIC registers...
q2) 'updates' the LCD at a 2Hz rate,easy on the eyes to see. Could have been 1 HZ, 1/4Hz....it's just a test program..... |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|