PWM on multiple pins (with different frequencies)

I have a fairly silly question: how would one set different PWM frequency on different ports?
I need to pulse two separate steppers at different speeds, but when I do this (blinking LEDs for testing):

            PWM left = new PWM((PWM.Pin)FEZ_Pin.PWM.Di5);
            PWM right = new PWM((PWM.Pin)FEZ_Pin.PWM.Di6);

            left.Set(3, 50);
            right.Set(5, 50);

LED on pin 6 blinks, LED on pin 5 is on. If I choose 2 and 4 for feq, same thing happens, but 4 and 2 behaves different: both LEDs blink at 2hz but led on pin 5 has 1/2 the duty cycle.

Is this supposed to happen?
If yes, is there a way to use hardware WPM in any other way (I don’t want to waste CPU cycles on PWM)?

Thank you

P.S. I apologize if this is a no-brainer quetion… I tried searching the forum, eBook and FAQ but didn’t find any solutions…

I’m afraid you can’t have 2 different PWM frequencies. Only different duty cycles.
PWM on USBizi shares the same clock.

Take a look at the eBook’s section on PWM, see page 55 (Chapter 12: Pulse Width Modulation)

As Rimvis has said, you cannot have different frequencies, however duty cycles are independent. So if you wanted to have one run twice as fast as the other you might have a frequency of 10, with one having a duty cycle of 25 and the other of 50. This would mean you have one running 25% of the time and the other running 50% of the time.

There is also the option to just control the length of the pulses if you wish to do it that way.

Also look into output compare

MarkH, he wants to drive steppers, so I guess he allways want 50% duty cykle, and change speed with frequency (stepper boards usualy uses one pin for direction and one for step triggering).

I think, I would try 2 software timers.

The steppers I’m using will have microstepping, so 400 steps per RPM, at 100 RPM we are talking 666 hz (oops). Can I count on that frequency being reliably accurate using output compare?
Also, so I understand this better: output compare is implemented in software, or is there a hardware level that will take some workload off the CPU?

Thak you

That wasn’t Gus answering :slight_smile:

Now it is Gus :wink: I am not a steppers expert but from what I know is that steppers need a lot of speedy AND simultaneous IO which is the weakest point of NETMF. output compare helps in generating waveforms on an IO but with stepper you need multiple IOs and tight control, probably real time.

so, to use stepper “properly” you will need a little 8-bit micro that would be a “stepper controller” where FEZ can command it to do the work and then this little chip will handle do the rest.

Again, we are talking about steppers not servos right?

If a stepper driver chip is used, then the stepper motor can be driven by 2 pins. One pin will control the direction and the other pin will control the stepping. The output compare can be thought of as a fancy frequency out command that some micro controller languages have.
So the output compare will work if the proper stepper driver is used. This will not work if complex stepper control is needed. Say a pick and place arm wants to go an x distance with such an acceleration and velocity and stop with a de-acceleration profile. If very precise control is needed then there are motion control servos that include the controller. The fez could be used to send commands to it over several available buses. A driver like this would work

That’s where I was leaning, actually, so you confirmed my thoughts. (Although I like little 16-bit micro, MSP430 :slight_smile: ).

I’m not running a PNP machine, but would like to go x distance with certain acceleration and deceleration… I’m using Sparkfun’s EsyDriver stepper driver for this project, and I’m using two wires per motor (three actually, including “enable”). Motion control servoce are “out of my budget”, but as a former PNP machine operator/technician, I know here you’re going :slight_smile:

Thank you for your suggestions