Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIC32 PWM not working?
23-12-2015, 05:31 PM, (This post was last modified: 23-12-2015, 05:45 PM by jwzumwalt.)
#11
RE: PIC32 PWM not working?
(23-12-2015, 11:37 AM)pingotg Wrote: Your code tries to set the frequency but then has a bad tight loop.

With the delay in loop, does the PWM.setFrequency work?

Isn't the 170kHz simply due to your lack of a delay?  Your code tries to get 10kHz; does it get that when you have the delay (I suppose of at least a few ms)?

IOW, doesn't everyone wanting to use PWM.setFrequency need a delay?  Or, to avoid calling analogWrite often e.g. using something like:

static uchar done = 0;
if (!done) {
analogWrite(...);
done = TRUE;
}

John

ahh.., I am beginning to understand your point of view  Smile

So, first... my inquiry into analogWrite was twofold. 1st I was interested in the possibility
of simple solution, PWM requires three independent commands to be used. Without
any documentation I used the program listing shown above hoping the PWM command may
also control analogWrite - it does not.

The 2nd goal was to get away from a dedicated loop so that other processing could
be accomplished. This is often accomplished by using a timer and interrupt - but this
uses up a timer and using a timer somewhat limits code re-usability.

Part of my investigation was to see what the difference was between the PWM and
analogWrite. (I outlined the difference in the documentation and the comments in
the previous post.)
----------
Now to address your question (I am not making any assumptions to your past
chip usage so I am explaining everything).

The programming solution methodology changes somewhat depending on the
power and resources of the processor. If we use a PIC with 1k ram, we are
apt to only expect one or two things to be controlled, and readily embrace
a delay loop. However the PIC32 has 512k ram running at 80mhz which
means we really are interested in multiple processes (perhaps dozens) and
don't want a dedicated tight timing loop.

PWM and analogWrite are "set and forget" commands - no loop required. They
both continuously generate square waves without a loop, delay, or other
attention. The anologWrite does not allow the frequency
(as I found out) to be set.

So, if a programmer needs pulse width control, but does not care about
the frequency (i.e. simple DC motor), they would use the simple analogWrite.
If they needed pulse width AND frequency control (i.e. servo or stepper motor)
they would need to use PWM.x commands.

I had offered to post some projects and tutorials for this and other
subjects on the Wiki but as of this date the admin has not responded to
my request to create menu items for "projects" and "Tutorials".
----------------
Thanks,
j
wzumwalt
 (\__/)
 (='.'=)
 (")_(")
Reply
23-12-2015, 08:07 PM,
#12
RE: PIC32 PWM not working?
You can usually use the idea that Pinguino = Arduino but for PIC, i.e. use Arduino documentation - or just read the source / examples / wiki.

Using analogWrite very very often (170kHz? i.e. 170,000 times per second) is something no real program would want to do and as a result it was creating misleading output.

Instead, you'd use it ... maybe a few times per second or less. I expect it works in that case and also in conjunction with setFrequency.

BTW I think you mean 512K flash, as the PIC32 RAM is 128K max as yet, I think.

John
Reply
24-12-2015, 08:40 AM, (This post was last modified: 24-12-2015, 08:47 AM by jwzumwalt.)
#13
RE: PIC32 PWM not working?
(23-12-2015, 08:07 PM)pingotg Wrote: BTW I think you mean 512K flash, as the PIC32 RAM is 128K max as yet, I think.

Yup - thanks for catching that error Smile

As for the Arduino docs, the first few I found for analogWrite where pretty much useless - no examples etc. I finally found documentation that said the frequency could not be set - it was hard coded to ~450-900hz depending on the Arduino chip.

The interesting thing is I have been quite disappointed with the pinguino documentation since it has been around for at least a couple years (I bought two PIC32 2yrs ago - I waited thinking things would be better after a year or so). As I look at the Arduino docs, they are not much better - which came as quite a surprise given the number of hobbyist using it!
----------------
Thanks,
j
wzumwalt
 (\__/)
 (='.'=)
 (")_(")
Reply
24-12-2015, 09:07 AM,
#14
RE: PIC32 PWM not working?
Finding volunteers is hard Sad

John
Reply
24-12-2015, 09:14 AM,
#15
RE: PIC32 PWM not working?
(24-12-2015, 09:07 AM)pingotg Wrote: Finding volunteers is hard Sad

John

It's interesting that you mention that because a couple weeks ago I decided to create documentation for nearly all the commands - at least the ones I would most likely use. Then I came across the pinguino.cc Wiki site and thought it would make sense  to contribute to the community and just use the Wiki site. However, the couple of contacts I have had with the admin have not been encouraging and I decided to cool off a few days before doing something drastic.

I am considering creating my own Wiki - it would only take me about three weeks to flesh it out. I have not decided what I will do.
----------------
Thanks,
j
wzumwalt
 (\__/)
 (='.'=)
 (")_(")
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)