Searching \ for '[PIC] PIC with PWM outouts generating DIFFERENT fr' 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: 'PIC with PWM outouts generating DIFFERENT fr'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] PIC with PWM outouts generating DIFFERENT fr'
2010\02\28@043521 by Peter Feucht

flavicon
face
Hello,

I'm looking for a PIC which is able to generate two DIFFERENT frequencies at
two PWM outputs. Frequency range has to be 1 to 400Hz, I know this is very
low so I have to add dividers, but this is no problem.

The frequency has to be generated in background, that's why I want to use
PWM. The PIC is very busy with other stuff (keys, displays, interface and so
on).

I already looked at the MChip comparison list but got no info about my
problem. Before reading all manuals I thought it's easier to ask the list.

If anybody has another idea how to generate 2 frequencies in background (in
fact no PWM is needed, a duty cycle of whatever value is ok) please let me
know.

Any idea where to start?

Thanks and regards

Peter

2010\02\28@044941 by Marcel Birthelmer

picon face
I think lots of newer pics (not sure if just 18f or some 16f also)
have two CCP modules... regular CCP and ECCP... I think you can use
those to generate two separate frequencies, independently. Something
to check out at least.

2010\02\28@091339 by Tamas Rudnai

face picon face
Other option is to use one CCP module plus generate the other pwm by software.

On 2/28/10, Marcel Birthelmer <spam_OUTmarcelb.listsTakeThisOuTspamgmail.com> wrote:
> I think lots of newer pics (not sure if just 18f or some 16f also)
> have two CCP modules... regular CCP and ECCP... I think you can use
> those to generate two separate frequencies, independently. Something
> to check out at least.
> -

2010\02\28@113922 by Alan B. Pearce

face picon face
>I'm looking for a PIC which is able to generate two DIFFERENT
>frequencies at two PWM outputs. Frequency range has to be 1 to
>400Hz, I know this is very low so I have to add dividers, but
>this is no problem.

You should be able to do this using a PIC24 device. I have used one to have
a 'heartbeat' PWM at a high enough frequency that the LED didn't blink, as
well as another generating pulses at a significantly lower frequency
(somewhere around 30Hz as I recall, and could have gone significantly
lower).

2010\02\28@125504 by Spehro Pefhany

picon face
At 04:35 AM 2/28/2010, you wrote:
{Quote hidden}

Sounds like you just want to generate two frequencies, not actually generate
PWM.

Easiest way, IMHO, would be to use two CCP modules (eg. PIC16F873 etc.) in the
compare mode (set/clear output pin on match (and generate an interrupt
so that you can use registers to count the number of matches). With a
4MHz crystal and selecting the internal 8:1 prescaler you might just be able
to squeak by without it (524,288usec rollover, unless I made a mistake, so
the 0.5 second you need for a 1Hz output can be achieved without extra code
(add 0xF424 to the compare register on each interrupt). In general, the
number would be

adder = 0.5 * (fclk)/(prescale * fo)

You get to decide what to do if the number is not an integer-- either make
the frequency accurate and add jitter (by accumulating the errors and
rounding each add), or allow a slight deviation in frequency and have
essentially no jitter.

For 400Hz, it works out to 156.25. So if you use 156, you get 400.641 Hz.
If you use (in sequence) 156, 156, 156, 157,... the frequency is
exact, but the
duty cycle is off a bit and there will be a periodic jitter. You could reduce
this by reprogramming the prescaler, but since it's shared by the CCPs
this might not be practical. If you count matches with internal
registers you can set the prescaler to 1:1 and get 4/fosc timing resolution,
but it's a bit more coding- you have to ensure that you don't end up with any
of the compare times that are too short.

None of this uses any significant processor bandwidth, assuming a clock in
the MHz. The main limitation on your other stuff is that is shouldn't turn
off or otherwise prevent the CCP interrupt service routine from running
reasonably soon after the match occurs ("reasonably soon", of course, means
that you must always be able to respond to the interrupt and get to the point
of reloading the 16-bit compare registers and update CCP mode before the
*next* match is due to occur!).

>Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam@spam@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com



2010\02\28@131018 by Bob Blick

face
flavicon
face

On Sun, 28 Feb 2010 13:01:18 -0500, "Spehro Pefhany" said:

> Sounds like you just want to generate two frequencies, not actually
> generate
> PWM.
>
> Easiest way, IMHO, would be to use two CCP modules (eg. PIC16F873 etc.)
> in the
> compare mode (set/clear output pin on match (and generate an interrupt
> so that you can use registers to count the number of matches). With a
> 4MHz crystal and selecting the internal 8:1 prescaler you might just be
> able
> to squeak by without it (524,288usec rollover, unless I made a mistake,
> so
> the 0.5 second you need for a 1Hz output can be achieved without extra
> code
> (add 0xF424 to the compare register on each interrupt). In general, the
> number would be
>
> adder = 0.5 * (fclk)/(prescale * fo)


I second this approach. It is the most accurate and requires the least
amount of overhead!

You can generate PWM or variable pulses with this method if you use
different time for setting and clearing the pin. It is one of the best
ways of driving hoby servos.

Cheerful regards,

Bob

--
http://www.fastmail.fm - Faster than the air-speed velocity of an
                         unladen european swallow

2010\02\28@154715 by John Temples

flavicon
face
On Sun, 28 Feb 2010, Peter Feucht wrote:

> I'm looking for a PIC which is able to generate two DIFFERENT frequencies at
> two PWM outputs. Frequency range has to be 1 to 400Hz, I know this is very
> low so I have to add dividers, but this is no problem.
>
> The frequency has to be generated in background, that's why I want to use
> PWM. The PIC is very busy with other stuff (keys, displays, interface and so
> on).

If by "in the background" you mean "zero software overhead," your
options are limited, since you'll have to use a PWM.  In order to get
two different frequencies, you'll need a PIC with a TMR4 module and at
least two CCP modules (search for "2 8-bit timers" in the parametric
search).

However, the PWM timers on the PIC16/PIC18 only have a limited number
of bits in their prescalers, which limits your minimum PWM frequency
to Fosc / 16384 for most PIC16/PIC18 parts.  This won't be practical
for generating the low frequencies you're interested in.

Your other option is moving into the PIC24 family which has larger
prescalers on its timers.

--
John W. Temples, III

2010\02\28@173431 by ivp

face picon face
Peter,

> The PIC is very busy with other stuff

Can you put a figure on "very busy" ?

> generate 2 frequencies in background (in fact no PWM is needed,
> a duty cycle of whatever value is ok)

Is there anything in your "very busy" that would prevent you using
conventional timer interrupt servicing ? For example, what frequency
accuracy, what jitter, what duty cycle accuracy, what response time
for changes etc etc

wbr


'[PIC] PIC with PWM outouts generating DIFFERENT fr'
2010\03\01@035447 by Alan B. Pearce
face picon face
>you'll need a PIC with a TMR4 module and at least two CCP
>modules (search for "2 8-bit timers" in the parametric
>search).

Some of the PIC24 chips have a seperate timer module that is dedicated to
the CCP.

2010\03\01@045236 by Chris McSweeny

picon face
On 2/28/10, Peter Feucht <feuchtsspamKILLspamkabelbw.de> wrote:
> Hello,
>
> I'm looking for a PIC which is able to generate two DIFFERENT frequencies at
> two PWM outputs. Frequency range has to be 1 to 400Hz, I know this is very
> low so I have to add dividers, but this is no problem.

Maybe not a lot of help, but an AtTiny45 will do this - I have an app
with two separate PWMs, one running at 32kHz, one at 1Hz. They do
their own thing once set up.

Chris

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