Searching \ for '[PIC:] Frequency dividing to 440 Hz' 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: 'Frequency dividing to 440 Hz'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] Frequency dividing to 440 Hz'
2004\01\07@091126 by Koen van Leeuwen

flavicon
face
Hi all,

I am now designing a electronic metronome for myself, PIC-based of course.
As an extra, since I'm using crystal precision anyway, I thought of including a 440 Hz (an A note) reference tone to tune flutes etc.
But I can't find any standard (cheap) crystal that divides nicely in 440 Hz.
Do you know a simple solution, that does not introduce audible jitter (that would effectively ruin the use as a tuner)?
Are self-adjusting timer loops good enough?

Well, thanks in advance again,

Koen van Leeuwen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@092522 by Spehro Pefhany

picon face
At 03:09 PM 1/7/2004 +0100, you wrote:
>Hi all,
>
>I am now designing a electronic metronome for myself, PIC-based of course.
>As an extra, since I'm using crystal precision anyway, I thought of
>including a 440 Hz (an A note) reference tone to tune flutes etc.
>But I can't find any standard (cheap) crystal that divides nicely in 440 Hz.
>Do you know a simple solution, that does not introduce audible jitter
>(that would effectively ruin the use as a tuner)?
>Are self-adjusting timer loops good enough?
>
>Well, thanks in advance again,

How about just using a capture-compare module and whatever crystal you like?

Best regards,

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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@102347 by llile

flavicon
face
Dewd!  I have been wanting to build a metronome for a while!  Keep me
posted on how you are doing and I will be glad to pitch in a hand.  I
would love to build one myself.

Let's see:  440 Hz.  I tried a few standard crystal freqs, 18.432 MHZ, 10
MHZ, 4 MHZ and you are right they do not divide evenly.  Don't give up
however, there is more than one way to skin a cat.  Let's think of
several.

1.  Timing loops.  We should be able to make a dedicated timing loop that
counts to 1/440/2 = 1.136 mSec and flips a bit to the speaker driver.
Disadvantage:  the PIC does nothing else.

2. Interrupts.  This might be cleaner, set up a timer interrupt that times
out every 1.136 mSec and flips a bit.  Then your PIC could do something
else int he interrum like scan for keypresses, talk to an LCD display, or
listen to your instrument and tell you how close your pitch is.  These
should be regular enough to avoid jitter.  Different notes could be
programmed into the interrupt timer if you want something other than A440.


I have a routine that produces tones in a PIC that I can send offline.  It
is a dedicated timing loop style routine, meant to produce melodic beeps
on a keypress.  I am thinking the interrupt method would be a better
design, though.

As far as the tick sound goes, here is what I would do.  I would use an
interrupt based routine to generate the tick sound.  The interrupt can be
fast, maybe 128 beats per second (7.8125 mSec) then all the interrupt does
is increment a counter.  Your user interface picks a tempo (in beats per
minute) the PIC does the math and determines how many 7.8125 mSecs divide
into so many beats per minute.  A use interface could also translate beats
per minute into regular musical terms like Largo and so on.  Do you know
these terms and how they translate into beats per minute?

A straightforward user interface is a Scott Edwards serial LCD and a
couple of buttons.  And a speaker of course.  A large diameter piezo
driven by a transistor is all that is needed.  Geez the thing is almost
designed already.

I play instruments, but my main need for a metronome is in dance.  My wife
and I practice dance a lot, and we want to practice to a regular clock
tick when we are not using music.  When we practice a step, we tend to
speed up and speed up until we can't perform the trick anymore.  A
metronome is great for this.  Then later when we have mastered the move,
we want to practice to a fast beat.

-- Lawrence Lile





Koen van Leeuwen <.....koenKILLspamspam@spam@VANLEEUWEN.XS4ALL.NL>
Sent by: pic microcontroller discussion list <PICLISTspamKILLspamMITVMA.MIT.EDU>
01/07/2004 08:09 AM
Please respond to pic microcontroller discussion list


       To:     .....PICLISTKILLspamspam.....MITVMA.MIT.EDU
       cc:
       Subject:        [PIC:] Frequency dividing to 440 Hz


Hi all,

I am now designing a electronic metronome for myself, PIC-based of course.
As an extra, since I'm using crystal precision anyway, I thought of
including a 440 Hz (an A note) reference tone to tune flutes etc.
But I can't find any standard (cheap) crystal that divides nicely in 440
Hz.
Do you know a simple solution, that does not introduce audible jitter
(that would effectively ruin the use as a tuner)?
Are self-adjusting timer loops good enough?

Well, thanks in advance again,

Koen van Leeuwen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads



--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@103911 by Dave VanHorn

flavicon
face
At 09:21 AM 1/7/2004 -0600, EraseMEllilespam_OUTspamTakeThisOuTSALTONUSA.COM wrote:
>Dewd!  I have been wanting to build a metronome for a while!  Keep me
>posted on how you are doing and I will be glad to pitch in a hand.  I
>would love to build one myself.
>
>Let's see:  440 Hz.  I tried a few standard crystal freqs, 18.432 MHZ, 10
>MHZ, 4 MHZ and you are right they do not divide evenly.  Don't give up
>however, there is more than one way to skin a cat.  Let's think of
>several.

I remember a 2.0something mhz xtal that was designed for electronic organs.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@104751 by Spehro Pefhany

picon face
At 09:31 AM 1/7/2004 -0500, you wrote:
>At 03:09 PM 1/7/2004 +0100, you wrote:
>>Hi all,
>>
>>I am now designing a electronic metronome for myself, PIC-based of course.
>>As an extra, since I'm using crystal precision anyway, I thought of
>>including a 440 Hz (an A note) reference tone to tune flutes etc.
>>But I can't find any standard (cheap) crystal that divides nicely in 440 Hz.
>>Do you know a simple solution, that does not introduce audible jitter
>>(that would effectively ruin the use as a tuner)?
>>Are self-adjusting timer loops good enough?
>>
>>Well, thanks in advance again,
>
>How about just using a capture-compare module and whatever crystal you like?

P.S. with a 4MHz crystal, you'd use 1e6/880 = 1136 for the adder for the
timer. That would be a nominal 440.14 Hz with zero jitter. Using a 20MHz
crystal, you would use 5682 for the adder, which would yield a nominal
439.986Hz, which is within 0.0031%.

