Quadrature
Posted: Mon Nov 19, 2012 2:19 pm
I have been searching the web looking for examples to try to implement the QEI functions.
The chunk of code below, gets you the encoder position and was mostly copied from a message on the ArmExpress Site.
The QEICAP in the Print Routine will report the number of pulses seen in the Time period specified in QEITIME and QEILOAD.
#include "LPC17xx.bas"
' Quadrature Encoder Interface Testing Program 7/19/12 DG
DIM POSITION As Integer
Dim RPM as Integer
SUB INIT
SCB_PCONP = SCB_PCONP or (1<<18) 'enable QEI bit in power/clock register (PCONP)
PCB_PINSEL3 = PCB_PINSEL3 or (1<<8) 'Set pin P1.20 mode for PH A
PCB_PINSEL3 = PCB_PINSEL3 or (1<<14) 'Set pin P1.23 mode for PH B
QEICON = QEICON or 1 'clear position
QEIMAXPOS=256 'The number of Pulses for one revolution of the encoder.
QEITIME=10000000 'Initial Sample time for
QEILOAD=10000000
ENDSUB
MAIN:
INIT
Do
POSITION = QEIPOS
Print POSITION,QEICAP
WAIT (100)
Loop
END
I'm trying to find the RPM of the encoder shaft, the documentation below describes a Variable PCLK.
My question today is:
Is there a variable in LPC17xx.bas that contains this clock value?
RPM = (PCLK * QEICAP * 60) ÷ (QEILOAD * PPR * Edges)
where:
• PCLK is the peripheral clock rate for the QEI block. See Section 4.7.3 for more on the
possibilities for PCLK).
• QEICAP is the captured velocity counter value for the last velocity timer period.
• QEILOAD is the velocity timer reload value.
• PPR is the number of pulses per revolution of the physical encoder used in the
application
• Edges is 2 or 4, based on the capture mode set in the QEICON register (2 for
CapMode set to 0 and 4 for CapMode set to 1)
The chunk of code below, gets you the encoder position and was mostly copied from a message on the ArmExpress Site.
The QEICAP in the Print Routine will report the number of pulses seen in the Time period specified in QEITIME and QEILOAD.
#include "LPC17xx.bas"
' Quadrature Encoder Interface Testing Program 7/19/12 DG
DIM POSITION As Integer
Dim RPM as Integer
SUB INIT
SCB_PCONP = SCB_PCONP or (1<<18) 'enable QEI bit in power/clock register (PCONP)
PCB_PINSEL3 = PCB_PINSEL3 or (1<<8) 'Set pin P1.20 mode for PH A
PCB_PINSEL3 = PCB_PINSEL3 or (1<<14) 'Set pin P1.23 mode for PH B
QEICON = QEICON or 1 'clear position
QEIMAXPOS=256 'The number of Pulses for one revolution of the encoder.
QEITIME=10000000 'Initial Sample time for
QEILOAD=10000000
ENDSUB
MAIN:
INIT
Do
POSITION = QEIPOS
Print POSITION,QEICAP
WAIT (100)
Loop
END
I'm trying to find the RPM of the encoder shaft, the documentation below describes a Variable PCLK.
My question today is:
Is there a variable in LPC17xx.bas that contains this clock value?
RPM = (PCLK * QEICAP * 60) ÷ (QEILOAD * PPR * Edges)
where:
• PCLK is the peripheral clock rate for the QEI block. See Section 4.7.3 for more on the
possibilities for PCLK).
• QEICAP is the captured velocity counter value for the last velocity timer period.
• QEILOAD is the velocity timer reload value.
• PPR is the number of pulses per revolution of the physical encoder used in the
application
• Edges is 2 or 4, based on the capture mode set in the QEICON register (2 for
CapMode set to 0 and 4 for CapMode set to 1)