Searching \ for 'Digital frequency generation' 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/index.htm?key=digital+frequency
Search entire site for: 'Digital frequency generation'.

Truncated match.
PICList Thread
'Digital frequency generation'
1999\11\08@144453 by roberto1

flavicon
face

A challenge:

How to generate in a single PIC (16F877) 3 square waves with different
frequencies? and more: all the 3 frequencies can assume any value from
1Hz to 1000Hz (in 1Hz steps).
Preferentially I wish to see an routine/algorithm that allow me to write
3 words (2 bytes each)that will setup the 3 frequencies. This is my
problem.
Remember: this pic has 3 timer that could be used for this purpose...
However I thinking it may be possible to use only one timer module (!?)

If it isn't possible to make via software, I accept sugestions about any
IC that exists and can do the following task: -Receive in I2C format the
word (two bytes) that will setup an internal oscillator that will
generate one square wave with the same value (in Hz) of the received
word (two bytes), so my problem is solved: I may use 3 of this ICs.
If your can help me or know an ICs that work like this or similar,
tell me.


See you,

Beto.




_________________________________________________________________________
MailBR - O e-mail do Brasil -- http://www.mailbr.com.br
Estamos concorrendo ao IBEST - Servigos On-Line
Acesse http://ibest.mailbr.com.br e Vote!

1999\11\08@145921 by Robin Abbott

flavicon
face
Well 2 isn't too hard.

You can use the 2 compare registers set to trigger the CCP outputs and
change the compare value in an interrupt routine - you will need to change
the action on each interrupt (i.e. on each half cycle change from set output
to clear and vice versa).  This is documented in the the Capture/Compare/PWM
section of the manual.

This only uses one timer module - TMR1 and can result in perfect square
waves with no jitter, you can easily do this with a 4MHz clock to get up to
1KHz outputs.

The third output is harder, but can be achieved with the Timer 0 module set
to overflow more frequently than 1mS - say every 256uS with a 4MHz clock.
Now you can count overflows on interrupts to set and clear an ouput - but it
will be jittery ! You can obtain an exact frequency by correcting the timer
in the interrupt routine by adding a value to it - this needs some care as
the timer stops for a while after it is updated and of course the read value
is also out of date, but it can be made to work- Alternatively PIC's are so
cheap you could use 2 !

The coding is up to you - I wish you luck !

Robin Abbott - spam_OUTrobin.abbottTakeThisOuTspamfored.co.uk

**************************************************************************
*
* Forest Electronic Developments
* http://www.fored.co.uk
*
**************************************************************************

{Original Message removed}

1999\11\08@162318 by Wagner Lipnharski

picon face
You can use a timer interrupt, calibrated to generate one interrupt each
one millisecond (this is your granularity, or resolution, isn't?).

You need to specify 3 x 16 bits reload counters, each one would contain
exactly half the value from each one of the 3 frequencies (double
frequency), necessary to flip the output pin twice per complete
frequency cycle. Then, the reload counters are loaded into 3 decrement
counters (16 bits each).

Each loop through the interrupt routine will decrement each one of the
decrement counters, when any reaches zero its correspondent port pin
output should flip level, then this decrement counter is load with its
correspondent reload counter value.

If your instrument only job is generate those 3 frequencies, *and
nothing else*, this can be done with a one millisecond timer routine,
but in this case you should have the same number of instruction cycles
executed with or without the "flip output and reload timers" steps, so
the routine would run steady without any jitter.

Remember that in all cirscunstances involving software, you will never
have the 3 wave forms happening at exactly the same time, if your
specify the same frequency for all of them. They will always have some
microseconds between edges.

Boa sorte e depois nos diga como resolveu... :)

Wagner.

1999\11\08@164905 by Dennis Plunkett

flavicon
face
>Boa sorte e depois nos diga como resolveu... :)
>
>Wagner.
>
>


Practicing the Portuguese Wagner, Yes good luck to you too :)


Dennis

1999\11\08@190752 by Tracy Smith

picon face
--- Wagner Lipnharski <.....wagnerlKILLspamspam@spam@EARTHLINK.NET> wrote:
{Quote hidden}

I'm sure that Wagner, like always, has good
intentions, but don't let his absolutisms fool you.

