Tone Generator

Discussion in 'Programmer's Corner' started by chrisw1990, Mar 24, 2012.

  1. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    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:
    Code ( (Unknown Language)):
    1. void codeGenerator(char note, char length)
    2. {
    3. Etc..
    4. }
    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
     
  2. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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.
     
  3. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    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: Mar 26, 2012
  4. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Yes it can work on any timer overflow interrupt.

    So which PIC does not have a timer0?
     
  5. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    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: Mar 26, 2012
Loading...