EmbeddedRelated.com
Forums

Encoder Integration

Started by Paul Williams July 31, 2006
I am having trouble integrating an encoder into my code for a MC9S12D64. I
am using ICC12 and am using a combination of C and assembly.

I have tried using a timer interrupt with a table lookup and have got less
than adequate results. Ie < 20 Hz

I am looking to get a quadrature encoder input of approx 2Khz.

My question is will a HCTL 2020 or equivalent using a PWM output (8Mhz CPU
CLK) from the MCU be able to cope with the sample rate and evaluation of the
position adequately to be able to update a fuzzy control algorithm to
control the position of a servo motor

Thanks for any advice

Paul
Yes. My inverted pendulum fuzzy routine executes in 10.5usec at 24Mhz
(I'm using a C32). A 2KHz servo rate would uses only approx. 2% of
processor time. Since the fuzzy ops are interruptible (worst case
appears to be 8 cycle loop inside WAV) it is possible to use the input
timer interrupts for the encoder - no encoder chip is required if the
max rpm is reasonable.

If you check all edges (max resolution) then the interrupt rate for a
400 count encoder at 5 rev/sec is 8000 interrupts/sec or 125usec. My
input timer interrupts execute in 1.75/1.83 usec at 24MHz depending on
branching. This leaves a lot of time per interrupt for fuzzy algo and
pid setup. I've not spent the time to calculate the max rpm possible
since the system is fast enough for my requirements (only so many hours
in a life).

-rob

Paul Williams wrote:
> I am having trouble integrating an encoder into my code for a MC9S12D64. I
> am using ICC12 and am using a combination of C and assembly.
>
> I have tried using a timer interrupt with a table lookup and have got less
> than adequate results. Ie < 20 Hz
>
> I am looking to get a quadrature encoder input of approx 2Khz.
>
> My question is will a HCTL 2020 or equivalent using a PWM output (8Mhz CPU
> CLK) from the MCU be able to cope with the sample rate and evaluation of the
> position adequately to be able to update a fuzzy control algorithm to
> control the position of a servo motor
>
> Thanks for any advice
>
> Paul
>
>
Thanks for the help

I will give it a go using the edge detection. I was previously using a Timer
7 interrupt and a table lookup for the encoder state. But as you have stated
the edge detection should be able to handle the encoder adequately.

Thanks for the help
Paul

-----Original Message-----
From: 6... [mailto:6...] On Behalf Of
Rob Milne
Sent: Tuesday, 1 August 2006 1:04 AM
To: 6...
Subject: Re: [68HC12] Encoder Integration

Yes. My inverted pendulum fuzzy routine executes in 10.5usec at 24Mhz
(I'm using a C32). A 2KHz servo rate would uses only approx. 2% of
processor time. Since the fuzzy ops are interruptible (worst case
appears to be 8 cycle loop inside WAV) it is possible to use the input
timer interrupts for the encoder - no encoder chip is required if the
max rpm is reasonable.

If you check all edges (max resolution) then the interrupt rate for a
400 count encoder at 5 rev/sec is 8000 interrupts/sec or 125usec. My
input timer interrupts execute in 1.75/1.83 usec at 24MHz depending on
branching. This leaves a lot of time per interrupt for fuzzy algo and
pid setup. I've not spent the time to calculate the max rpm possible
since the system is fast enough for my requirements (only so many hours
in a life).

-rob

Paul Williams wrote:
> I am having trouble integrating an encoder into my code for a MC9S12D64. I
> am using ICC12 and am using a combination of C and assembly.
>
> I have tried using a timer interrupt with a table lookup and have got less
> than adequate results. Ie < 20 Hz
>
> I am looking to get a quadrature encoder input of approx 2Khz.
>
> My question is will a HCTL 2020 or equivalent using a PWM output (8Mhz CPU
> CLK) from the MCU be able to cope with the sample rate and evaluation of
the
> position adequately to be able to update a fuzzy control algorithm to
> control the position of a servo motor
>
> Thanks for any advice
>
> Paul
>
>