Using a 16MHz crystal and timing of 4545/4546 (still no jitter) will
be as close to perfect as you could want (10ppm), while using very little
processor time. You'd use an interrupt to update the compare register-
the only requirement is that it be serviced within 1.1msec after the
compare hit.

Best regards,

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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@110906 by cisco J. A. Ares

flavicon
face
The problem with 440 Hz is that "11" ( 440 = 11 * 5  * 2^3 ), so if you
can get a crystal or ceramic oscillator/resonator with a neat multiple
of 11 and 10, you'll probably get 440 Hz.

But 440Hz is for "tempered" (not sure about the name) scale, isn't it?
This A in natural scale is 441,48 Hz. And this difference is noticeable
just for the best ears.

You may try to use a frequency generator and play around 440 Hz to see
if a close enough value from a standard crystal would really sound as
out of tune.

Francisco


Koen van Leeuwen wrote:

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@112739 by Koen van Leeuwen

flavicon
face
> Dewd!  I have been wanting to build a metronome for a while!  Keep me
> posted on how you are doing and I will be glad to pitch in a hand.  I
> would love to build one myself.

Well, the metronome part is not too hard using the compare module and corresponding interrupt, and a lookup table (or eeprom, or math) is easily written with the right delay values to convert bpm into a 'knightrider' led display. The tick also follows from that. But, as you said, there are many ways to do this.
The 'problem' is in the tuning fork feature, which I am making too hard perhaps. I don't like listening to square waves so I  thought of a 1 bit D/A converter using the USART and an audio power opamp integrator (hmm nice thing). But then I need to have an iterrupt at a multiple of 440 Hz, increasing my frequency error...

Perhaps I should stick with a square wave, like you suggested...

> I am thinking the interrupt method would be a better
> design, though.
I agree :o)

> A straightforward user interface is a Scott Edwards serial LCD and a
> couple of buttons.  And a speaker of course.  A large diameter piezo
> driven by a transistor is all that is needed.  Geez the thing is almost
> designed already.

hmm.. an LCD would be nice indeed if i'm stuffing it with not-so-often used features...

Thank you for helping me think :o)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@113740 by

picon face
Koen van Leeuwen wrote :

> The 'problem' is in the tuning fork feature, which I am
> making too hard perhaps. I don't like listening to square
> waves so I  thought of a 1 bit D/A converter using the USART
> and an audio power opamp integrator (hmm nice thing)...


Or, if *only* generating 440Hz, a passive
low-pass filter to "shape" the waveform.

B.t.w (and absolutly not as much fun :-) ), I bought
a guitarr tuning device for about $15. Generates
all 6 tones and has a builtin "analog" LCD meter
that shows how far out of tune you are. Everything
packed in something like a matchbox...

Jan-Erik.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@114150 by Ken Pergola

flavicon
face
Hi Koen,

Here's another option while you are working out the PIC details.

Use a program like Cool Edit and create a 440 Hz sine wave and other test
tones if you so desire.
Then burn a CD with the resultant WAV files.

Obviously this requires a CD player and is not as much fun as a PIC project,
but at least you have a quick solution in the interim period.

I seem to recall that using 50% duty cycle PWM on a PIC using a 19.6608 MHz
crystal, further divided externally with N number of flip-flops gave me
tones in the equal tempered musical scale including 440 Hz -- I'll see if I
can dig up the details.

You might also do a search on "top-octave generators".

Best regards,

Ken Pergola

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@114605 by Bob Ammerman

picon face
A CCP module is restricted to multiples of the instruction rate. This will
not let the user to get exactly 440Hz.

I would recommend a DDS solution. This could have as little as one bit of
output, or it could use a lookup table and the PWM device to generate a nice
pretty sine wave.

Bob Ammerman
RAm Systems

{Original Message removed}

2004\01\07@114815 by Koen van Leeuwen

flavicon
face
I haven't heard of other "standards" before other than the A4=440 Hz.
I have read somewhere that in Mozart's time a typical A4 was 450 Hz, but it
has been standardized in 1939 as 440 Hz (Source:
www.boulder.nist.gov/timefreq/general/glossary.htm
).
That page also states that the smallest noticable difference is 0.28%, so that
gives at least some headroom :o)

So I should make my tuner tunable for other scales too :o)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@122603 by llile

flavicon
face
Yeah, these things can be bought cheap, the point is to have fun improving
it! (as you well know)


-- Lawrence Lile





"Jan-Erik Soderholm XA (TN/PAC)" <@spam@jan-erik.xa.soderholmKILLspamspamERICSSON.COM>
Sent by: pic microcontroller discussion list <KILLspamPICLISTKILLspamspamMITVMA.MIT.EDU>
01/07/2004 10:35 AM
Please respond to pic microcontroller discussion list


       To:     RemoveMEPICLISTTakeThisOuTspamMITVMA.MIT.EDU
       cc:
       Subject:        Re: [PIC:] Frequency dividing to 440 Hz


Koen van Leeuwen wrote :

> The 'problem' is in the tuning fork feature, which I am
> making too hard perhaps. I don't like listening to square
> waves so I  thought of a 1 bit D/A converter using the USART
> and an audio power opamp integrator (hmm nice thing)...


Or, if *only* generating 440Hz, a passive
low-pass filter to "shape" the waveform.

B.t.w (and absolutly not as much fun :-) ), I bought
a guitarr tuning device for about $15. Generates
all 6 tones and has a builtin "analog" LCD meter
that shows how far out of tune you are. Everything
packed in something like a matchbox...

Jan-Erik.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads



--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@123813 by Ken Pergola

flavicon
face
I wrote:

> I seem to recall that using 50% duty cycle PWM on a PIC using a 19.6608
MHz
> crystal, further divided externally with N number of flip-flops gave me
> tones in the equal tempered musical scale including 440 Hz -- I'll see if
I
> can dig up the details.


Hi Koen,

Well, I dug up the details. Sorry, using PIC PWM module and 19.6608 MHz
crystal produced only approximations to the musical scale -- would have
drove people with perfect pitch crazy.


The two closest frequencies to 440 Hz were:
       441.38
       438.86


I still thing the CD with pre-burned 440 Hz wave files would make a good
cheap tuner.

You could even use a portable CD player to play the tones.

Best regards,

Ken Pergola

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@132758 by Koen van Leeuwen

flavicon
face
On Wednesday 07 January 2004 18:24, you wrote:
> Yeah, these things can be bought cheap, the point is to have fun improving
> it! (as you well know)
>
>
> -- Lawrence Lile

