piclist 1999\08\17\003903a >
Thread: hardware PWM output pin
www.piclist.com/techref/io/pwm/index.htm?key=pwm
flavicon
face BY : Mark Willis email (remove spam text)



Bit-banging it is the way I'd go, then.  Probably run 4 state machines
in one (something like this quick hack of a piece of protocode):  Here,
PWM1 is to be on 10 of 12 cycles, PWM2 12 of 40, etc.  (Yeah, it's not
optimized or anything, and it's untested.  So flame me <G>)  One obvious
optimization:  At runtime, if ratio can have common factors thrown out,
do so (i.e. case # 1 here would become 5 of 6, # 2 would become 3 of 10,
# 3 1 of 4, and # 4 stay the same.)

Bool PWM1State = False, PWM2State = False;
Bool PWM3State = False, PWM4State = False;
Int PWM1On = 10,  PWM1Cycles = 12,  PWM1Counter = 0;
Int PWM2On = 12,  PWM2Cycles = 40,  PWM2Counter = 0;
Int PWM3On = 15,  PWM3Cycles = 60,  PWM3Counter = 0;
Int PWM4On = 13,  PWM4Cycles = 20,  PWM4Counter = 0;

While (True) do
{
 PWM1State = (PWM1Counter < PWM1On);
 PWM2State = (PWM2Counter < PWM2On);
 PWM3State = (PWM3Counter < PWM3On);
 PWM4State = (PWM4Counter < PWM4On);
 SetPWMPins (PWM1State, PWM2State, PWM3State, PWM4State);
 PWM1Counter++;  If (PWM1Counter >= PWM1Cycles) PWM1Counter = 0;
 PWM2Counter++;  If (PWM2Counter >= PWM2Cycles) PWM2Counter = 0;
 PWM3Counter++;  If (PWM3Counter >= PWM3Cycles) PWM3Counter = 0;
 PWM4Counter++;  If (PWM4Counter >= PWM4Cycles) PWM4Counter = 0;
}

 Mark

Andre Abelian wrote:
>
> Hi to all engineers.
>
> I was wondering if possible to change  hardware PWM  output pin.
> In my project I need 4 outputs to turn each one on at different
> duty cycle ( software PWM works ) but hardware PWM seams like
> I am stock on one pin any idea ?
>
> Andre

<37B8E66F.15D842E6@nwlink.com> 7bit

See also: www.piclist.com/techref/io/pwm/index.htm?key=pwm
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) hardware PWM output pin

month overview.

new search...