Searching \ for '[PIC] dsPIC PWM oddity...' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=pwm
Search entire site for: 'dsPIC PWM oddity...'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] dsPIC PWM oddity...'
2004\10\27@210316 by Herbert Graf

picon face
Hello everyone, well, now that I've got some stuff working I decided to
tackle some more, so for today the task was to get the PWM working.

I'm using a dsPIC30F2010. I've configured the PWM for free running mode,
no post scale, no pre scale, no dead time (yet), nothing fancy.

I load PTPER with 99 (comes from a macro, value confirmed with the
ICD2), and then load PDC1 with whatever I want.

I put a scope to the PWM pin and voila, a duty cycle of half what I
expect!??!

For example, when I write 99 to PDC1 (which is the same as PTPER), I get
~50%, when I write 50 into PDC1 I get about 25%? When I set it to 150
(which is MORE the PTPER) I get 75%??

Am I missing something basic with regards to PWM on the dsPIC?

I've checked the manual and the errata, no go.

Please note that the PWM module, the dsPIC and the ICD2 are COMPLETELY
new to me, so it's VERY likely I've yet again done something stupid. If
so I ask you let me know (and PLEASE me kind! :) ).

Anyways a screen capture of my MPLAB environment with the output of the
ICD2 and relevant code can be found here:

http://repatch.dyndns.org:8383/classd_MPLAB.gif

A picture of the waveform coming out for that case can be found here:

http://repatch.dyndns.org:8383/classd_scope.jpg

Anyways, any help would be most appreciated. I can go ahead with it as
is, but I'd rather know WHY it's doing what it's doing. Thanks, TTYL

____________________________________________

2004\10\28@074751 by olin_piclist

face picon face
Herbert Graf wrote:
> I'm using a dsPIC30F2010. I've configured the PWM for free running mode,
> no post scale, no pre scale, no dead time (yet), nothing fancy.
>
> I load PTPER with 99 (comes from a macro, value confirmed with the
> ICD2), and then load PDC1 with whatever I want.
>
> I put a scope to the PWM pin and voila, a duty cycle of half what I
> expect!??!

First, which PWM generator are you using?  The one that is most like other
PICs is called the "output compare" module.  The "motor control PWM" is a
new and different beast.  I have used both of these, and never encountered
such a symptom.  There were some flakys is early versions of the '2010
output compare module, but those have all been fixed.  Anyway, those had to
do with spurious pulses caused by unrelated events.

The motor control PWM module has a lot of options.  I'm guessing you are
using it and have the mode set incorrectly in one of the many control
registers.  A factor of two sounds suspiciously like you are thinking single
slope and it's doing dual slope, or the other way around.  I vaguely
remember that there was a factor of two difference between some of the
modes.

Do you really need all the flexibility of the motor control PWM, or will the
simpler output compare module do it?

Unlike other PICs where everything you need is in the data sheet, on the
dsPIC you need their equivalent of the midrange reference manual.  It's
called "dsPIC30F Family Reference Manual".  Unfortunately there isn't a
single DS number for this manual because they gave each chapter a different
one.

You need to read section 15, "Motor Control PWM" (if that's what you're
using) completely and thoroughly.  Actually, I've found it's useful to skim
a section once to get the general flavor, then read it carefully word for
word.  Only then are you ready to write code.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
____________________________________________

2004\10\28@095925 by Herbert Graf

flavicon
face
On Thu, 2004-10-28 at 07:48, Olin Lathrop wrote:
> Herbert Graf wrote:
> > I'm using a dsPIC30F2010. I've configured the PWM for free running mode,
> > no post scale, no pre scale, no dead time (yet), nothing fancy.
> >
> > I load PTPER with 99 (comes from a macro, value confirmed with the
> > ICD2), and then load PDC1 with whatever I want.
> >
> > I put a scope to the PWM pin and voila, a duty cycle of half what I
> > expect!??!
>
> First, which PWM generator are you using?  The one that is most like other
> PICs is called the "output compare" module.  

I'm using the 2010, so it only has the motor control PWM.

Since I've never used PWM on a PIC before no "prior knowledge" can
pollute me! :)

> The motor control PWM module has a lot of options.  I'm guessing you are
> using it and have the mode set incorrectly in one of the many control
> registers.  

