independent control of PWM in same submodule. Possible?

Discussion to talk about software related topics only.
Post Reply
chourizo
Posts: 16
Joined: Tue Apr 07, 2015 8:00 pm

independent control of PWM in same submodule. Possible?

Post by chourizo »

I am using a nano (that has 8 PWM outputs) to control 3 motors and some LEDs. But following the example (EdgeAlignedPWM and CenterAlignedPWM) I can only set all the A to a ratio and all the B to another ratio.

Is it possible to have the 8 PWMs controlled independently? I don't need different frequencies, but I do need different ratios.

Thanks.
mbrown
Posts: 61
Joined: Tue Jan 29, 2013 7:12 pm

Re: independent control of PWM in same submodule. Possible?

Post by mbrown »

I'm not exactly sure what it is you're trying to accomplish, but I'll try to elaborate on the example and the PWM behavior. For more precise information, see the MCF5441x reference manual chapter 34 Motor Control Pulse-Width Modulation (mcPWM) in your /nburn/docs/FreescaleManuals directory.

Basically, the PWM unit in the core is broken into 4 submodules. Each of these submodules has an A channel, B channel, and internal X channel that can be controlled by manipulating the prescalars for the input clocks and the on-off values of the individual signals. The example from NetBurner is just one example of how to set up the bus to control the outputs. In this case, the input clock to all the submodules are the main operating frequency inside the processor, 125MH, and the prescalar is the same 128. This means that the counter inside the module is running at about 1MHz. From there, the example primarily changes 6 values. Init is the starting count that our counter starts at, and reset (val[0]) is the value it counts to. With the default parameters given in the example, for a center-aligned PWM, these values are 0xF000 and 0x1000 or -4096 and +4096 respectively. This gives us a possible range of on and off values of 8192 or 1MHz/8192 ~= 120Hz for a PWM frequency. The other changed values are the val[2] through val[5] parameters which control when the A and B signals are turned on or off. Look at lines 272 through 278 for where all of these assignments happen. All of these values can be assigned independently on a submodule basis. So each submodule can run at it's own frequency and have it's own start and stop times. However, pairs of signals A and B will share their initial count and reset values. So a pair of signals A and B must run at the same frequency but can be turned off and on at different times.

The example is actually written to facilitate this. For instance, instead of passing in all the start and stop times as CenterAlignedPWM(pin, startCnt, reset, pwmOn, pwmOff);, you could just create new variables each pin you wish to control. For instance,

CenterAlignedPWM(31, startCnt, reset, 0x0, reset); //PWM A0
CenterAlignedPWM(33, startCnt, reset, startCnt, 0x0); //PWM B0

Now each of the pins on this submodule will come on at the opposite time of each other and stay on for half the cycle. or I could assign new variables somewhere in my code like lines 74-77 (like pwmAOn and pwmBOn, or pwmAOff and pwmBOff). As long as each pair of pins A and B share the same start and reset count, you can make the PWM signals run however you like. However, if I for instance changed the reset count on that second line of code above, I'd change it not just for pin 33, but also for pin 31.
Post Reply