Author Topic: PWMs in PIC18F4550  (Read 1029 times)

0 Members and 1 Guest are viewing this topic.

Offline extreme.alyTopic starter

  • Jr. Member
  • **
  • Posts: 47
  • Helpful? 0
PWMs in PIC18F4550
« on: March 13, 2013, 05:48:43 AM »
Hello,

I recently bought a new microcontroller, a PIC18F4550, and I can't really understand the datasheet properly. I want to know that how many PWMs output I can have from this PIC. I think there are 1 or 2. But it's very confusing, the ECCP, EPWM :s

Can I somehow control two motor controllers using the PWMs in this microcontroller?

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,343
  • Helpful? 81
Re: PWMs in PIC18F4550
« Reply #1 on: March 13, 2013, 11:10:02 AM »
The data sheet, on page 143, says that there are two PWM modules (CCP or ECCP) which means you can separately control two PWM outputs. If your motor controllers accept PWM input, then yes, you should be able to control two motor controllers with those outputs.
Also, the chip seems to be available in a low-pin-count and a high-pin-count version; I don't know if there are any pin sharing problems in the low-pin-count version, nor do I know which version you actually got.
Hope this helps!

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,935
  • Helpful? 98
Re: PWMs in PIC18F4550
« Reply #2 on: March 13, 2013, 07:50:15 PM »
What jwatt said plus:

Microchip has a PIC18 family reference manual available on their web site that explains the PICs in slightly more detail.
They also have many App Notes on how to use PICs for many differnt tasks including PWM motor speed control. Do look these up and read.
There is also a PIC user's forum that has lots of info, discussions, examples from PIC users. When you get really stuck trying to understand a PIC feature this is a good place to ask.

As to the PWM (CCP module) in the PIC18F4550. Section 15 of the data sheet exalians how to use the PWM. Do note that they use names such as "CCPRxL" (see Figure 15-3) for the PWM control registers. The "x" can be a '1' or a '2' for the two CCP modules (two PWM outputs) so there are CCPR1L and CCPR2L registers. Study the register map in Table 5-1 to see all of these registers.

Next is to note that both CCP modules (PWM outputs) use the same timer to set the PWM period (frequency). This means that both PWM outputs are the same period but their duty cycles are independently controlled. This works perfectly to control the speed of two motors (through H-bridges) independently.
So TMR2 and PR2 set the PWM period whereas CCPRxL and CCPxCON<4:5> control PWM output duty cycle.

Offline extreme.alyTopic starter

  • Jr. Member
  • **
  • Posts: 47
  • Helpful? 0
Re: PWMs in PIC18F4550
« Reply #3 on: March 13, 2013, 10:20:46 PM »
Ok a sigh of relief! :D Thank you :)

Ok, now I believe that I can make my motor controllers work on this PIC, but I'll only be able to make them work on PWM in one direction... Because each motor controller circuit will have only one PWM and one regular digital signal.

To make my motor turn CW direction, I'll set the PWM duty cycle (to like 50% or what-so-ever) and LOW the other signal. Motor goes CW direction with 50% duty cycle.
- What should I do for CCW direction?

I have two possibilities in my mind:
1. Turn the PWM duty cycle to zero and set the other pin to HIGH. (Expectation: Motor goes CCW direction in full speed.)
2. Or keep the PWM cycle to 50% and set the other pin to HIGH. (Expectation: Motor goes CCW direction with 50% duty cycle.)
- Is this even possible?

Please suggest me if there is any other way to accomplish what I need.

Thank you :)

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,343
  • Helpful? 81
Re: PWMs in PIC18F4550
« Reply #4 on: March 13, 2013, 11:11:54 PM »
There are two ways of doing this.

If you use a motor controller (not just an H-bridge,) then the input is typically "direction" and "enable." If you run the "enable" pin on PWM, the "direction" pin lets you set the direction.

Another option is to run the PWM really fast (like 20 kHz or faster) and use a very fast H-bridge, and make it switch entirely between forward and backward. You have to make sure you have the right overshoot protection delay in your MOSFET drivers! What this ends up doing is treat the motor as an inductive filter. When the duty cycle is 50%, basically no current flows through the motor, and the robot stands still and draws very little power. When the duty cycle is 75%, the motor will be turning forward at half force; at 25%, backwards at half force; 0% and 100% are full-back and full-forward respectively.

Offline voodoo

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: PWMs in PIC18F4550
« Reply #5 on: March 14, 2013, 09:41:07 PM »
Hi I use a 4550 in my robot called Irowe 4550. I have a header file that I run seperately from my main code & just include it. All you have to do is put it in your project folder. If you want the code for pwm for the 18f4550, then pm me & I can send you the code. Also its eary to selevt your speed! ;)

 


Get Your Ad Here

data_list