uhm, as a side note, the thing I intend to build is primarily a metronome and
has the tuning feature as an improvement :o)
Of course, it would be interesting to add a freqmixer and a freq-to-voltage
converter to do some neat "the BPM is 130 and your piano is 4.52 Hz wrong"
(and with a DTMF chip "should I call the piano tuner yes/no" or with a
modified accu drill, directly adjust the snares ) but that's not what I
originally intended. Heck, I dont even have a piano.
But I would like to have an accurate reference frequency...

Thanks for thinking, all.

Koen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@133028 by llile

flavicon
face
googling to here

http://www.ece.uakron.edu/SDmaterial/spr2003/SDteam5.pdf

gets a really complete treatise on a metronome project turned in as a
senior class project for some college engineering students..  They present
pseudocode for the project, but no source code that I can see.  Also their
approach is a little complex.  Good background, though.

-- Lawrence Lile
Senior Project Engineer
Toastmaster, Inc.
Division of Salton, Inc.
573-446-5661 voice
573-446-5676 fax




Koen van Leeuwen <spamBeGonekoenspamBeGonespamVANLEEUWEN.XS4ALL.NL>
Sent by: pic microcontroller discussion list <TakeThisOuTPICLISTEraseMEspamspam_OUTMITVMA.MIT.EDU>
01/07/2004 10:26 AM
Please respond to pic microcontroller discussion list


       To:     RemoveMEPICLISTspamTakeThisOuTMITVMA.MIT.EDU
       cc:
       Subject:        Re: [PIC:] Frequency dividing to 440 Hz


> Dewd!  I have been wanting to build a metronome for a while!  Keep me
> posted on how you are doing and I will be glad to pitch in a hand.  I
> would love to build one myself.

Well, the metronome part is not too hard using the compare module and
corresponding interrupt, and a lookup table (or eeprom, or math) is easily
written with the right delay values to convert bpm into a 'knightrider'
led display. The tick also follows from that. But, as you said, there are
many ways to do this.
The 'problem' is in the tuning fork feature, which I am making too hard
perhaps. I don't like listening to square waves so I  thought of a 1 bit
D/A converter using the USART and an audio power opamp integrator (hmm
nice thing). But then I need to have an iterrupt at a multiple of 440 Hz,
increasing my frequency error...

Perhaps I should stick with a square wave, like you suggested...

> I am thinking the interrupt method would be a better
> design, though.
I agree :o)

> A straightforward user interface is a Scott Edwards serial LCD and a
> couple of buttons.  And a speaker of course.  A large diameter piezo
> driven by a transistor is all that is needed.  Geez the thing is almost
> designed already.

hmm.. an LCD would be nice indeed if i'm stuffing it with not-so-often
used features...

Thank you for helping me think :o)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads



--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@134100 by James Nick Sears

picon face
As an almost lifelong guitar player I think that A4 = 440 is pretty standard
these days.  One thing you will run into however is that while you can tune
just about every instrument you can't tune the piano (not easily and on the
spot like a guitar, etc anyway) so often times everyone will tune to
whatever it happens to be tuned to.  Many commercial tuners offer a variable
reference frequency - maybe you should look into this too.  It shouldn't be
that hard, right?

Let's start with a 440Hz square wave.  To generate this you need to toggle a
bit 880 times per second.

Say you run a 20MHz Xtal so 5MHz Inst. Clk.:
5e6 / 880 = 5681.8181.. ~= 5682 cycles (within .0033% plus the tolerance of
you oscillator which should be insignificant for this purpose if it is
working properly)

With no prescaler on TMR1 and the register loaded with zero at the start you
get an interrupt every 0x10000 or 65536 cycles.

So if you preload the TMR1 register with 65536 - 5682 = 59854 and as the
first step in your TMR1 ISR reload the timer with that same value you will
get interrupts at 879.972Hz.  In reality you also would have to account for
the few cycles it takes to get into the ISR and to the point where this
happens but this should just mean adding a constant value to the TMR1
preload depending on the specifics of your code (Add the number of cycles it
takes to get from interrupt fire to TMR1 reload).  The stopwatch feature in
MPLAB can be good for getting this sorted out.

Then you can make the TMR1 preload value a variable which is changed when
the user makes an appropriate input to the device.  One cycle difference
changes the frequency by .0774 Hz at 440Hz - (this function is of the form y
= 1/x and so is not linear).  So you could just precalculate a lookup table
as in

..
"439.91",5683
"439.99",5682
"440.06",5681
..
etc.

and use this to feed the LCD and the TMR1 preload based upon a position
determined by the user's selected frequency.

With this setup it would be very easy to tweak the frequency to say ~442Hz
or you could even make an EADGBE guitar tuner or a chromatic tuner if you
were so inclined by precalculating the TMR1 values and including them in
your lookup table.  Combining these two features would be more work though
since you can't just offset the A440 referenced TMR values by the same
amount across the scale.  (You need less adjustment at low frequencies and
more at higher frequencies so you'd either need another lookup table or some
division routines, etc.)  For a variable A4 alone though it should be pretty
easy.

Once you have your ~440Hz square wave, remember that an ideal square wave
only carries energy at multiples of the fundamental.  So you need a filter
that passes 440 (and a little cushion for frequency adjustment and component
tolerances of course) and cuts 880,1320,1760, etc.  If you could make a
perfect filter that was a brick wall at say 500Hz then you would be left
with a perfect 440Hz sine wave.  Perfect, perfect, perfect.  Yeah right.  In
reality though I think if you had a good steep filter you could get pretty
close.  Maxim makes various filter IC's that I have not actually used but I
think they just require a few external components and the IC to make 8th
order filters and the like.  Try:

http://para.maxim-ic.com/ss.asp?FAM=Filt&TREE=Filters&HP=Filters.cfm&LN=&SORD=125+122+1052+124&FT_125=202&FT_122=194&FT_1052=12374&FT_124=198&Dest=Search+%26+Update

For example look at the MAX7400/MAX7404 (8th order elliptic, switched cap
filter - http://pdfserv.maxim-ic.com/en/ds/MAX7400-MAX7407.pdf).  In the
datasheet it is spec'ed that at 1.5 * Fcorner the output is down at least
75dB (typically 82).  If your corner is 500Hz then at 750Hz (before the 2nd
harmonic) you are down ~80dB.  Should make a pretty decent representation of
a sine wave.

I would definitely filter the output.  It is definitely harder to tune a
guitar accurately with distortion on (basically morphs the guitar signal to
be more like a square wave) and I wouldn't doubt that the effect would be
similar to trying to tune to a square wave.

Good luck - sounds like a fun project.

Nick




{Original Message removed}

2004\01\07@134934 by llile

flavicon
face
Let's think about hardware for a minute:

I assume youa re not going to build more than one of these.  Neither am I.
Therefore the hardware does not have to be absolutely cheap, in fact if
it is easier to produce that is better.  If the whole cost of parts is
under a hundred clams then the Misses won't scream about it.

Power the thing with a 12 or 18V DC wall wart, and add a 5V regulator and
the power supply is done.

I am assuming that any 20MHz PIC will probably do the job, as long as it
has timer2 and enough pins.  I usually prototype with something out of the
16F87x series, since they have all the mid range peripherals.  16F873,
perhaps, would be plenty of overkill.  Crystal frequency is still a design
issue, IMHO

A serial LCD screen is hard to beat for a quick and dirty interface.  You
just write to it with an RS232 port.  Scott Edwards  BPI216N is a simple
unit that fills the bill  http://www.seetron.com/prices.htm#BPK216  $45.

If you are a real cheapskate then a Hantronics display can be had for $7
or $8, however wyou have to talk to it in Hitachi, which is a barrier
AFAIK. I would rather design something that takes minimum head-scratching.


Generally I would prefer to code something like this in C.  CCS or Hitech
either one is OK, CCS would be easiest to get up and running, since it has
the serial INVERT mode that saves messing about with a MAX232 serial level
converter.  If you are using a software UART this works, if you use a
hardware UART then a MAX232 is definitely required.

and of course, the speaker.  A large diameter piezo make sense, but it
will never sound that great being a cheap speaker.  That may be all we
need though.  Tie it to 18V across a resistor, power it with a 2N2222A
common emitter, and run the base to the PIC through a 1K resistor.  That
is the simplest sound output you can find, and will work fine for simple
sounds.  We are not playing MP3's here you know.

Any of this make sense?


-- Lawrence Lile





Koen van Leeuwen <koenEraseMEspam.....VANLEEUWEN.XS4ALL.NL>
Sent by: pic microcontroller discussion list <EraseMEPICLISTspamMITVMA.MIT.EDU>
01/07/2004 12:27 PM
Please respond to pic microcontroller discussion list


       To:     RemoveMEPICLISTEraseMEspamEraseMEMITVMA.MIT.EDU
       cc:
       Subject:        Re: [PIC:] Frequency dividing to 440 Hz


On Wednesday 07 January 2004 18:24, you wrote:
> Yeah, these things can be bought cheap, the point is to have fun
improving
> it! (as you well know)
>
>
> -- Lawrence Lile

uhm, as a side note, the thing I intend to build is primarily a metronome
and
has the tuning feature as an improvement :o)
Of course, it would be interesting to add a freqmixer and a
freq-to-voltage
converter to do some neat "the BPM is 130 and your piano is 4.52 Hz wrong"
(and with a DTMF chip "should I call the piano tuner yes/no" or with a
modified accu drill, directly adjust the snares ) but that's not what I
originally intended. Heck, I dont even have a piano.
But I would like to have an accurate reference frequency...

Thanks for thinking, all.

Koen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads



--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@135936 by llile

flavicon
face
Nice stuff, James.  Good point about the filter.

I would argue for using the simplest possible output (unfiltered) first,
trying it, then going with the simplest possible filter (an RC filter)
trying that, and then go for the complex but better performing filter if
needed.   I find when I take that approach, I get the project off the
ground and working, then have more motivation to get the trickier details
done.  If I design the whole thing out to be the finest from the start
(the way I might do a commercial project) it takes so much time that I am
on to some other project before the thing is finished.  Hobbies are never
done, you know.   So far this sound to me like a rainy afternoon
construction project.  I may even have the hardware I described laying
around from something else.

-- Lawrence Lile

"You can tune a piano, but you cannot tuna fish."





James Nick Sears <RemoveMEjsears2027spam_OUTspamKILLspamHOTMAIL.COM>
Sent by: pic microcontroller discussion list <RemoveMEPICLISTTakeThisOuTspamspamMITVMA.MIT.EDU>
01/07/2004 12:40 PM
Please respond to pic microcontroller discussion list


       To:     EraseMEPICLISTspamspamspamBeGoneMITVMA.MIT.EDU
       cc:
       Subject:        Re: [PIC:] Frequency dividing to 440 Hz


As an almost lifelong guitar player I think that A4 = 440 is pretty
standard
these days.  One thing you will run into however is that while you can
tune
just about every instrument you can't tune the piano (not easily and on
the
spot like a guitar, etc anyway) so often times everyone will tune to
whatever it happens to be tuned to.  Many commercial tuners offer a
variable
reference frequency - maybe you should look into this too.  It shouldn't
be
that hard, right?

Let's start with a 440Hz square wave.  To generate this you need to toggle
a
bit 880 times per second.

Say you run a 20MHz Xtal so 5MHz Inst. Clk.:
5e6 / 880 = 5681.8181.. ~= 5682 cycles (within .0033% plus the tolerance
of
you oscillator which should be insignificant for this purpose if it is
working properly)

With no prescaler on TMR1 and the register loaded with zero at the start
you
get an interrupt every 0x10000 or 65536 cycles.

So if you preload the TMR1 register with 65536 - 5682 = 59854 and as the
first step in your TMR1 ISR reload the timer with that same value you will
get interrupts at 879.972Hz.  In reality you also would have to account
for
the few cycles it takes to get into the ISR and to the point where this
happens but this should just mean adding a constant value to the TMR1
preload depending on the specifics of your code (Add the number of cycles
it
takes to get from interrupt fire to TMR1 reload).  The stopwatch feature
in
MPLAB can be good for getting this sorted out.

Then you can make the TMR1 preload value a variable which is changed when
the user makes an appropriate input to the device.  One cycle difference
changes the frequency by .0774 Hz at 440Hz - (this function is of the form
y
= 1/x and so is not linear).  So you could just precalculate a lookup
table
as in

..
"439.91",5683
"439.99",5682
"440.06",5681
..
etc.

and use this to feed the LCD and the TMR1 preload based upon a position
determined by the user's selected frequency.

With this setup it would be very easy to tweak the frequency to say ~442Hz
or you could even make an EADGBE guitar tuner or a chromatic tuner if you
were so inclined by precalculating the TMR1 values and including them in
your lookup table.  Combining these two features would be more work though
since you can't just offset the A440 referenced TMR values by the same
amount across the scale.  (You need less adjustment at low frequencies and
more at higher frequencies so you'd either need another lookup table or
some
division routines, etc.)  For a variable A4 alone though it should be
pretty
easy.

Once you have your ~440Hz square wave, remember that an ideal square wave
only carries energy at multiples of the fundamental.  So you need a filter
that passes 440 (and a little cushion for frequency adjustment and
component
tolerances of course) and cuts 880,1320,1760, etc.  If you could make a
perfect filter that was a brick wall at say 500Hz then you would be left
with a perfect 440Hz sine wave.  Perfect, perfect, perfect.  Yeah right.
In
reality though I think if you had a good steep filter you could get pretty
close.  Maxim makes various filter IC's that I have not actually used but
I
think they just require a few external components and the IC to make 8th
order filters and the like.  Try:

http://para.maxim-ic.com/ss.asp?FAM=Filt&TREE=Filters&HP=Filters.cfm&LN=&SORD=125+122+1052+124&FT_125=202&FT_122=194&FT_1052=12374&FT_124=198&Dest=Search+%26+Update

For example look at the MAX7400/MAX7404 (8th order elliptic, switched cap
filter - http://pdfserv.maxim-ic.com/en/ds/MAX7400-MAX7407.pdf).  In the
datasheet it is spec'ed that at 1.5 * Fcorner the output is down at least
75dB (typically 82).  If your corner is 500Hz then at 750Hz (before the
2nd
harmonic) you are down ~80dB.  Should make a pretty decent representation
of
a sine wave.

I would definitely filter the output.  It is definitely harder to tune a
guitar accurately with distortion on (basically morphs the guitar signal
to
be more like a square wave) and I wouldn't doubt that the effect would be
similar to trying to tune to a square wave.

Good luck - sounds like a fun project.

Nick




{Original Message removed}

2004\01\07@140143 by James Nick Sears

picon face
Oops.  This lookup table should actually be
..
"439.91",59853
"439.99",59854
"440.06",59855
..
(with adjustments for getting into the ISR, etc) if you want to load the
value directly to TMR1.


> Then you can make the TMR1 preload value a variable which is changed when
> the user makes an appropriate input to the device.  One cycle difference
> changes the frequency by .0774 Hz at 440Hz - (this function is of the form
y
> = 1/x and so is not linear).  So you could just precalculate a lookup
table
{Quote hidden}

some
> division routines, etc.)  For a variable A4 alone though it should be
pretty
> easy.
>
> Once you have your ~440Hz square wave, remember that an ideal square wave
> only carries energy at multiples of the fundamental.  So you need a filter
> that passes 440 (and a little cushion for frequency adjustment and
component
> tolerances of course) and cuts 880,1320,1760, etc.  If you could make a
> perfect filter that was a brick wall at say 500Hz then you would be left
> with a perfect 440Hz sine wave.  Perfect, perfect, perfect.  Yeah right.
In
> reality though I think if you had a good steep filter you could get pretty
> close.  Maxim makes various filter IC's that I have not actually used but
I
> think they just require a few external components and the IC to make 8th
> order filters and the like.  Try:
>
>
http://para.maxim-ic.com/ss.asp?FAM=Filt&TREE=Filters&HP=Filters.cfm&LN=&SORD=125+122+1052+124&FT_125=202&FT_122=194&FT_1052=12374&FT_124=198&Dest=Search+%26+Update
>
> For example look at the MAX7400/MAX7404 (8th order elliptic, switched cap
> filter - http://pdfserv.maxim-ic.com/en/ds/MAX7400-MAX7407.pdf).  In the
> datasheet it is spec'ed that at 1.5 * Fcorner the output is down at least
> 75dB (typically 82).  If your corner is 500Hz then at 750Hz (before the
2nd
> harmonic) you are down ~80dB.  Should make a pretty decent representation
of
> a sine wave.
>
> I would definitely filter the output.  It is definitely harder to tune a
> guitar accurately with distortion on (basically morphs the guitar signal
to
> be more like a square wave) and I wouldn't doubt that the effect would be
> similar to trying to tune to a square wave.
>
> Good luck - sounds like a fun project.
>
> Nick
>
>
>
>
> {Original Message removed}

2004\01\07@141013 by James Nick Sears

picon face
> Nice stuff, James.  Good point about the filter.

Thanks.  I totally agree with you about the incremental development.  One
other thing I want to make sure the OP knows that is relevant to this is
that Maxim will send you a handful of those (or any of their) ICs totally
free with no questions asked if you order samples from their website.  So
I'd order up and then develop the simple version.  By the time this is done
you should have a package of free chips to play with and a circuit that is
ready to use them.

Nick


{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@141430 by Koen van Leeuwen

flavicon
face
Well, this might be the right moment to make clear I am a EE student in my
second year, having just a little experience in asm, even less in C (more in
Java, but that's irrelevant I guess) and about two months experience with
PICs, not even related to my courses :o)
My 'development environment' consists of:
Linux box 300 MHz, using gputils (assembler MPASM compatible) and gpsim
Parallel port programmer made in 10 minutes using parts from a dead ATX supply
       (hardwired for 16F62[78], but I guess it's compatible with others too)
Standard soldering equipment
Cheap DMM

So I have to do a lot of paper design first, because I don't have much parts
"on the shelf" and that makes it difficult to extend projects later.

Being a student defines me to be a cheapskate, I guess (Also, I'm dutch,
so...)

Don't expect too much from me, if you are planing to build one (as for the
parts, I only have a 16F628 ATM, not even a crystal or cap with a known
value. (lots of caps with unknown values) ).

Greetings,

Koen van Leeuwen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@142501 by Jinx

face picon face
Spehro's alternate timing intervals would be an easy and
pretty accurate solution

> Using a 16MHz crystal and timing of 4545/4546

This would give a mark:space of 1136.25us : 1136.5us

440Hz = period of 2272.73us

1136.25 + 1136.5 = 2272.75 = 439.9956Hz = 0.0001% low

> ...other "standards" .... other than the A4=440 Hz.

> http://www.boulder.nist.gov/timefreq/general/glossary.htm

You'll notice that the page also mentions how other notes in a
particular scale are derived from the root. What this means is that
the "A" in the key of C is not the same frequency as the "A" in the
key of Eb. According to purists, music becomes discordant if there
is a key change. Ideally all instruments should change their tuning
to the root of the key moved into. Possible with an electronic k/b, a
bit tricky with tubular bells

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@145544 by Olin Lathrop

face picon face
Ken Pergola wrote:
> Well, I dug up the details. Sorry, using PIC PWM module and 19.6608
> MHz crystal produced only approximations to the musical scale --
> would have drove people with perfect pitch crazy.
>
>
> The two closest frequencies to 440 Hz were:
>         441.38
>         438.86

I don't know where you got that from.  It seems that a fast enough crystal
gives enough resolution so that you can hit any frequency in the 440Hz range
with sufficient accuracy.

With a 20MHz crystal you get a 5MHz instruction rate.  This is essentially
what you get to divide down if using a PIC.  5MHz / 440Hz = 11,363.64
approximately.  This means you could hit

 5MHz / 11,363 = 440.02Hz
 5MHz / 11,364 = 439.99Hz

The last one is off by 32ppm, or less than .0006 of a semi-tone.  Even the
first one is only off by 56ppm or less than .001 semi-tones.  At this rate
the crystal accuracy becomes a significant portion of the overall error.

Isn't that well more than good enough?


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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@153111 by Koen van Leeuwen

flavicon
face
That still limits me to a square wave though.
It would be nice to have some time for some d/a conversion that would lead to
a lower THD. (less parts, more complex software = cheaper and more fun for a
hobbyist)

Anybody built an d/a convertor out of the USART and and integrator before or
am I the first (I mean, with a PIC. I know SACD works roughly this way)?
The idea:
1 = curve goes up
0 = curve goes down
Tied to an integrator with virtual ground at Vdd/2 this would give the curve
back.
So a sine would look like 111011010101001000000100101010110111 and loop
(draw it if you don't see it)
As you can see this is quite small, and can be compressed much more: a sine is
pointsymmetrical(?) so you can mirror halfway, and invert a quarter.
So you only have to store a quarter of a period, one byte would lead to 32
samples/period. I haven't been able to calculate the harmonic distortion, but
its surely more smooth than a square wave :o)

But I guess I have to open up my filter design book... oh wait thats a next
quarter course... :o)

Greetings,

Koen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@154811 by Ken Pergola

flavicon
face
Olin Lathrop wrote:

> I don't know where you got that from.

Hi Olin,

Well I do. :)

Let me explain:

My goal was not to generate 440 Hz. I posted because I thought I could help
the original poster with the results of an old project.

As I said in my previous post, in a past project I was using the *PWM
module* and a 19.6608 MHz crystal.
The duty cycle would be adjusted in firmware to be 50% no matter what the
frequency was selected, and the frequency is controlled by changing the
value in PR2.

Thus, 256 distinct frequencies are produced over a frequency range of 300 Hz
to 76,800 Hz (with some of the upper frequencies obviously beyond the range
of (some) humans):

If I remember correctly, I believe I ran the raw PWM output through a divide
by 4 circuit (using 74xx161 ) to get the following frequencies:



PR2     PWM Freq
---     --------

0      76,800.00
1      38,400.00
2      25,600.00
.          .
.          .
.        .
173      441.38
174      438.86
.          .
.          .
.        .
253      302.36
254      301.18
255      300.00



If you look at all 256 frequencies (see below), it is evident that that a
limited portion of the table comes pretty close to the following octave in
the equal-tempered chromatic scale:

Note Frequency
A  440.00
A# 466.16
B  493.88
C  523.25
C# 554.37
D  587.33
D# 622.25
E  659.26
F  698.46
F# 739.99
G  783.99
G# 830.61
A  880.00



My goal was not to generate 440 Hz nor a perfectly-tuned musical instrument,
it was to generate frequencies in the equal-tempered scale as best I could
given the 19.6608 MHz crystal.

Hope this helps and clears things up. I could post the whole PWM table if
you want.


Best regards,

Ken Pergola



PR2  FREQ

86 882.76
87 872.73
88 862.92
89 853.33
90 843.96
91 834.78
92 825.81
93 817.02
94 808.42
95 800.00
96 791.75
97 783.67
98 775.76
99 768.00
100 760.40
101 752.94
102 745.63
103 738.46
104 731.43
105 724.53
106 717.76
107 711.11
108 704.59
109 698.18
110 691.89
111 685.71
112 679.65
113 673.68
114 667.83
115 662.07
116 656.41
117 650.85
118 645.38
119 640.00
120 634.71
121 629.51
122 624.39
123 619.35
124 614.40
125 609.52
126 604.72
127 600.00
128 595.35
129 590.77
130 586.26
131 581.82
132 577.44
133 573.13
134 568.89
135 564.71
136 560.58
137 556.52
138 552.52
139 548.57
140 544.68
141 540.85
142 537.06
143 533.33
144 529.66
145 526.03
146 522.45
147 518.92
148 515.44
149 512.00
150 508.61
151 505.26
152 501.96
153 498.70
154 495.48
155 492.31
156 489.17
157 486.08
158 483.02
159 480.00
160 477.02
161 474.07
162 471.17
163 468.29
164 465.45
165 462.65
166 459.88
167 457.14
168 454.44
169 451.76
170 449.12
171 446.51
172 443.93
173 441.38
174 438.86

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@155813 by Koen van Leeuwen

flavicon
face
On Wednesday 07 January 2004 21:30, I wrote:
> That still limits me to a square wave though.
> It would be nice to have some time for some d/a conversion that would lead
> to a lower THD. (less parts, more complex software = cheaper and more fun
> for a hobbyist)

hmm.
A little calculation shows that I have this time.
I need an interrupt every 355 cycles (@5 mhz), one bit every interrupt, 32
bits/period:
5MHz/(335*32)=440.14 Hz (=0.03% high)
355 cycles to calculate what bit should be given to the integrator should be
enough :)

hmm again.
A pic running at 20 MHz xtal driving a 40 bpm led string is a division by
30000000... (after all it started with a metronome)
well...
thats gonna eat some registers...

Greets

Koen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@180630 by llile

flavicon
face
Google on "magic sine waves" and then let your jaw flop to the ground.
This is sort of what you are proposing.



-- Lawrence Lile
Senior Project Engineer
Toastmaster, Inc.
Division of Salton, Inc.
573-446-5661 voice
573-446-5676 fax