That's why I included the screen capture
(http://repatch.dyndns.org:8383/classd_MPLAB.gif), it shows how I'm
setting each relevant register, and through the ICD2 confirms those
settings.

FWIW setting it up isn't that complicated if you don't use some of the
more fancy features.

The most important settings, AFAIK is PTCON and PWMCON1:

PTCON is set to zero (at first, I later enable bit15 to enable the
module). This, AFAIK should enable free running mode, no prescale, no
post scale, which is what I want.

PWMCON1 sets up the IO to complementary mode (0) and only PWM1L and
PWM1H set as PWM pins, the others are set as digital IO (11).

Then I set dead time to zero (don't need it right now) and AFAIK that's
it. Please let me know if I'm missing something. I've looked at the
other registers and all the default values are what I want, but since
I'm not using most of those features it doesn't matter anyways.

Finally, I set PTPER to 99 and for now statically set PDC1 to 99 (I've
tried other numbers for that one. I've also tried other numbers for
PTPER).

> A factor of two sounds suspiciously like you are thinking single
> slope and it's doing dual slope, or the other way around.  I vaguely
> remember that there was a factor of two difference between some of the
> modes.

AFAIK being dual slope would simply result in half the PWM frequency
(since the counter would count up to PTPER and then back down to zero),
correct me if I'm wrong but it should not affect duty cycle.

> Do you really need all the flexibility of the motor control PWM, or will the
> simpler output compare module do it?

Do I NEED the motor control PWM? Not technically, but it sure does make
it MUCH easier. I need the complementary outputs, and I need the dead
time generation. I suppose that could be done with the other PWM module,
but I'd rather not.

On top of that I only HAVE 2010 parts on hand, so it's not like I have a
choice.

> Unlike other PICs where everything you need is in the data sheet, on the
> dsPIC you need their equivalent of the midrange reference manual.  It's
> called "dsPIC30F Family Reference Manual".  Unfortunately there isn't a
> single DS number for this manual because they gave each chapter a different
> one.

Yup, that's what I've been referring, also used it for setting up the
ADC, which is working, and which was much more complicated (to me at
least, never used a PIC ADC before!).

Oh, and to those out there, yes I know C30 has libraries for the PWM, I
want to set it up myself since that gets me the most familiar with the
hardware.

> You need to read section 15, "Motor Control PWM" (if that's what you're
> using) completely and thoroughly.  Actually, I've found it's useful to skim
> a section once to get the general flavor, then read it carefully word for
> word.  Only then are you ready to write code.

Already did, wouldn't have posted my first message if I hadn't.

I am certain that this problem is a result of me having done something
royally stupid, I just haven't been able to figure out what I did that
was stupid.

If anyones needs any additional info please let me know.

Thanks, TTYL

-----------------------------
Herbert's PIC Stuff:
http://repatch.dyndns.org:8383/pic_stuff/

____________________________________________

2004\10\28@104129 by Jan-Erik Soderholm

face picon face
Hi.
It's probably of no help, it's a shoot in the dark,
but anyway...

I would probebly try to run the PWM in the most simple
"mode" as possibly. In this case it would probably be the
"Free Running mode". That is more deeply described in the
data sheet with some graphics. The "Complementary mode"
is a little less described (at least in the data sheet, don't
know about the Ref Man). But, as far as I understand, the
Complementary mode should not change the basic duty cycle
anyway, so I don't know realy... :-)

Best Regards,
Jan-Erik.
____________________________________________

2004\10\28@104912 by Alan B. Pearce

face picon face
>Oh, and to those out there, yes I know C30 has libraries
>for the PWM, I want to set it up myself since that gets
>me the most familiar with the hardware.

However perusing the libraries source code may also help understand the
hardware module, even if you do not use the library directly.

____________________________________________

2004\10\28@110832 by Jan-Erik Soderholm

face picon face
Alan B. Pearce wrote :

> >Oh, and to those out there, yes I know C30 has libraries
> >for the PWM, I want to set it up myself since that gets
> >me the most familiar with the hardware.
>
> However perusing the libraries source code may also help
> understand the hardware module, even if you do not use
> the library directly.

Or writing a short piece of "proof of concept" code directly
in ASM to be *real* sure of what's happening.
(Either from scratch or by using the C30 lib routines as
a base.)

Jan-Erik.
____________________________________________

2004\10\28@111424 by Herbert Graf

flavicon
face
On Thu, 2004-10-28 at 10:51, Alan B. Pearce wrote:
> >Oh, and to those out there, yes I know C30 has libraries
> >for the PWM, I want to set it up myself since that gets
> >me the most familiar with the hardware.
>
> However perusing the libraries source code may also help understand the
> hardware module, even if you do not use the library directly.

Since I only have the demo I don't know if the library source is
included (and I'm not at my home machine to check). If the source is
included that's a great suggestion! :) TTYL

-----------------------------
Herbert's PIC Stuff:
http://repatch.dyndns.org:8383/pic_stuff/

____________________________________________

2004\10\28@112131 by Herbert Graf

flavicon
face
On Thu, 2004-10-28 at 11:08, Jan-Erik Soderholm wrote:
> Alan B. Pearce wrote :
>
> > >Oh, and to those out there, yes I know C30 has libraries
> > >for the PWM, I want to set it up myself since that gets
> > >me the most familiar with the hardware.
> >
> > However perusing the libraries source code may also help
> > understand the hardware module, even if you do not use
> > the library directly.
>
> Or writing a short piece of "proof of concept" code directly
> in ASM to be *real* sure of what's happening.
> (Either from scratch or by using the C30 lib routines as
> a base.)

I actually wasn't that concerned that C30 wasn't compiling things
properly since the ICD2 shows the registers in question being set to
what I want them set. Thanks, TTYL

-----------------------------
Herbert's PIC Stuff:
http://repatch.dyndns.org:8383/pic_stuff/

____________________________________________

2004\10\28@113232 by olin_piclist

face picon face
Herbert Graf wrote:
> I'm using the 2010, so it only has the motor control PWM.

No, it has 2 output compare modules in addition to the 3 motor control PWMs
with complementary outputs.  I have actually used both simultaneously on
this chip.

> Do I NEED the motor control PWM? Not technically, but it sure does make
> it MUCH easier. I need the complementary outputs, and I need the dead
> time generation.

In that case the motor control PWM is the better choice.

>> You need to read section 15, "Motor Control PWM" (if that's what you're
>> using) completely and thoroughly.  Actually, I've found it's useful to
>> skim a section once to get the general flavor, then read it carefully
>> word for word.  Only then are you ready to write code.
>
> Already did, wouldn't have posted my first message if I hadn't.

I knew there was something about a factor of 2 in there, so this time I
looked myself.  See the Figure 15-5 at the top of page 15-21.  Note how bits
14-0 of PTMR are compared against bits 15-1 of PDCx.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
____________________________________________

2004\10\28@114340 by olin_piclist

face picon face
part 1 372 bytes content-type:text/plain; (decoded 7bit)

Herbert Graf wrote:
> Since I only have the demo I don't know if the library source is
> included (and I'm not at my home machine to check).

I've attached a dsPIC source code module that includes setup and use of a
motor control PWM channel.  This runs on a 30F2010.  The part you probably
care about is in the PFC_INIT routine.


part 2 20705 bytes content-type:application/octet-stream; (decode)

part 3 79 bytes content-type:text/plain; charset="us-ascii"
(decoded 7bit)

____________________________________________

2004\10\28@120230 by Alan B. Pearce

face picon face
>Since I only have the demo I don't know if the
>library source is included (and I'm not at my
>home machine to check). If the source is
>included that's a great suggestion! :) TTYL

The libraries sources are available as a separate zip download.
____________________________________________

2004\10\28@141446 by Herbert Graf

flavicon
face
On Thu, 2004-10-28 at 11:32, Olin Lathrop wrote:
> Herbert Graf wrote:
> >> You need to read section 15, "Motor Control PWM" (if that's what you're
> >> using) completely and thoroughly.  Actually, I've found it's useful to
> >> skim a section once to get the general flavor, then read it carefully
> >> word for word.  Only then are you ready to write code.
> >
> > Already did, wouldn't have posted my first message if I hadn't.
>
> I knew there was something about a factor of 2 in there, so this time I
> looked myself.  See the Figure 15-5 at the top of page 15-21.  Note how bits
> 14-0 of PTMR are compared against bits 15-1 of PDCx.

BINGO! Thank you Olin, that's exactly what I was missing.

Well, this is a nice surprise, I'll be able to get twice the resolution
I was expecting, that means I can turn up my PWM freq! Woohoo. TTYL

-----------------------------
Herbert's PIC Stuff:
http://repatch.dyndns.org:8383/pic_stuff/

____________________________________________

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...