Author Topic: Generating audio tones with PIC micro  (Read 2064 times)

0 Members and 1 Guest are viewing this topic.

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2797
  • Country: au
Generating audio tones with PIC micro
« on: January 19, 2015, 07:06:15 am »
I have a project where I'm generating audio tones with a 8-bit PIC microcontroller.  At present I'm using the CCP module in PWM mode.

To generate a rise-fall siren, I'm stepping the frequency (PR2 value) every 50ms. There is a bit flag to keep track of whether I'm going up or down in value.

This works over a short range of frequencies, but since the on-time is fixed it leaves something to be desired.

Is there a way to use the PIC hardware to generate tones with 50% duty cycle without having to calculate the width (for the other registers) for each step?

There are comms (38400 baud) interrupts occurring all of the time so I don't think bit banging the tones is an option.
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4206
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Generating audio tones with PIC micro
« Reply #1 on: January 19, 2015, 08:20:04 am »
It's one register... write the period, shift right one place, write the 'on' time. Not hard or time consuming.

Code: [Select]
PR2 = period;
CCPR2L = period >> 1;
« Last Edit: January 19, 2015, 08:22:16 am by AndyC_772 »
 

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2797
  • Country: au
Re: Generating audio tones with PIC micro
« Reply #2 on: January 19, 2015, 10:57:55 pm »
Thanks Andy.  That works a treat.   :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf