Shop OBEX P1 Docs P2 Docs Learn Events
PWM - multiple pins, one cog — Parallax Forums

PWM - multiple pins, one cog

PhilldapillPhilldapill Posts: 1,283
edited 2008-03-19 23:22 in Propeller 1
I'm building a CNC machine and would like to be able to adjust the current through the motors using PWM, rather than using a shunt. Ok, I'm rewriting this to make it more clear. Basically, I will be changing what pins are on. This will only be 4 pins that will go to a stepper controller that will step the motor. The pins that are high will change, but I want to be able to use PWM on the ones that are high. I'm not looking for any super high freq. PWM, but my motors will be stepping at 2000steps/sec. From that, I figure I will need to have the PWM about 50-100 times that. Let's say 100-200khz PWM signal? I'm guessing this needs to be done in assembly, which I know very little of. Right now, I just want to know if it's possible to use PWM on multiple pins, while their states will be changing between pulses(possibly). Perhaps in the code, I will only focus on pins 0-3, and consecutively, go through the pins 1 by 1, check if they are on/off, and toggle them accordingly, and reloop.

Suggeestions?

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-19 23:22
    One suggestion is to put an inverter on the outputs. This will allow other cogs to turn the output of the inverter off by setting the pin high. Would you be better off just putting a mosfet in the ground side of your driver? This means you would only need to PWM one pin instead of four.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-19 23:22
    You can have a cog doing the PWM with its output being a bitmask for the 4 pins and this bitmask changes from all one bits to all zero bits with the PWM timing. The bitmask is AND'd with a bitmask that controls the stepping action for the speed and direction you want. The PWM routine simply does the AND and copies the result into OUTA. There's probably plenty of time to do both operations in the same cog, but that does make the code more complicated.
Sign In or Register to comment.