The subject you wish to learn more about is: phase
accumulators. Do some home work and search about this
on the web. Others have commented (quite succinctly)
on this list in the past. I remember posts from Paul
(not sure which one) and Mike Keitz that were both
very good. So perhaps the archives would be a good
place to begin.

A phase accumulator in C would go something like this

unsigned delta_phase,new_phase;

delta_phase = ----;
do {

  new_phase = phase + delta_phase;
  if(new_phase < phase)
    output ^= 1;

  phase = new_phase;

}

The trick is in the roll-over arithmetic. Each time
you go through the loop, you add delta_phase to the
phase. If this rolls over, then you toggle the output.
The output frequency is half of the roll over
frequency.

If the update rate is too slow, the output frequency
will have a lot of jitter. The 'average' output
frequency would be correct, but most people want the
instantaneous frequency to be correct too. So to
mitigate this problem, the phase is updated as fast as
possible. Perhaps an example would clarify the
concept:  Suppose you wanted to generate 1000Hz and
were updating the phase accumulator every 50uS. Then
exactly 20 (1/1000/50uS)iterations in the loop above
(with the appropriate delta_phase) would generate the
1000Hz square wave. However, if you wanted to generate
a 900Hz square wave you'd need to iterate through the
loop 22.2222 (1/900/50uS) times! This of course isn't
possible. Consequently, the phase accumulator will
constrict you to either 909.0909Hz (1/22/50uS) or
869.565Hz (1/23/50uS) exact square waves. To obtain an
average frequency of 900Hz, you'll have to squirt out
a combination of 909 and 869 Hz square waves. The
phase accumulator algorithm will automatically take
care of this for you, but you'll have a bit of
jitter...

As far as generating 3 square waves simultaneously,
well you simply have three different phase
accumulators. If you want them to change at the same
time (i.e. no phase shift if they're perfectly
sunchronized) then you'd store the toggle info in a
register and then write that register out to the I/O
port.

.lo

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

1999\11\09@070300 by paulb

flavicon
face
Tracy Smith wrote:

> The subject you wish to learn more about is: phase accumulators.  Do
> some home work and search about this on the web.  Others have
> commented (quite succinctly) on this list in the past.  I remember
> posts from Paul (not sure which one) and Mike Keitz that were both
> very good.  So perhaps the archives would be a good place to begin.

 I thought you were referring to me!  But then you said "succinctly".
Now I don't know if it was me or not! ;-)

 Anyway, the phase accumulator generates frequencies which have the
same long-term accuracy as your (crystal) clock to the PIC and are
totally coherent - if you change the frequency, the new frequency starts
from the phase of the old one at the point of change.  The resolution
is *exactly* what you specify it to be too.

 What it does have, is jitter.  More precisely, the output is *decided*
at a sub-multiple of the clock rate, say at 8,192 Hz using a crystal
frequency of 4.096 MHz.  This means the "decision" interval is 122.070
µs so that is the limit of the "jitter" (+/- 61 µs if you like to look
at it this way).

 If your square waves permit this amount of jitter, this design is
quite do-able.  In fact, it has to be, as there is no other way of
obtaining *any* three different frequencies of integral Hertz from one
clock oscillator (using a PIC).  Of course, multiplying the PIC clock
frequency to 8.192 MHz or 16.384 MHz may permit two and four times
better resolution respectively.

 Other clock frequencies are usable but complicate the maths.  The
above derivation allows simple binary addition to be used for the
accumulators, with an isosynchronous program taking 125 instruction
cycles in a loop.  Each of the three frequency values is added each loop
to its respective phase accumulator in a 16-bit add routine, and bit 4
of the MSB of the phase accumulator is transferred to the corresponding
output bit.

 Preferably, they are in fact transferred to bits in a shadow register
which is then written to the port register, so whichever bits change,
change together.

 AND THAT'S ALL!  That's the *whole* frequency generation algorithm,
believe it or not.  No timers (and interrupts *cannot* be used at all).
A 12C508 will do the job perfectly (if you can figure out how to use the
one remaining I/O to code in the frequency values!  Hint - serial comms
with a baudrate of 8192 Baud!).
--
 Cheers,
       Paul B.

