View Single Post
  #15   Spotlight this post!  
Unread 27-09-2007, 13:16
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,708
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Project Questions about Programming and Electrical

Ryan,

PWM outputs 13-16 are directly connected to the user processor's CCP modules, so you can use them to generate timed pulses. The default code has a section briefly covering this:
Code:
/* FIFTH: Set your PWM output types for PWM OUTPUTS 13-16.
  /*   Choose from these parameters for PWM 13-16 respectively:               */
  /*     IFI_PWM  - Standard IFI PWM output generated with Generate_Pwms(...) */
  /*     USER_CCP - User can use PWM pin as digital I/O or CCP pin.           */
  Setup_PWM_Output_Type(IFI_PWM,IFI_PWM,IFI_PWM,IFI_PWM);

  /* 
     Example: The following would generate a 40KHz PWM with a 50% duty cycle on the CCP2 pin:

         CCP2CON = 0x3C;
         PR2 = 0xF9;
         CCPR2L = 0x7F;
         T2CON = 0;
         T2CONbits.TMR2ON = 1;

         Setup_PWM_Output_Type(USER_CCP,IFI_PWM,IFI_PWM,IFI_PWM);
  */
One use for the CCP hardware was replacing the IFI code for the PWMs with more stable code. This is described here.

So, using the CCP, you can get a square wave signal at (mostly) whatever frequency you want, but two problems remain. First, the signal will oscillate between 0(ish)V and 5(ish)V. Sending something like this through a speaker isn't particularly nice. Especially if the 0V side isn't 0V, as then you'd be constantly sending a current through the speaker. So you'd need an op-amp circuit to shift the square wave so it oscillates around 0V.

You could, in fact, send this through the speaker, but it'd sound a bit odd as it's not a nice sine wave like a pure audio tone is. It's possible to get a nice pure tone out of a square wave, however. The sharp edges (more or less) represent higher frequency components of the signal. So if you create a filtering circuit to filter out high frequencies, you'll get a much purer, cleaner tone. That bit isn't as necessary to making a sound come out of the speaker, though.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter