0
\$\begingroup\$

i am working on a project of my own, making a RC CAR. I want to my motor to be controlled with PWM. I understand the basics of basics for PWM but still I get confused with calculation. What is the connection between PRx and OCxR, OCxR register, what does PRx register value do to duty cycle.

I have a motor that works on a 5-9V and frequency of 5-10MHz. My dspic has 10MHz oscillator input with PLL4. In datasheet the formula for PWM period is:

enter image description here

TOSC = 1/FOSC = 1/40MHz = 0.025us

PRx = 0

PWMperiod = (PRx+1) * 4 * TOSC *(TMRprescale 1:1) = 0.1us => PWMfreq = 1/PWMperiod = 10MHz.

That is how i get 10MHz pwm frequency.

If PRx is set to 0 what will happen to the pwm signal?

\$\endgroup\$
3
  • \$\begingroup\$ Do you have any datasheets that talk about registers because I have no idea what PRx, OCxR or any of that are. \$\endgroup\$
    – user103380
    Commented Jan 23, 2019 at 21:06
  • \$\begingroup\$ Sorry I forgot here is link to datasheet: ww1.microchip.com/downloads/en/devicedoc/70138c.pdf \$\endgroup\$
    – A.F.
    Commented Jan 23, 2019 at 21:08
  • \$\begingroup\$ What makes you think that your motor works on a frequency of 5-10MHz? \$\endgroup\$
    – brhans
    Commented Jan 23, 2019 at 21:14

1 Answer 1

2
\$\begingroup\$

Here the the PWM timing diagram, from the datasheet:

enter image description here

You have two parameters, Period and Duty Cycle. To have some variability in power control, you want the Period bigger than Duty Cycle, and then change the Duty Cycle within Period. So don't set PRx to zero, set it to something more reasonable, 1024 or something. Then you will have essentially a 10-bit control range when you change Duty Cycle (whatever register is responsible for it) from 0 to 1023.

The above settings will result in 1MHz period, if the formula is interpreted correctly. In reality the 1 MHz PWM is still too high for control bridge to handle, you probably should use much longer base Period, to bring the PWM period into 5-10 kHz rate.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.