Shop OBEX P1 Docs P2 Docs Learn Events
encoder counts and PWM frequency — Parallax Forums

encoder counts and PWM frequency

fang-weifang-wei Posts: 7
edited 2007-05-13 23:00 in Robotics
Hi!!
I have a new challenge [noparse]:)[/noparse]

I want to control the speed of the motor through a microcontroller and the thing is that I am not sure at what frequency should I work to generate the PWM signal.
The encoder of the motor makes 360 counts / revolution at a speed of 170 rpm.
The encoder has two output signals (in quadrature) and each of those are three pulses / revolution
for each shaft of the motor we obtain 12 pair of signals ...

now what I did was:

170 rpm / 60 = period 1
period 1··* freq = 360 counts ; f = 127 Hz

if I assume that it is correct I just have the possibility of using f = 122 Hz (after scaling the fcpu) and it would turn on a wrong number of counts ... I am a bit confussed ...

What do u think about it? Am I wrong? rolleyes.gif

I would be very thankful for any piece of advice

Have a good weekend

fang-wei

Comments

  • LawsonLawson Posts: 870
    edited 2007-05-12 16:57
    Huh? it looks like you're making things harder for yourself than it needs to be. PWM frequency for driving a motor is generally chosen based only on the motor and driver circuitry used. (5-20kHz are pretty common frequencies.)

    are you using two encoders to measure the motor's speed? why? (I see one 360 [noparse][[/noparse]count/rev] and one 3 [noparse][[/noparse]count/rev] encoder listed)

    also, the math is a bit off. I'd recommend keeping units with everything and making sure the units cancel into what you're looking for.

    170 [noparse][[/noparse]rev/min] * 1/60 [noparse][[/noparse]min/sec] = 2.833 [noparse][[/noparse]rev/sec] aka [noparse][[/noparse]Hz]

    The period of this rotation is then 1/2.833 [noparse][[/noparse]sec/rev] or 0.3529 [noparse][[/noparse]sec/rev]

    assuming a 360 [noparse][[/noparse]count/rev] quadrature encoder with 4x decoding. (so decoded encoder resolution is 360*4 = 1440 [noparse][[/noparse]count/rev] )

    2.833 [noparse][[/noparse]rev/sec] * 1440 [noparse][[/noparse]count/rev] = 4079.5 [noparse][[/noparse]counts/sec]

    Hope this helps,
    Marty
  • fang-weifang-wei Posts: 7
    edited 2007-05-13 09:20
    Ahaaaaaa

    I see... thanks Marty [noparse]:)[/noparse], and the 4x decoding is because you have to count the rise and fall flanks of each output signal?

    So, the specs from the vendor say that the resolution is 360 counts / revolution. (The other information was that there are 3 pulses per shaft and per signal)

    So, now to generate the PWM signal with the microcontroller, I could scale the frequency till 4 KHz. In order to measure the position of the motor, could be acceptable to say that each 1412 counts the motor makes a complete shaft?

    maybe I am still making it harder than it is ...

    Thanks

    Have a nice day

    fang-wei
  • LawsonLawson Posts: 870
    edited 2007-05-13 23:00
    yes, the 4x decoding is done by XOR'ing the two quadrature signals and counting edges.··It's not really necessary, but improves the precision of·the system.·
    fang-wei said...
    So, now to generate the PWM signal with the microcontroller, I could scale the frequency till 4 KHz. In order to measure the position of the motor, could be acceptable to say that each 1412 counts the motor makes a complete shaft?
    ·Ok, now that you can read the motor speed with the encoder,· (aka how many encoder counts per second) you need a servo loop to control the motor.· First find the motor's speed error.· (i.e. subtract the current speed from the desired speed.· be shure to use the same units.)· Next, multiply this error by some constant, this is the manipulation.· (this constant depends on the specific system and is usually found by experimentation, or careful modeling)··Finally, the·manipulation is used to determine how much power is sent to the motor.· In other words the duty cycle of the·PWM for the motor should be proportional to the manipulation that was calculated from the motor's speed error.·

    I hope this helps.· I've just gone over the bare basics.· Try this stuff out, the information on more sophisticated servo loops is just a web search away.· (Google and Wikipedia is your friend yeah.gif )

    best of luck,
    Marty
Sign In or Register to comment.