Koen van Leeuwen <RemoveMEkoenKILLspamspamVANLEEUWEN.XS4ALL.NL>
Sent by: pic microcontroller discussion list <PICLISTSTOPspamspamspam_OUTMITVMA.MIT.EDU>
01/07/2004 02:30 PM
Please respond to pic microcontroller discussion list


       To:     spamBeGonePICLISTSTOPspamspamEraseMEMITVMA.MIT.EDU
       cc:
       Subject:        Re: [PIC:] Frequency dividing to 440 Hz


That still limits me to a square wave though.
It would be nice to have some time for some d/a conversion that would lead
to
a lower THD. (less parts, more complex software = cheaper and more fun for
a
hobbyist)

Anybody built an d/a convertor out of the USART and and integrator before
or
am I the first (I mean, with a PIC. I know SACD works roughly this way)?
The idea:
1 = curve goes up
0 = curve goes down
Tied to an integrator with virtual ground at Vdd/2 this would give the
curve
back.
So a sine would look like 111011010101001000000100101010110111 and loop
(draw it if you don't see it)
As you can see this is quite small, and can be compressed much more: a
sine is
pointsymmetrical(?) so you can mirror halfway, and invert a quarter.
So you only have to store a quarter of a period, one byte would lead to 32
samples/period. I haven't been able to calculate the harmonic distortion,
but
its surely more smooth than a square wave :o)

But I guess I have to open up my filter design book... oh wait thats a
next
quarter course... :o)

Greetings,

Koen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads



--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@182335 by Andrew Warren

flavicon
face
llile@saltonusa.com <KILLspamPICLISTspamBeGonespammitvma.mit.edu> wrote:

> Google on "magic sine waves" and then let your jaw flop to the
> ground. This is sort of what you are proposing.

   Actually, Koen's proposal looked like straight PWM; I'm sure the
   PICLIST archives contain numerous examples of PWM sine-wave
   generation using a quarter-period lookup table.  Lancaster's
   "magic sine waves" are different in that they cancel harmonics.

   -Andy

=== Andrew Warren -- EraseMEaiwspamEraseMEcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@193503 by Koen van Leeuwen

flavicon
face
On Thursday 08 January 2004 00:27, you wrote:
>     Actually, Koen's proposal looked like straight PWM; I'm sure the
>     PICLIST archives contain numerous examples of PWM sine-wave
>     generation using a quarter-period lookup table.  Lancaster's
>     "magic sine waves" are different in that they cancel harmonics.

There is nothing magic about it, but its not PWM either (at least, I use only
full on/full off).
The thing that makes it look like a sine wave is the integrating amplifier.
See the attached PNG:
Green the sine I want to achieve, blue the PIC output and red the integrand of
the PIC output.
In binary the PIC output is 11110110 10010000 00001001 01101111,
which is 0xF6, 0xF6 flipped&inverted, 0xF6 inverted, 0xF6 flipped.
So you need a quarter-period lookup table of 1 byte. That's not a large
table...

I hope this makes something clear :o)

Koen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@194128 by Andrew Warren

flavicon
face
Koen van Leeuwen <@spam@PICLIST@spam@spamspam_OUTmitvma.mit.edu> wrote:

> its not PWM either (at least, I use only full on/full off). The
> thing that makes it look like a sine wave is the integrating
> amplifier.

   That's PWM.

   -Andy

=== Andrew Warren -- spamBeGoneaiwspamKILLspamcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@194540 by Koen van Leeuwen

flavicon
face
On Thursday 08 January 2004 01:45, you wrote:

>     That's PWM.
OK.
Sorry.
I thought PWM had a fixed pulse frequency, but I see thats not needed.
Thanks.

Koen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@200857 by Koen van Leeuwen

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

On Thursday 08 January 2004 01:32, I wrote:

> See the attached PNG:
> Green the sine I want to achieve, blue the PIC output and red the integrand
> of the PIC output.

damn those attachments :o|
(and my memory)

Goodnight,

Koen

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads




part 2 1532 bytes content-type:image/png; (decode)

2004\01\07@201853 by Jinx

face picon face
>     Actually, Koen's proposal looked like straight PWM; I'm sure the
>     PICLIST archives contain numerous examples of PWM sine-wave
>     generation

There's a fair bit of practical and theory at http://www.sxlist.com too

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@202100 by Andrew Warren

flavicon
face
Koen van Leeuwen <.....PICLISTspam_OUTspammitvma.mit.edu> wrote:

> I thought PWM had a fixed pulse frequency, but I see thats not needed.

   Oh, I see.  Yes, your method is different from the high-frequency
   PWM method that would be used if you wanted to output, say, 128
   8-bit samples per period. I guess the most straightforward method
   of doing that would require a pulse frequency of 128 * 256 * your
   fundamental frequency.

   I would call both methods "PWM", but perhaps that's not correct
   (or not the standard usage, anyway).

   In any case, the method you proposed has advantages over the
   very-high-frequency method, although you'll have a lot of
   harmonic content if you really plan to do it with only 7 pulses
   per period.

   -Andy

=== Andrew Warren -- TakeThisOuTaiw.....spamTakeThisOuTcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@203342 by Jinx

face picon face
> 1 = curve goes up
> 0 = curve goes down
> Tied to an integrator with virtual ground at Vdd/2 this would give
> the curve back

I use audio processors that do exactly this with CVSD. Data is
stored in SRAM/EPROM and written/read serially. They can
reproduce music at around about cassette quality

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\07@233514 by Russell McMahon

face
flavicon
face
> > Google on "magic sine waves" and then let your jaw flop to the
> > ground. This is sort of what you are proposing.
>
>     Actually, Koen's proposal looked like straight PWM; I'm sure the
>     PICLIST archives contain numerous examples of PWM sine-wave
>     generation using a quarter-period lookup table.  Lancaster's
>     "magic sine waves" are different in that they cancel harmonics.

Lancaster's magic sine waves aren't magic and they aren't Lancaster's, but
he has publicised them well enough that he deserves some mileage from the
concept.

A MSW with a given number of transitions is the minimum error PWM
approximation that you can achieve to a perfect sine wave. I'm told (and
haven't yet tried it)(but intend to) that you get the same sequences by
setting a predefined error limit, setting your output to zero, summing the
accumulated error wrt to a sine wave with respect to time and then flipping
the output every time the error reaches the limit. Someone may wish to try
this. The mean error overall will be less than the error limit that you use
to toggle the output.


       RM

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\08@020627 by Scott Dattalo

