Searching \ for '[PIC]: Generating a 120KHz pulse' 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/devices.htm?key=pic
Search entire site for: 'Generating a 120KHz pulse'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Generating a 120KHz pulse'
2001\01\28@100028 by Bob Ammerman

picon face
> Now I need to generate a 120KHz pulse that last
> about 1ms, can I use
> PWM with a 50% duty cycle. I've never done this
> before and I just want
> to make sure. I'll be using a PIC16F877.
>
> --
> Neil Cherry

This should be pretty easy.

The only issue is the accuracy available.

PWM duty cycle is always a multiple of the instruction time.

So, given  a 20MHz XTAL, each instruction takes 0.2 microseconds.

The period of a 120KHz signal is 8.3333... microseconds.

The closest you'll be able to get (with the 20MHz clock) is 8.2
microseconds.

This is an error of (8.3333-8.2)/8.33333 = about 1.6%

The actual frequency would be 121.951 KHz.

To get a more accurate result, you'd need to use a carefully selected
crystal, that is one that is a multiple of four times (because Tinst =
4Tcycle) your 120KHz signal.

12.000MHz or 18.000MHz would work fine.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\01\28@223051 by Drew Vassallo

picon face
>The closest you'll be able to get (with the 20MHz clock) is 8.2
>microseconds.

I beg to differ :)

>This is an error of (8.3333-8.2)/8.33333 = about 1.6%
>The actual frequency would be 121.951 KHz.

However, if you used 8.4us (1 more instruction), you could get 119.047 KHz,
which is only 0.8% error.

>12.000MHz or 18.000MHz would work fine.

This is a better suggestion :)
--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\01\29@071633 by mike

flavicon
face
On Sun, 28 Jan 2001 22:30:51 -0500, you wrote:

>>The closest you'll be able to get (with the 20MHz clock) is 8.2
>>microseconds.
>
>I beg to differ :)
>
>>This is an error of (8.3333-8.2)/8.33333 = about 1.6%
>>The actual frequency would be 121.951 KHz.
>
>However, if you used 8.4us (1 more instruction), you could get 119.047 KHz,
>which is only 0.8% error.
>
>>12.000MHz or 18.000MHz would work fine.
I didn't see the original question, but if you used 8.2uS high and
8.4uS low, that would give 8.3uS = 120.481= 0.4% out.
--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\29@075626 by Bob Ammerman

picon face
> >The closest you'll be able to get (with the 20MHz clock) is 8.2
> >microseconds.
>
> I beg to differ :)

And, of course, you'd be right!

>
> >This is an error of (8.3333-8.2)/8.33333 = about 1.6%
> >The actual frequency would be 121.951 KHz.
>
> However, if you used 8.4us (1 more instruction), you could get 119.047
KHz,
> which is only 0.8% error.

Duh...

> >12.000MHz or 18.000MHz would work fine.
>
> This is a better suggestion :)
> --Andrew

Would you believe my floating point unit was set to truncate mode instead of
round-to-nearest?

Or maybe that I did the calculation on a Pentium?

Or just that I wasn't thinking too clearly?

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\29@100114 by James Paul

flavicon
face
Mike,

Actually, you'd have to use 4.1 uS and 4.2 Us because the period is
8.333uS.  Your statement would put the period at 16.6 uS which would
be about 60Khz.  But if he can handle a slightly non symetrical wave
form, this would be a good idea.  The duty cycle works out to ~49%
with 8.1uS as the high time and 50.6% with 8.2uS as the high time.
Either way, it's very close.

                                         Regards,

                                           Jim



On Mon, 29 January 2001, Mike Harrison wrote:

{Quote hidden}

spam_OUTjimTakeThisOuTspamjpes.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\29@151945 by Drew Vassallo

picon face
>  Actually, you'd have to use 4.1 uS and 4.2 Us because the period is
>  8.333uS.  Your statement would put the period at 16.6 uS which would
>  be about 60Khz.  But if he can handle a slightly non symetrical wave
>  form, this would be a good idea.  The duty cycle works out to ~49%
>  with 8.1uS as the high time and 50.6% with 8.2uS as the high time.
>  Either way, it's very close.

Jim, you can't get 4.1us with 20MHz clock, as the cycle time is .200us.  If
you drop to 12MHz clock, you can get 0.33333333us per clock cycle, giving 25
instructions for 120KHz operation, but still can't be broken down into 2
equal pulses.  Even at 16MHz, you get .250us per cycle, or 33.33333333
instructions for 120KHz operation, which still doesn't work.
You may be able to get an off-speed crystal, but I haven't done the research
on that one.

Your best bet is going with my 8.4us period (4.2us each high and low) at
20MHz, which is only 0.8% error.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\29@162021 by James Paul

flavicon
face
Drew,

I see that now.  I should have seen it before.  I stand corrected.
Thanks for catching it for me.

                                           Regards,

                                             Jim



On Mon, 29 January 2001, Drew Vassallo wrote:

{Quote hidden}

.....jimKILLspamspam@spam@jpes.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\29@162028 by Don Hyde

flavicon
face
You can get crystals in any frequency you want.  You will probably have to
order direct from the manufacturer, and for onesies-twosies, you will have
to pay extra and wait a while.  If you're buying at least a few hundred, it
probably won't even cost any more to have them cut to order.

Crystals are "really" for radios, and in that application, oddball
frequencies are the norm and frequencies like 10MHz are the oddballs.

I know our RF guys have a favorite crystal maker that specializes in
delivering strange frequencies quickly.  If you are interested, contact me
offlist, and I can ask who that is.

SNIP

> You may be able to get an off-speed crystal, but I haven't
> done the research
> on that one.
>
SNIP
>

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


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