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



Scott Dattalo wrote:
> On Tue, 17 Aug 1999, Andre Abelian wrote:
>
> > Date: Tue, 17 Aug 1999 09:00:50 -0700
> > From: Andre Abelian <spamBeGoneengelecEraseMEspamearthlink.net>
> > To: RemoveMEPICLISTKILLspamspamEraseMEMITVMA.MIT.EDU
> > Subject: Re: hardware PWM output pin
> >
> > Sorry  Mark I am not good at C can you convert it to assembly.
>
> Here's a routine I posted about a year or so ago that implements in
> assembly mostly of what Mark writes in C. The only difference is that
> these multiple pwms are synchronized. That is, they all turn on at the
> same time but turn off at the time defined by the pwm pulse width. If you

Quite do-able in my QuickHack code, just set the PWM{i}Cycles numbers
all to the same in my routine <G>  Probably a better way to do it in
Assembly, here, and you save 3 Int's worth of storage - I did say it
wasn't optimized <G>.  I'll also add that it's sometimes good to use a
comparison on PWM'ing, to a variable (like my PWM1On) instead of to a
constant (for example: if you're trying to PWM 3.3VDC from 5VDC off a
PIC pin, you want to do feedback, watching the actual voltage, not the
theoretical voltage!)  (Make sure your algorithm does what you need it
to do, not just what "theoretically is right", for you beginners <G>)

10 second C lesson, here:  (Not that this was really C, more quick &
dirty C-Like Pseudocode <G>)

Bool PWM1State = False;  means PWM1State is a variable, initialized to
0, with 2 states (1 for true, 0 for false.)  Though in C, nonzero
usually is used to mean True.

Int PWM1On = 10;  means Integer variable (could be 8-bit or 16-bit, in
assembler I'd use 8-bit probably) initialized to 10.

While (True) do { } means do the same things repeatedly forever (could
be Label:  [Stuff in { }] followed by Goto Label, in assembler.

PWM1State = (PWM1Counter < PWM1On)  means that if PWM1Counter < PWM1On,
set PWM1State to True, else False (use ClrW then IORLW like Scott
Dattalo did, same thing.)

SetPWMPins (PWM1State, PWM2State, PWM3State, PWM4State) is a function
call - I imply MovWF PWM_Port there.

PWM1Counter++ means increment PWM1Counter.

If (PWM1Counter >= PWM1Cycles) PWM1Counter = 0 is sort of obvious <G>

 Mark

<37B9EC33.4D195453@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...