Tone Generator

Thread Starter

chrisw1990

Joined Oct 22, 2011
551
Hi,
Me again,
Basically, i dont wanna be told how do implement a tone generator, but using a pic32 my concept was to use the pwm, at set frequency, (from wikipedia) say an A - 440Hz, and it went on for one beat so say a quarter or a second..
so the function would look like this:
Rich (BB code):
void codeGenerator(char note, char length)
{
Etc..
}
But, my implementation was using a timer, in a little while loop, waiting for the length of time specified to be done with.. but obviously i cant sit my pic in a little while loop for a quarter of a second when it has to do lots of other tasks.
so my question is: how else would i go about implementing the timing side of it?
Cheers
Hope this makes sense
 

THE_RB

Joined Feb 11, 2008
5,438
Hi, have a look at the C routines here;
http://www.romanblack.com/one_sec.htm

They can run in a timer interrupt (ie every 256 or 512 instructions) and will generate any freq you like from any interrupt and any xtal.

They can even be repeated in the interrupt to produce more than one tone at once.
 

Thread Starter

chrisw1990

Joined Oct 22, 2011
551
a useful website! very in fact (small correction by the way, not all pics have timer0 but im just being picky;))
This will also come in handy for implementing the thousandths clock i was thinking about! wahey! just need to figure out how it works (the thousandths clock bit anyway)
many thanks!
Also, I assume this is when timers Overflow, rather than count to a specific value? like the timers in PIC32, at least timer 1 does that for sure..
 
Last edited:

Thread Starter

chrisw1990

Joined Oct 22, 2011
551
my pic 32..:D
oh and, assuming thats your site, its very helpful all over!

ok, question, reading the hundredths of a second version of the code, why 2048? and also, that portion of code depends on bit3 toggling, but that obviously wouldnt trigger an overflow (and therefore interrupt) so how did you get it to trigger?
 
Last edited:
Top