face
flavicon
face
On Thu, 8 Jan 2004, Russell McMahon wrote:

{Quote hidden}

This makes intuitive sense, Russell. However, it's theoretically possible
to construct a stream of pulses that exactly cancel the first N harmonics,
where N is an arbitrarily large number. However, the N+1'st and higher
harmonics will contain a significant amount of energy. The idea is that a
simple low pass filter can be constructed to eliminate these higher
harmonics. The problem with the theory is that in order to cancel the
first N harmonics, something on the order of N factorial pulses are needed
for just a single cycle of the sine wave. This becomes practically
difficult when N is 10 or so.

You can check out some of the mathematics here:

http://www.dattalo.com/technical/theory/sqwave.html

I haven't found any other analysis of this kind of stuff. I found
Lancaster's page lacking in mathematical detail.

Other's have also suggest differential pulse-code modulation somewhat like
something Roman Black had written about a few years ago on the list. In
this scheme it's assumed that the impedance of the device being driven by
the square wave is known. (This can be a simple RC low-pass filter that is
buffered with an opamp). A model of this impedance is created in the PIC.
A square wave stream is created and it's output is adjusted based on the
feedback from the output of the simulated impedance. Of course, if one had
a really fast A/D then the output signal of the real impedance could be
fed back and servo'd to the sine wave (or whatever analog signal one
wishes to produce). But for simple things like tone generators, this open
looped approach (or simulated closed loop) can generate a reasonable
sound.

Here are some graphs I created from an Octave script to investigate this:

http://www.dattalo.com/p2.png
http://www.dattalo.com/p3.png
http://www.dattalo.com/p4.png

Here's the Octave script:

http://www.dattalo.com/swsd.m

Roman's page is here:

http://centauri.ezy.net.au/~fastvid/picsound.htm

Scott

--
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

2004\01\08@034950 by Alan B. Pearce

face picon face
>and of course, the speaker.  A large diameter piezo make sense, but it
>will never sound that great being a cheap speaker.  That may be all we
>need though.  Tie it to 18V across a resistor, power it with a 2N2222A
>common emitter, and run the base to the PIC through a 1K resistor.  That
>is the simplest sound output you can find, and will work fine for simple
>sounds.  We are not playing MP3's here you know.

Well if going this route, and using a wall wart at 9-18V, then why not use
an LM386 power amp IC, or similar, and a transistor radio speaker.

--
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

2004\01\08@045122 by James Nick Sears

picon face
As long as you are PWM-ing (or even if you were just filtering a square
wave) why not just drive a logic-level FET through an LC filter.  For that
matter, consider that for a fixed frequency you are essentially generating a
PWM signal by making a 440Hz square wave.  The only problem with that is the
same problem with 44.1kHz digital audio.  You have to create a filter that
goes from 0 to -infinity in 1 octave.

Good luck.

Nick


{Original Message removed}

2004\01\08@104315 by llile

flavicon
face
>Lancaster's magic sine waves aren't magic and they aren't Lancaster's,
but
he has publicised them well enough that he deserves some mileage from the
concept.

Yeah, "Magic" is an unfortunate word that Lancaster used to popularize the
concept.  What blew my mind was the mathematical elegance of the concept.
Generally if I see something touted as "magic" I hit the delete button
fast because it is almost always a scam.

Lancaster may not have invented much, but he has sure produced volumes of
clear, concise, readable docs on all subjects electronic.  Lancaster,
Ciarcia, and a few other authors are way up there on my list.

My feeling is that the "Magic sine wave" concept is way to complex for
this appliaction.  But hey, it is just software, it could be part of
Release II.

-- Lawrence Lile





Russell McMahon <TakeThisOuTapptechKILLspamspamspamPARADISE.NET.NZ>
Sent by: pic microcontroller discussion list <.....PICLISTspamRemoveMEMITVMA.MIT.EDU>
01/07/2004 10:35 PM
Please respond to pic microcontroller discussion list


       To:     RemoveMEPICLISTspamspamBeGoneMITVMA.MIT.EDU
       cc:
       Subject:        Re: [PIC:] Frequency dividing to 440 Hz



--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads



--
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

2004\01\08@110409 by Spehro Pefhany

picon face
At 09:41 AM 1/8/2004 -0600, you wrote:
> >Lancaster's magic sine waves aren't magic and they aren't Lancaster's,
>but
>he has publicised them well enough that he deserves some mileage from the
>concept.
>
>Yeah, "Magic" is an unfortunate word that Lancaster used to popularize the
>concept.  What blew my mind was the mathematical elegance of the concept.
>Generally if I see something touted as "magic" I hit the delete button
>fast because it is almost always a scam.
>
>Lancaster may not have invented much, but he has sure produced volumes of
>clear, concise, readable docs on all subjects electronic.  Lancaster,
>Ciarcia, and a few other authors are way up there on my list.

Agree. He (and others such as Bob Pease) may be going a bit to seed
these days, but they have done a lot for the hobby, and contributed to the
industry as well.

>My feeling is that the "Magic sine wave" concept is way to complex for
>this appliaction.  But hey, it is just software, it could be part of
>Release II.

If the number of additional edges is small (as suggested), and the
tightest ones are reasonably spaced, it's not that much to do- just
work out a table with the values and step through it on each CCP
interrupt. The overall frequency accuracy remains just as high as
the square wave numbers which we've already worked out. There will
some degradation of the harmonic reduction from the granularity of
the edge timing, but that's no big deal for reasonable numbers.

This is a REALLY easy case- the frequency is low and fixed, and
the amplitude is fixed.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
spamBeGonespeff@spam@spamspam_OUTinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.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

2004\01\09@045448 by Peter L. Peres

picon face
>Anybody built an d/a convertor out of the USART and and integrator before
>or am I the first (I mean, with a PIC. I know SACD works roughly this
>way)?

You are not. I used it for speech output. You can wire a headphone speaker
directly to a RS232 output. I used PWM not sigma-delta, what you seem to
be trying, at 115.2kBauds, and xor-modulated it with a block of white
noise so there was no whistling. The driver was simply a user mode program
driving a standard comms port by opening a file and writing to it.

The interesting part is to do it the other way around, a/d using the
serial input. I do not know how this could be done but something clever
involving 'modulation' from TxD could be devised.

Peter

--
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 2004 , 2005 only
- Today
- New search...