How can I put "tick" sound ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Visit site
Activity points
9,442
Guys,

I wanna create "tick" sound in between of second on my clock,

Here's the function :
Code:
/* initialise the PWM */

void pwm_init(void)
{
    /* use OC1A pin as output */
    DDRB = _BV(PB5);

    /*
    * clear OC1A on compare match
    * set OC1A at BOTTOM, non-inverting mode
    * Fast PWM, 8bit
    */
   TCCR1A = _BV(COM1A1) | _BV(WGM10);
   
    /*
    * Fast PWM, 8bit
    * Prescaler: clk/1 = 8MHz
    * PWM frequency = 8MHz / (255 + 1) = 31.25kHz
    */
  TCCR1B = _BV(WGM12) | _BV(CS10);
   
    /* set initial duty cycle to zero */
    //OCR1A = 0;
   
    sample_count = 4;
	sei();
}

beep_sound()
{
	 sample_count--;
	 if (sample_count == 0)
	 {
		 sample_count = 4;
		 OCR1A = pgm_read_byte(&pcm_samples[sample++]);
		 if(sample>pcm_length)sample=0;
	 }
}

display_time()
{
char tempCelcius[50];
char volts[50];
int  adc_result;
double adcA;
long adcresistance;
double d;	

static unsigned char tenms=1;
	//beep
	beep_sound();
	tenms++;                  // Read DS1307 every 100 x 10ms = 1 sec
	if (tenms >= 100) {
		cli();                                // Disable Interupt
         
		// Read DS1307
		Read_DS1307();
.
.
.
.
}

ISR(TIMER0_OVF_vect)
{
  display_time();
  }

 main()
{
.
.
.
// Initial ATMega128 Timer/Counter0 Peripheral
	
	TCCR0=(1<<CS02)|(1<<CS00);   // Use maximum prescaller: Clk/1024
	TIFR = (1<<TOV0);            //Clear pending TOV0 interrupt 
	TCNT0=0x4E;                   // Start counter from 0x4E, overflow at 10 mSec
	TIMSK=(1<<TOIE0);            // Enable Counter Overflow Interrupt
	
	sei();  
.
.
.
}

I can hear a sound already in the buzzer but it's not regular every second, sometimes it's on, sometimes it's off
Any ideas what do I miss here ?

Thanks
 
Last edited:

I'm not familiar with ATMega128 devices but it looks like you are using PWM to generate the tick sound. I suggest you try simply raising and lowering the output pin to pulse a current to the loudspeaker. If it needs a delay, I would suggest about 50mS.

Brian.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…