1999\11\09@133232 by Wagner Lipnharski

picon face
Tracy Smith wrote:
> I'm sure that Wagner, like always, has good
> intentions, but don't let his absolutisms fool you.
>
> The subject you wish to learn more about is: phase
> accumulators. Do some home work and search about this
> on the web. Others have commented (quite succinctly)
> on this list in the past. I remember posts from Paul
> (not sure which one) and Mike Keitz that were both
> very good. So perhaps the archives would be a good
> place to begin.
[snip]

If you have jitter, even when the total pulses per second is correct,
you have an imprecise wave form, that serves only as the average along a
period of time, nothing else, even that several frequency counters (HP
5328, 5334,5,etc) would say it is a correct frequency (average in time),
but try to measure pulse period.

Of course it can be used in several application when pulse period
accuracy is not a request. I also think that a frequency generator based
on a 8MHz PIC will not be the "important" time base in a bench, is it?
so anything will works for the purpose.

Price by price I would go for a commercial programmable wave form
generator and then use the PIC to control it.  I understand that it
could be funny to use a hammer to set a bolt, but it is not the right
tool, you will have *limitations*.

Try several "prime" numbers as frequency to be generated from a 8MHz
driven unit, and after a while even your calculator digits will be
jittering... :)

You will not want a microcontroller being driven by a jittering
programmable oscillator, if you need clock stability and precision.
Don't let miraculous solutions fool you.

Remember the "Magician Law":  The effect of a magic act is directly
proportional to how much fool is the audience, so, when you see a great
magician producing a great magic act, he is only exposing the big fool
in you.

Wagner

1999\11\10@073841 by Pavel Korensky

flavicon
face
>Price by price I would go for a commercial programmable wave form
>generator and then use the PIC to control it.  I understand that it
>could be funny to use a hammer to set a bolt, but it is not the right
>tool, you will have *limitations*.

I share the same opinion. For example, AD9835 DDS chip is relatively cheap
and with stable base oscillator, it can generate mentioned frequencies
without any problem, if the base oscillator is stable enough. In most
times, it is not...

>You will not want a microcontroller being driven by a jittering
>programmable oscillator, if you need clock stability and precision.
>Don't let miraculous solutions fool you.

:-) More than year ago, I started to develop my bench top signal generator.
When I looked at Analog's DDS chips, I thought that I found miraculous
solution - frequency generator which is able to generate fequencies with
milihertz precision. It seems simple, but as soon as someone think a bit
about it, it is not so simple. Till today, the whole project is not yet
finished, because it took me more than eight months to find and build
reasonably stable base oscillator.
BTW, I tested two commercial DDS based signal generators and the results
was disasterous. Both of them claimed something like 1-20.000.000 Hz,
precision 0.001 Hz and both of them was +/- 10 - 50 Hz off most time,
drifting like crazy (at 10.000.000). In one unit, there was used normal
crystal oscillator as a master - they did not bother to use any form of
temperature compensation...

PavelK

**************************************************************************
* Pavel KorenskyÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ *
* DATOR3 LAN Services spol. s r.o.ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ *
* Styblova 13, 140 00, Prague 4, Czech Republic      ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ *
*ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ *
* PGP Key fingerprint:Ê F3 E1 AE BC 34 18 CB A6Ê CC D0 DA 9E 79 03 41 D4 *
*ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ *
* SUMMA SCIENTIA - NIHIL SCIREÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ *
**************************************************************************

1999\11\10@164438 by paulb

flavicon
face
There have been some interesting diversions in this thread.

 Back on topic however, the *purpose* of at least one of the two
original enquiries was a speed control for a stepper motor system, an
application in which jitter less than a modest fraction of a millisecond
is of no consequence whatever.

 For that application, a phase accumulator algorithm on a PIC, quite
possibly a PIC12C508, is *more* than adequate for the task to generate
three frequencies.  Actually that is a bit simplistic - in practice a
16C71 or 16F84 would be used to generate the *complete* drive waveforms
for three steppers.

 It certainly remains true that the Phase accumulator/ DDS procedure is
capable of generating extremely stable and accurate frequencies with any
resolution (reasonably) specified, but only ever within the accuracy of
its clock source.
--
 Cheers,
       Paul B.

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