working on quadrature encoders of MPC5604P any sample code for capture and diection?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

working on quadrature encoders of MPC5604P any sample code for capture and diection?

Jump to solution
1,606 Views
vramalingam
Contributor II

Working on with quad encoders. used A[0] and A[1] pins. I kept ctrl register as 8001. still I counter is not counting.. I also want direction register to set.  any sample code or Application note will be helpful.

Labels (1)
1 Solution
1,349 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

See attached example testing quadrature count mode of the eTimer module.

It sets some eTimer channels and FlexPWM to generate quadrature signals and another eTimer channel for a Quadrature count mode.

BR, Petr

View solution in original post

3 Replies
1,349 Views
vramalingam
Contributor II

Hi petr,

   Thanks for reply.. Now counter is running..

But how to find speed and direction. Now Encoder input is applied with train of pulses in A[0] and with 90deg offset with A[1]. With this how to find speed and direction. Actually now I can see counter running and it keeps reducing. Some calculation need to be done?

Regards

ram

0 Kudos
1,349 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi Ram,

The speed measuring method depends on sensor signal (frequency range). The interrupt can be used, but it is not sufficient for high rates. You can also use the capture feature then read the period upon needs, etc. It is so application dependent I think.

 

There is no “flag” which say you if counter is counting up/down in Quadrature count mode. The easiest way how to get the direction is to take two counter samples and calculate the difference.

But you can also do it in HW way; set the output mode for the counter which asserts OFLAG when counting up and cleares when counting down. You can use this output as secondary input for other channel within module. If this channel will be stopped, then the CTRL2[INPUT] bit will reflect that direction. If this channel will be started you can also detect the OFLAG edge and generate interrupt on direction change.

BR, Petr

1,350 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

See attached example testing quadrature count mode of the eTimer module.

It sets some eTimer channels and FlexPWM to generate quadrature signals and another eTimer channel for a Quadrature count mode.

BR, Petr