Hi
Did some tests with different parameters to test out the tones with the codes below. Would like to share my observations and hear your comments. The thing with hearing sound is, after a while, they all seem to be quite the same and inconsistencies begin to appear. Perhaps someone can give, at least the theoretical aspects of what each parameter should adjust, since I may be one of those quintessential tone-deafness
sufferer!!
Code:
#include <p18f4550.h>
#include <delays.h>
#pragma config FOSC = HS
#pragma config PWRT = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config LVP = OFF
void init(void);
void PWM(unsigned char i);
// Initial
void init(void)
{
CMCON=0b00000111; // Close Comparator
TRISA=0b00010000;
TRISB=0b00000001;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00001000;
ADCON1=0b00001111; // Configure Digital Channel
CCP1CON=0b00001100;
}
// Set PWM Mode
void PWM(unsigned char i)
{
CCPR1L = 25*i;
}
// Main Programmer
void main( void )
{
unsigned char i;
init();
//test1
// Sound 1
/* T2CONbits.TMR2ON = 0; //0=timer2 is off, 1=timer2 is on
T2CONbits.T2OUTPS3 = 1;
T2CONbits.T2OUTPS2 = 1;
T2CONbits.T2OUTPS1 = 1;
T2CONbits.T2OUTPS0 = 1;
T2CONbits.T2CKPS1 = 1;
T2CONbits.T2CKPS0 = 1;
PR2 = 255;
TRISCbits.TRISC2=0; // set RC2 (buzzer) port an output
T2CONbits.TMR2ON = 1;
for (i=0;i<2;i++)
{
PWM(4);
Delay1KTCYx(150);
PWM(0);
Delay1KTCYx(150);
}
}
Played with the following parameters to create "different" sounds:
1. Sound A : Pre-scaler=11, Post-scaler=1111, PR=255, CCPR1L=4*25
2. Sound B : Pre-scaler=00, Post-scaler=0000, PR=255, CCPR1L=4*25
3. Sound C : Same as Sound A except different CCPR1L=8*25
4. Sound D : Same as Sound B except different CCPR1L=8*25
5. Sound E : Same as Sound A except different PR=30
6. Sound F : Same as Sound B except different PR=30
My observations as follows when I compare the sounds :
a. Sound A vs Sound B : Sound A has higher tone
b. Sound A vs Sound C : Same tone, but sound C is louder
c. Sound B vs Sound D : Same tone, but sound D is louder
d. Sound A vs Sound E : Sound A has higher tone, Sound E is louder
e. Sound B vs Sound F : Sound F has higher tone and is louder
Preliminary conclusions :
i) Pre & Post scaler affects tone.
ii) CCPR1L affects loudness
iii) Am not sure abt PR though...perhaps my tone-deafness kicks in by then.