CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Buzzer Routine Help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rrb011270



Joined: 07 Sep 2003
Posts: 51

View user's profile Send private message Yahoo Messenger

Buzzer Routine Help
PostPosted: Mon Dec 22, 2003 7:28 pm     Reply with quote

Mabuhay!

My buzzer routine below:
output_high(BUZZER);
delay_ms(200);
output_low(BUZZER);
delay_ms(450);

Is there another way such that I can use interrupt driven o reduce the instruction cycle of this routine?

My application is an RF reader which use an #int_ext2 to capture the ID from the badge. When it is successfull a buzzer will sound for success.

most of my code use the interrupt handler routine like the clock which use the #int_timer0 such it will capture the time and date and added to a complete packet of data which are compose of date, time, RFid, etc...

Any help will do?

Tenkyu
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 22, 2003 8:05 pm     Reply with quote

In the previous post, you were bit banging the output.
http://www.ccsinfo.com/forum/viewtopic.php?t=17853

Are you saying now that you only need to output for a duration?
rrb011270



Joined: 07 Sep 2003
Posts: 51

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Dec 23, 2003 12:24 am     Reply with quote

Mark wrote:
In the previous post, you were bit banging the output.
http://www.ccsinfo.com/forum/viewtopic.php?t=17853

Are you saying now that you only need to output for a duration?


Yes would output for a duration only? Need Help?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 23, 2003 8:01 am     Reply with quote

I like to use timer2 as a 1ms tick. Most of my software timers are based in milliseconds.

Code:

#include <18F452.h>              // Target PIC Microcontroller IC
#device  *=16                    // use a 16-bit pointer
#device ICD=TRUE

#fuses HS,NOPROTECT,NOLVP,NOWDT        // PIC MCU Configuration

#use delay(clock=20000000)       // 20MHz Crystal clock speed

// Configure PortA4 for buzzer output
#bit BUZZER=0xF80.4

int Buzzer_Timer = 0;

#int_timer2
void tick(void)
{

  if (Buzzer_Timer)
  {
    Buzzer_Timer--;
     if (!Buzzer_Timer)
    {
      output_high(BUZZER);
    }
  }
}

void Beep(void)
{
  Buzzer_Timer = 200;
  output_low(BUZZER);
}
 
main()
{
  // Setup timer2 for 1ms intervals
  setup_timer_2(T2_DIV_BY_4,250,5);
  enable_interrupts(int_timer2);
  enable_interrupts(global);

  Beep();
  while (1) ;
}
rrb011270



Joined: 07 Sep 2003
Posts: 51

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Dec 28, 2003 6:56 pm     Reply with quote

This is what I did for timer2:

Code:

   
#include <18F452.h>              // Target PIC Microcontroller IC
#device  *=16                    // use a 16-bit pointer

#fuses HS,NOPROTECT,NOWDT        // PIC MCU Configuration

#use delay(clock=20000000)       // 20MHz Crystal clock speed

#define BUZZER PIN_A4            // buzzer to PortA4

#int_timer2
timer2_isr()
{
   if (glBuzzerFlag)    // check if buzzer flag bit enable
   {
      if (buzzcnt >= 11)
      {
         output_high(BUZZER);       // buzzer turn-off
         glBuzzerFlag = 0;          // reset flag bit
      }
      buzzcnt++;
   }

   if (glBuzzerError)   // check if buzzer error flag bit enable
   {
      if ((buzzcnt >=11) && (buzzcnt < 21))
         output_high(BUZZER);       // turn-off buzzer for ~130msec.

      if ((buzzcnt >= 21) && (buzzcnt < 31))
         output_low(BUZZER);        // turn-on buzzer for ~130msec.

      if (buzzcnt >= 31)
      {
         output_high(BUZZER);       // buzzer turn-off
         glBuzzerError = 0;         // reset flag bit
      }
      buzzcnt++;
   }
}

void buzzSound()        // buzzer sounder routine
{
   output_low(BUZZER);  // turn ON buzzer
   buzzcnt = 0;         // set buzzer time in 100mS per count
}

void init_chip() {   // Initialize the MCU Chip

   setup_adc_ports(NO_ANALOGS);
   setup_timer_2(T2_DIV_BY_16,0xFF,16);   // 6.56mS interupt interval
   enable_interrupts(int_timer2);   // Enable timer2 interrupt
   enable_interrupts(GLOBAL);     // Enable Global interrupt
}

   


Thank u for the help...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group